From: Laszlo T. <ave...@us...> - 2005-02-02 17:29:41
|
Update of /cvsroot/gemrb/gemrb/gemrb/plugins/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16930/Core Modified Files: GameScript.cpp GameScript.h Interface.cpp Log Message: gamescript update (FloatMessageRnd) Index: GameScript.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/GameScript.cpp,v retrieving revision 1.222 retrieving revision 1.223 diff -C2 -d -r1.222 -r1.223 *** GameScript.cpp 30 Jan 2005 16:23:08 -0000 1.222 --- GameScript.cpp 2 Feb 2005 17:29:25 -0000 1.223 *************** *** 38,41 **** --- 38,43 ---- static ObjectFunction objects[MAX_OBJECTS]; static IDSFunction idtargets[MAX_OBJECT_FIELDS]; + static Cache SrcCache; //cache for string resources (pst) + //static Cache BcsCache; //cache for scripts static int ObjectIDSCount = 7; *************** *** 348,351 **** --- 350,355 ---- {"floatmessage", GameScript::DisplayStringHead,0}, {"floatmessagefixed", GameScript::FloatMessageFixed,0}, + {"floatmessagefixedrnd", GameScript::FloatMessageFixedRnd,0}, + {"floatmessagernd", GameScript::FloatMessageRnd,0}, {"forceaiscript", GameScript::ForceAIScript,0}, {"forcefacing", GameScript::ForceFacing,0}, *************** *** 474,477 **** --- 478,482 ---- {"runtopoint", GameScript::MoveToPoint,AF_BLOCKING}, //until we know better {"runtopointnorecticle", GameScript::MoveToPoint,AF_BLOCKING},//until we know better + {"runtosavedlocation", GameScript::MoveToSavedLocation,AF_BLOCKING},// {"savelocation", GameScript::SaveLocation,0}, {"saveplace", GameScript::SaveLocation,0}, *************** *** 747,750 **** --- 752,786 ---- } + static void FreeSrc(SrcVector *poi) + { + if( SrcCache.DecRef((void *) poi, false) <0) { + printMessage( "GameScript", "Corrupted Src cache encountered (reference count went below zero)", WHITE ); + abort(); + } + } + + static SrcVector *LoadSrc(ieResRef resname) + { + SrcVector *src = (SrcVector *) SrcCache.GetResource(resname); + if (src) { + return src; + } + DataStream* str = core->GetResourceMgr()->GetResource( resname, IE_SRC_CLASS_ID ); + if( !str) { + return NULL; + } + ieDword size=0; + str->ReadDword(&size); + src = new SrcVector(size); + while(size--) { + ieDword tmp; + str->ReadDword(&tmp); + str->ReadDword(&tmp); + src->at(size)=tmp; + } + delete ( str ); + return src; + } + GameScript::GameScript(const char* ResRef, unsigned char ScriptType, Variables* local) *************** *** 5954,5958 **** void GameScript::FloatMessageFixed(Scriptable* Sender, Action* parameters) { ! DisplayStringCore(Sender, parameters->int0Parameter, DS_CONSOLE|DS_HEAD); } --- 5990,6026 ---- void GameScript::FloatMessageFixed(Scriptable* Sender, Action* parameters) { ! Scriptable* target = GetActorFromObject( Sender, parameters->objects[0] ); ! if(!target) { ! target=Sender; ! printf("DisplayStringHead/FloatMessage got no target, assuming Sender!\n"); ! } ! ! DisplayStringCore(target, parameters->int0Parameter, DS_CONSOLE|DS_HEAD); ! } ! ! void GameScript::FloatMessageFixedRnd(Scriptable* Sender, Action* parameters) ! { ! Scriptable* target = GetActorFromObject( Sender, parameters->objects[0] ); ! if(!target) { ! target=Sender; ! printf("DisplayStringHead/FloatMessage got no target, assuming Sender!\n"); ! } ! ! SrcVector *rndstr=LoadSrc(parameters->string0Parameter); ! DisplayStringCore(target, rndstr->at(rand()%rndstr->size()), DS_CONSOLE|DS_HEAD); ! FreeSrc(rndstr); ! } ! ! void GameScript::FloatMessageRnd(Scriptable* Sender, Action* parameters) ! { ! Scriptable* target = GetActorFromObject( Sender, parameters->objects[0] ); ! if(!target) { ! target=Sender; ! printf("DisplayStringHead/FloatMessage got no target, assuming Sender!\n"); ! } ! ! SrcVector *rndstr=LoadSrc(parameters->string0Parameter); ! DisplayStringCore(target, rndstr->at(rand()%rndstr->size()), DS_CONSOLE|DS_HEAD); ! FreeSrc(rndstr); } Index: Interface.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Interface.cpp,v retrieving revision 1.251 retrieving revision 1.252 diff -C2 -d -r1.251 -r1.252 *** Interface.cpp 22 Jan 2005 20:36:22 -0000 1.251 --- Interface.cpp 2 Feb 2005 17:29:29 -0000 1.252 *************** *** 2607,2611 **** return item; } ! DataStream* str = GetResourceMgr()->GetResource( resname, IE_ITM_CLASS_ID ); ItemMgr* sm = ( ItemMgr* ) GetInterface( IE_ITM_CLASS_ID ); if (sm == NULL) { --- 2607,2611 ---- return item; } ! DataStream* str = key->GetResource( resname, IE_ITM_CLASS_ID ); ItemMgr* sm = ( ItemMgr* ) GetInterface( IE_ITM_CLASS_ID ); if (sm == NULL) { *************** *** 2639,2643 **** Spell* Interface::GetSpell(const char* resname) { ! DataStream* str = GetResourceMgr()->GetResource( resname, IE_SPL_CLASS_ID ); SpellMgr* sm = ( SpellMgr* ) GetInterface( IE_SPL_CLASS_ID ); if (sm == NULL) { --- 2639,2643 ---- Spell* Interface::GetSpell(const char* resname) { ! DataStream* str = key->GetResource( resname, IE_SPL_CLASS_ID ); SpellMgr* sm = ( SpellMgr* ) GetInterface( IE_SPL_CLASS_ID ); if (sm == NULL) { Index: GameScript.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/GameScript.h,v retrieving revision 1.154 retrieving revision 1.155 diff -C2 -d -r1.154 -r1.155 *** GameScript.h 30 Jan 2005 16:23:09 -0000 1.154 --- GameScript.h 2 Feb 2005 17:29:28 -0000 1.155 *************** *** 67,70 **** --- 67,72 ---- #endif + typedef std::vector<ieDword> SrcVector; + class GEM_EXPORT Targets { public: *************** *** 1045,1048 **** --- 1047,1052 ---- static void FadeToColor(Scriptable* Sender, Action* parameters); static void FloatMessageFixed(Scriptable* Sender, Action* parameters); + static void FloatMessageFixedRnd(Scriptable* Sender, Action* parameters); + static void FloatMessageRnd(Scriptable* Sender, Action* parameters); static void ForceAIScript(Scriptable* Sender, Action* parameters); static void ForceFacing(Scriptable* Sender, Action* parameters); |