From: Laszlo T. <ave...@us...> - 2012-11-24 20:33:07
|
gemrb: Infinity Engine emulator The branch master has been updated via 3ac73f5b8c11b6135ee85fbf3e68c4960abf33de (commit) Summary of changes: gemrb/core/Scriptable/PCStatStruct.cpp | 72 ++++++++++++++++++++++++++++++++ gemrb/core/Scriptable/PCStatStruct.h | 4 ++ 2 files changed, 76 insertions(+), 0 deletions(-) from 7d8870eb373a30d3817f681a30a218d125e8fe74 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://gemrb.git.sourceforge.net/git/gitweb.cgi?p=gemrb/gemrb;a=commitdiff;h=3ac73f5b8c11b6135ee85fbf3e68c4960abf33de commit 3ac73f5b8c11b6135ee85fbf3e68c4960abf33de Author: Avenger <ave...@so...> Date: Sat Nov 24 21:32:22 2012 +0100 implemented core function for registering favourite spells/weapons diff --git a/gemrb/core/Scriptable/PCStatStruct.cpp b/gemrb/core/Scriptable/PCStatStruct.cpp index a7ff34d..7f5801b 100644 --- a/gemrb/core/Scriptable/PCStatStruct.cpp +++ b/gemrb/core/Scriptable/PCStatStruct.cpp @@ -185,4 +185,76 @@ int PCStatsStruct::GetHeaderForSlot(int slot) return -1; } +//register favourite weapon or spell +//method: +//there are MAX_FAVOURITES slots, each with a resref and an usage count +//the currently registered resref will always be stored somewhere, the question is just where +//if it was an old favourite, just increase the usage count +//if it is the new favourite candidate (last slot) then just increase the usage count +//but also swap it with a previous slot if its usage count is now better, so the last slot is always the weakest +//finally if it was not found anywhere, register it as the new candidate with 1 usage + +void PCStatsStruct::RegisterFavourite(ieResRef fav, int what) +{ + ieResRef *respoi; + ieWord *cntpoi; + + switch (what) { + case FAV_SPELL: + respoi = FavouriteSpells; + cntpoi = FavouriteSpellsCount; + break; + case FAV_WEAPON: + respoi = FavouriteWeapons; + cntpoi = FavouriteWeaponsCount; + break; + default: + print("Illegal RegisterFavourite call..."); + abort(); + return; + } + //least favourite candidate position and count + int minpos = 0; + int mincnt = cntpoi[0]; + int pos = 0; + for (pos = 0; pos<MAX_FAVOURITES-1; pos++) { + if (!strnicmp(fav, respoi[pos], 8) ) { + //found an old favourite, just increase its usage count and done + if (cntpoi[pos]<0xffff) { + cntpoi[pos]++; + } + return; + } + if (pos) { + //collect least favourite for possible swapping + if (cntpoi[pos]<mincnt) { + minpos = pos; + mincnt = cntpoi[pos]; + } + } + } + + //pos is always MAX_FAVOURITES-1 here + if (strnicmp(fav, respoi[pos], 8) ) { + //new favourite candidate, scrapping the old one + cntpoi[pos] = 1; + strnuprcpy(respoi[pos], fav, 8); + return; + } + //increase the favourite candidate + cntpoi[pos]++; + if (cntpoi[pos]>mincnt) { + //if it is now exceeding an old favourite, swap them + + //move the old resref to the last position + memcpy(respoi[pos], respoi[minpos], sizeof(ieResRef) ); + //store the new resref into the new position + strnuprcpy(respoi[minpos], fav, 8); + //store the new count to the new position + cntpoi[minpos] = cntpoi[pos]; + //store the old count to the last position + cntpoi[pos] = mincnt; + } +} + } diff --git a/gemrb/core/Scriptable/PCStatStruct.h b/gemrb/core/Scriptable/PCStatStruct.h index e97889a..1b0984b 100644 --- a/gemrb/core/Scriptable/PCStatStruct.h +++ b/gemrb/core/Scriptable/PCStatStruct.h @@ -89,6 +89,9 @@ namespace GemRB { #define GUIBT_COUNT (MAX_QSLOTS + 3) +#define FAV_SPELL 0 +#define FAV_WEAPON 1 + class GEM_EXPORT PCStatsStruct { public: ieStrRef BestKilledName; @@ -131,6 +134,7 @@ public: void SetSlotIndex(unsigned int which, ieWord headerindex); void GetSlotAndIndex(unsigned int which, ieWord &slot, ieWord &headerindex); int GetHeaderForSlot(int slot); + void RegisterFavourite(ieResRef fav, int what); }; } ----------------------------------------------------------------------- This is an automated email from the git hooks/post-receive script. -- gemrb: Infinity Engine emulator |