melee / ranged effects
[gemrb.git] / gemrb / core / Scriptable / PCStatStruct.cpp
bloba17359b6a6a89011db736aa8ff3cb136b6adc886
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "Scriptable/PCStatStruct.h"
23 #include "globals.h" //for abort()
24 #include "win32def.h"
26 #include <cstring>
28 PCStatsStruct::PCStatsStruct()
30 BestKilledName = 0xffffffff;
31 BestKilledXP = 0;
32 AwayTime = 0;
33 JoinDate = 0;
34 unknown10 = 0;
35 KillsChapterXP = 0;
36 KillsChapterCount = 0;
37 KillsTotalXP = 0;
38 KillsTotalCount = 0;
39 memset( FavouriteSpells, 0, sizeof(FavouriteSpells) );
40 memset( FavouriteSpellsCount, 0, sizeof(FavouriteSpellsCount) );
41 memset( FavouriteWeapons, 0, sizeof(FavouriteWeapons) );
42 memset( FavouriteWeaponsCount, 0, sizeof(FavouriteWeaponsCount) );
43 SoundSet[0]=0;
44 SoundFolder[0]=0;
45 QSlots[0]=0xff;
46 memset( QuickSpells, 0, sizeof(QuickSpells) );
47 memset( QuickSpellClass, 0xff, sizeof(QuickSpellClass) );
48 memset( QuickItemSlots, -1, sizeof(QuickItemSlots) );
49 memset( QuickItemHeaders, -1, sizeof(QuickItemHeaders) );
50 memset( QuickWeaponSlots, -1, sizeof(QuickWeaponSlots) );
51 memset( QuickWeaponHeaders, -1, sizeof(QuickWeaponHeaders) );
52 memset( PortraitIcons, -1, sizeof(PortraitIcons) );
53 memset( PreviousPortraitIcons, -1, sizeof(PreviousPortraitIcons) );
54 memset( PortraitIconString, 0, sizeof(PortraitIconString) );
55 LastLeft = 0;
56 LastJoined = 0;
59 void PCStatsStruct::IncrementChapter()
61 KillsChapterXP = 0;
62 KillsChapterCount = 0;
65 void PCStatsStruct::NotifyKill(ieDword xp, ieStrRef name)
67 if (BestKilledXP<=xp) {
68 BestKilledXP = xp;
69 BestKilledName = name;
72 KillsTotalXP += xp;
73 KillsChapterXP += xp;
74 KillsTotalCount ++;
75 KillsChapterCount ++;
78 //init quick weapon/item slots
79 void PCStatsStruct::SetQuickItemSlot(int idx, int slot, int headerindex)
81 if (slot>=0) {
82 QuickItemSlots[idx]=(ieWord) slot;
84 QuickItemHeaders[idx]=(ieWord) headerindex;
87 void PCStatsStruct::InitQuickSlot(unsigned int which, int slot, int headerindex)
89 if (!which) {
90 int i;
92 for(i=0;i<MAX_QUICKITEMSLOT;i++) {
93 if (slot==QuickItemSlots[i]) {
94 QuickItemHeaders[i]=headerindex;
95 return;
99 for(i=0;i<MAX_QUICKWEAPONSLOT;i++) {
100 if (slot==QuickWeaponSlots[i]) {
101 QuickWeaponHeaders[i]=headerindex;
102 return;
105 return;
108 //precalculate field values. Empty slots will get their ability header
109 //initialized to the invalid value of 0xffff to stay binary compatible
110 //with original
111 int slot2, header;
113 if (slot==0xffff) {
114 slot2 = 0xffff;
115 header = 0xffff;
117 else {
118 slot2 = slot+1;
119 header = 0;
121 switch(which) {
122 case ACT_QSLOT1: SetQuickItemSlot(0,slot,headerindex); break;
123 case ACT_QSLOT2: SetQuickItemSlot(1,slot,headerindex); break;
124 case ACT_QSLOT3: SetQuickItemSlot(2,slot,headerindex); break;
125 case ACT_QSLOT4: SetQuickItemSlot(3,slot,headerindex); break;
126 case ACT_QSLOT5: SetQuickItemSlot(4,slot,headerindex); break;
127 case ACT_WEAPON1:
128 QuickWeaponSlots[0]=slot;
129 QuickWeaponHeaders[0]=header;
130 QuickWeaponSlots[4]=slot2;
131 QuickWeaponHeaders[4]=header;
132 break;
133 case ACT_WEAPON2:
134 QuickWeaponSlots[1]=slot;
135 QuickWeaponHeaders[1]=header;
136 QuickWeaponSlots[5]=slot2;
137 QuickWeaponHeaders[5]=header;
138 break;
139 case ACT_WEAPON3:
140 QuickWeaponSlots[2]=slot;
141 QuickWeaponHeaders[2]=header;
142 QuickWeaponSlots[6]=slot2;
143 QuickWeaponHeaders[6]=header;
144 break;
145 case ACT_WEAPON4:
146 QuickWeaponSlots[3]=slot;
147 QuickWeaponHeaders[3]=header;
148 QuickWeaponSlots[7]=slot2;
149 QuickWeaponHeaders[7]=header;
150 break;
154 /* this function is obsolete, use initquickslot with slot=-1
155 void PCStatsStruct::SetSlotIndex(unsigned int which, ieWord headerindex)
157 //this is not correct, not the slot, but a separate headerindex should be here
158 switch(which) {
159 case ACT_QSLOT1: QuickItemHeaders[0]=headerindex; return;
160 case ACT_QSLOT2: QuickItemHeaders[1]=headerindex; return;
161 case ACT_QSLOT3: QuickItemHeaders[2]=headerindex; return;
162 case ACT_QSLOT4: QuickItemHeaders[3]=headerindex; return;
163 case ACT_QSLOT5: QuickItemHeaders[4]=headerindex; return;
165 ///it shouldn't reach this point
166 abort();
170 //returns both the inventory slot and the header index associated to a quickslot
171 void PCStatsStruct::GetSlotAndIndex(unsigned int which, ieWord &slot, ieWord &headerindex)
173 int idx;
175 switch(which) {
176 case ACT_QSLOT1: idx = 0; break;
177 case ACT_QSLOT2: idx = 1; break;
178 case ACT_QSLOT3: idx = 2; break;
179 case ACT_QSLOT4: idx = 3; break;
180 case ACT_QSLOT5: idx = 4; break;
181 default: abort();
183 slot=QuickItemSlots[idx];
184 headerindex=QuickItemHeaders[idx];
187 //return the item extended header assigned to an inventory slot (the ability to use)
188 //only quickslots have this assignment, equipment items got all abilities available
189 int PCStatsStruct::GetHeaderForSlot(int slot)
191 int i;
193 for(i=0;i<MAX_QUICKITEMSLOT;i++) {
194 if(QuickItemSlots[i]==slot) return (ieWordSigned) QuickItemHeaders[i];
197 for(i=0;i<MAX_QUICKWEAPONSLOT;i++) {
198 if(QuickWeaponSlots[i]==slot) return (ieWordSigned) QuickWeaponHeaders[i];
200 return -1;