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()
28 PCStatsStruct::PCStatsStruct()
30 BestKilledName
= 0xffffffff;
36 KillsChapterCount
= 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
) );
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
) );
59 void PCStatsStruct::IncrementChapter()
62 KillsChapterCount
= 0;
65 void PCStatsStruct::NotifyKill(ieDword xp
, ieStrRef name
)
67 if (BestKilledXP
<=xp
) {
69 BestKilledName
= name
;
78 //init quick weapon/item slots
79 void PCStatsStruct::SetQuickItemSlot(int idx
, int slot
, int headerindex
)
82 QuickItemSlots
[idx
]=(ieWord
) slot
;
84 QuickItemHeaders
[idx
]=(ieWord
) headerindex
;
87 void PCStatsStruct::InitQuickSlot(unsigned int which
, int slot
, int headerindex
)
92 for(i
=0;i
<MAX_QUICKITEMSLOT
;i
++) {
93 if (slot
==QuickItemSlots
[i
]) {
94 QuickItemHeaders
[i
]=headerindex
;
99 for(i
=0;i
<MAX_QUICKWEAPONSLOT
;i
++) {
100 if (slot
==QuickWeaponSlots
[i
]) {
101 QuickWeaponHeaders
[i
]=headerindex
;
108 //precalculate field values. Empty slots will get their ability header
109 //initialized to the invalid value of 0xffff to stay binary compatible
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;
128 QuickWeaponSlots
[0]=slot
;
129 QuickWeaponHeaders
[0]=header
;
130 QuickWeaponSlots
[4]=slot2
;
131 QuickWeaponHeaders
[4]=header
;
134 QuickWeaponSlots
[1]=slot
;
135 QuickWeaponHeaders
[1]=header
;
136 QuickWeaponSlots
[5]=slot2
;
137 QuickWeaponHeaders
[5]=header
;
140 QuickWeaponSlots
[2]=slot
;
141 QuickWeaponHeaders
[2]=header
;
142 QuickWeaponSlots
[6]=slot2
;
143 QuickWeaponHeaders
[6]=header
;
146 QuickWeaponSlots
[3]=slot
;
147 QuickWeaponHeaders
[3]=header
;
148 QuickWeaponSlots
[7]=slot2
;
149 QuickWeaponHeaders
[7]=header
;
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
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
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
)
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;
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
)
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
];