Issue #68: added getdeadcount script function

This commit is contained in:
Marc Zinnschlag 2012-10-27 11:33:18 +02:00
parent f72c35fc17
commit 453f347ee8
7 changed files with 44 additions and 1 deletions

View file

@ -76,6 +76,9 @@ namespace MWBase
virtual void restoreDynamicStats() = 0; virtual void restoreDynamicStats() = 0;
///< If the player is sleeping, this should be called every hour. ///< If the player is sleeping, this should be called every hour.
virtual int countDeaths (const std::string& id) const = 0;
///< Return the number of deaths for actors with the given ID.
}; };
} }

View file

@ -262,4 +262,14 @@ namespace MWMechanics
calculateRestoration (*iter, 3600); calculateRestoration (*iter, 3600);
} }
} }
int Actors::countDeaths (const std::string& id) const
{
std::map<std::string, int>::const_iterator iter = mDeathCount.find (id);
if (iter!=mDeathCount.end())
return iter->second;
return 0;
}
} }

View file

@ -63,6 +63,9 @@ namespace MWMechanics
void restoreDynamicStats(); void restoreDynamicStats();
///< If the player is sleeping, this should be called every hour. ///< If the player is sleeping, this should be called every hour.
int countDeaths (const std::string& id) const;
///< Return the number of deaths for actors with the given ID.
}; };
} }

View file

@ -326,4 +326,9 @@ namespace MWMechanics
buildPlayer(); buildPlayer();
mUpdatePlayer = true; mUpdatePlayer = true;
} }
int MechanicsManager::countDeaths (const std::string& id) const
{
return mActors.countDeaths (id);
}
} }

View file

@ -78,6 +78,10 @@ namespace MWMechanics
virtual void restoreDynamicStats(); virtual void restoreDynamicStats();
///< If the player is sleeping, this should be called every hour. ///< If the player is sleeping, this should be called every hour.
virtual int countDeaths (const std::string& id) const;
///< Return the number of deaths for actors with the given ID.
}; };
} }

View file

@ -206,5 +206,6 @@ op 0x200019f: GetPcSleep
op 0x20001a0: ShowMap op 0x20001a0: ShowMap
op 0x20001a1: FillMap op 0x20001a1: FillMap
op 0x20001a2: WakeUpPc op 0x20001a2: WakeUpPc
opcodes 0x20001a3-0x3ffffff unused op 0x20001a3: GetDeadCount
opcodes 0x20001a4-0x3ffffff unused

View file

@ -17,6 +17,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/dialoguemanager.hpp" #include "../mwbase/dialoguemanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
@ -592,6 +593,17 @@ namespace MWScript
} }
}; };
class OpGetDeadCount : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths (id);
}
};
const int numberOfAttributes = 8; const int numberOfAttributes = 8;
@ -644,6 +656,8 @@ namespace MWScript
const int opcodeSetLevel = 0x200018e; const int opcodeSetLevel = 0x200018e;
const int opcodeSetLevelExplicit = 0x200018f; const int opcodeSetLevelExplicit = 0x200018f;
const int opcodeGetDeadCount = 0x20001a3;
void registerExtensions (Compiler::Extensions& extensions) void registerExtensions (Compiler::Extensions& extensions)
{ {
static const char *attributes[numberOfAttributes] = static const char *attributes[numberOfAttributes] =
@ -729,6 +743,8 @@ namespace MWScript
extensions.registerInstruction("setlevel", "l", opcodeSetLevel, opcodeSetLevelExplicit); extensions.registerInstruction("setlevel", "l", opcodeSetLevel, opcodeSetLevelExplicit);
extensions.registerFunction("getlevel", 'l', "", opcodeGetLevel, opcodeGetLevelExplicit); extensions.registerFunction("getlevel", 'l', "", opcodeGetLevel, opcodeGetLevelExplicit);
extensions.registerFunction("getdeadcount", 'l', "c", opcodeGetDeadCount);
} }
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
@ -806,6 +822,7 @@ namespace MWScript
interpreter.installSegment5 (opcodeSetLevel, new OpSetLevel<ImplicitRef>); interpreter.installSegment5 (opcodeSetLevel, new OpSetLevel<ImplicitRef>);
interpreter.installSegment5 (opcodeSetLevelExplicit, new OpSetLevel<ExplicitRef>); interpreter.installSegment5 (opcodeSetLevelExplicit, new OpSetLevel<ExplicitRef>);
interpreter.installSegment5 (opcodeGetDeadCount, new OpGetDeadCount);
} }
} }
} }