Mercurial > mm7
comparison Actor.cpp @ 1850:521ffedabe19
sub_448518_npc_set_item using body of cleaned up Actor::GiveItem
author | Grumpy7 |
---|---|
date | Sun, 13 Oct 2013 10:45:48 +0200 |
parents | 794f6ac640f4 |
children | 80e897fc2438 |
comparison
equal
deleted
inserted
replaced
1849:794f6ac640f4 | 1850:521ffedabe19 |
---|---|
112 { | 112 { |
113 for (int i = 0; i < uNumActors; i++) | 113 for (int i = 0; i < uNumActors; i++) |
114 { | 114 { |
115 if (pActors[uNumActors].sNPC_ID == npc) | 115 if (pActors[uNumActors].sNPC_ID == npc) |
116 { | 116 { |
117 Actor* currActor = &pActors[i]; | 117 Actor::GiveItem(i, item, a3); |
118 if ( a3 ) | |
119 { | |
120 if ( currActor->uCarriedItemID == 0) | |
121 currActor->uCarriedItemID = item; | |
122 else if ( currActor->array_000234[0].uItemID == 0) | |
123 currActor->array_000234[0].uItemID = item; | |
124 else if ( currActor->array_000234[1].uItemID == 0) | |
125 currActor->array_000234[1].uItemID = item; | |
126 } | |
127 else | |
128 { | |
129 if ( currActor->uCarriedItemID == item ) | |
130 currActor->uCarriedItemID = 0; | |
131 else if ( currActor->array_000234[0].uItemID == item ) | |
132 currActor->array_000234[0].Reset(); | |
133 else if ( currActor->array_000234[1].uItemID == item ) | |
134 currActor->array_000234[1].Reset(); | |
135 } | |
136 } | 118 } |
137 } | 119 } |
138 } | 120 } |
139 | 121 |
140 //----- (004485A7) -------------------------------------------------------- | 122 //----- (004485A7) -------------------------------------------------------- |
141 void Actor::GiveItem(signed int uActorID, unsigned int uItemID, unsigned int bGive) | 123 void Actor::GiveItem(signed int uActorID, unsigned int uItemID, unsigned int bGive) |
142 { | 124 { |
143 unsigned int v3; // eax@3 | |
144 char *v4; // ecx@3 | |
145 int *v5; // eax@8 | |
146 ItemGen *v6; // ecx@12 | |
147 | |
148 if ( (uActorID >= 0) && (signed int)uActorID <= (signed int)(uNumActors - 1) ) | 125 if ( (uActorID >= 0) && (signed int)uActorID <= (signed int)(uNumActors - 1) ) |
149 { | 126 { |
150 v3 = uActorID; | 127 Actor* currActor = &pActors[uActorID]; |
151 v4 = (char *)&pActors[uActorID].uCarriedItemID; | |
152 if ( bGive ) | 128 if ( bGive ) |
153 { | 129 { |
154 if ( *(short *)v4 ) | 130 if ( currActor->uCarriedItemID == 0) |
155 { | 131 currActor->uCarriedItemID = uItemID; |
156 if ( pActors[v3].array_000234[0].uItemID ) | 132 else if ( currActor->array_000234[0].uItemID == 0) |
157 { | 133 currActor->array_000234[0].uItemID = uItemID; |
158 v5 = &pActors[v3].array_000234[1].uItemID; | 134 else if ( currActor->array_000234[1].uItemID == 0) |
159 if ( !*v5 ) | 135 currActor->array_000234[1].uItemID = uItemID; |
160 *v5 = uItemID; | |
161 } | |
162 else | |
163 { | |
164 pActors[v3].array_000234[0].uItemID = uItemID; | |
165 } | |
166 } | |
167 else | |
168 { | |
169 *(short *)v4 = uItemID; | |
170 } | |
171 } | 136 } |
172 else | 137 else |
173 { | 138 { |
174 if ( *(short *)v4 == uItemID ) | 139 if ( currActor->uCarriedItemID == uItemID ) |
175 { | 140 currActor->uCarriedItemID = 0; |
176 *(short *)v4 = 0; | 141 else if ( currActor->array_000234[0].uItemID == uItemID ) |
177 } | 142 currActor->array_000234[0].Reset(); |
178 else | 143 else if ( currActor->array_000234[1].uItemID == uItemID ) |
179 { | 144 currActor->array_000234[1].Reset(); |
180 v6 = pActors[v3].array_000234; | |
181 if ( pActors[v3].array_000234[0].uItemID == uItemID | |
182 || (v6 = &pActors[v3].array_000234[1], pActors[v3].array_000234[1].uItemID == uItemID) ) | |
183 v6->Reset(); | |
184 } | |
185 } | 145 } |
186 } | 146 } |
187 } | 147 } |
188 | 148 |
189 //----- (0040894B) -------------------------------------------------------- | 149 //----- (0040894B) -------------------------------------------------------- |
190 bool Actor::CanAct() | 150 bool Actor::CanAct() |
191 { | 151 { |
192 bool isparalyzed; // esi@1 | 152 bool isparalyzed; // esi@1 |
193 bool isstoned; // edi@2 | 153 bool isstoned; // edi@2 |
194 unsigned __int16 v3; // ax@6 | 154 AIState v3; // ax@6 |
195 | 155 |
196 isstoned = (signed __int64)this->pActorBuffs[5].uExpireTime > 0;// stoned | 156 isstoned = (signed __int64)this->pActorBuffs[5].uExpireTime > 0;// stoned |
197 isparalyzed = (signed __int64)this->pActorBuffs[6].uExpireTime > 0;// paralyzed | 157 isparalyzed = (signed __int64)this->pActorBuffs[6].uExpireTime > 0;// paralyzed |
198 v3 = this->uAIState; | 158 v3 = this->uAIState; |
199 return !(isstoned || isparalyzed || v3 == Dying || v3 == Dead || v3 == Removed || v3 == Summoned || v3 == Disabled); | 159 return !(isstoned || isparalyzed || v3 == Dying || v3 == Dead || v3 == Removed || v3 == Summoned || v3 == Disabled); |
201 | 161 |
202 //----- (004089C7) -------------------------------------------------------- | 162 //----- (004089C7) -------------------------------------------------------- |
203 bool Actor::IsNotAlive() | 163 bool Actor::IsNotAlive() |
204 { | 164 { |
205 bool isstoned; // esi@1 | 165 bool isstoned; // esi@1 |
206 //unsigned __int16 v2; // ax@3 | |
207 | 166 |
208 isstoned = (signed __int64)this->pActorBuffs[5].uExpireTime > 0;// stoned | 167 isstoned = (signed __int64)this->pActorBuffs[5].uExpireTime > 0;// stoned |
209 //v2 = this->uAIState; | |
210 return (isstoned || (uAIState == Dying) || (uAIState == Dead) || (uAIState == Removed) || (uAIState == Summoned) || (uAIState == Disabled)); | 168 return (isstoned || (uAIState == Dying) || (uAIState == Dead) || (uAIState == Removed) || (uAIState == Summoned) || (uAIState == Disabled)); |
211 } | 169 } |
212 | 170 |
213 //----- (004086E9) -------------------------------------------------------- | 171 //----- (004086E9) -------------------------------------------------------- |
214 void Actor::SetRandomGoldIfTheresNoItem() | 172 void Actor::SetRandomGoldIfTheresNoItem() |
215 { | 173 { |
216 Actor *v1; // esi@1 | |
217 int v2; // edi@1 | 174 int v2; // edi@1 |
218 signed int v3; // ebx@2 | |
219 unsigned __int8 v4; // al@7 | 175 unsigned __int8 v4; // al@7 |
220 | 176 |
221 v1 = this; | |
222 v2 = 0; | 177 v2 = 0; |
223 if ( !this->array_000234[3].uItemID ) | 178 if ( !this->array_000234[3].uItemID ) |
224 { | 179 { |
225 v3 = 0; | |
226 if ( this->pMonsterInfo.uTreasureDiceRolls ) | 180 if ( this->pMonsterInfo.uTreasureDiceRolls ) |
227 { | 181 { |
228 do | 182 for (int i = 0; i < this->pMonsterInfo.uTreasureDiceRolls; i++) |
229 { | 183 { |
230 ++v3; | 184 v2 += rand() % this->pMonsterInfo.uTreasureDiceSides + 1; |
231 v2 += rand() % v1->pMonsterInfo.uTreasureDiceSides + 1; | 185 } |
232 } | |
233 while ( v3 < v1->pMonsterInfo.uTreasureDiceRolls ); | |
234 if ( v2 ) | 186 if ( v2 ) |
235 { | 187 { |
236 v1->array_000234[3].uItemID = 197; | 188 this->array_000234[3].uItemID = 197; |
237 v1->array_000234[3].uSpecEnchantmentType = v2; | 189 this->array_000234[3].uSpecEnchantmentType = v2; //actual gold amount |
238 } | 190 } |
239 } | 191 } |
240 } | 192 } |
241 if ( rand() % 100 < v1->pMonsterInfo.uTreasureDropChance ) | 193 if ( rand() % 100 < this->pMonsterInfo.uTreasureDropChance ) |
242 { | 194 { |
243 v4 = v1->pMonsterInfo.uTreasureLevel; | 195 v4 = this->pMonsterInfo.uTreasureLevel; |
244 if ( v4 ) | 196 if ( v4 ) |
245 pItemsTable->GenerateItem(v4, v1->pMonsterInfo.uTreasureType, &v1->array_000234[2]); | 197 pItemsTable->GenerateItem(v4, this->pMonsterInfo.uTreasureType, &this->array_000234[2]); |
246 } | 198 } |
247 v1->uAttributes |= 0x800000; | 199 this->uAttributes |= 0x800000; |
248 } | 200 } |
249 | 201 |
250 //----- (00404AC7) -------------------------------------------------------- | 202 //----- (00404AC7) -------------------------------------------------------- |
251 void __fastcall Actor::AI_SpellAttack(unsigned int uActorID, AIDirection *pDir, int uSpellID, int a4, unsigned int uSkillLevel) | 203 void __fastcall Actor::AI_SpellAttack(unsigned int uActorID, AIDirection *pDir, int uSpellID, int a4, unsigned int uSkillLevel) |
252 { | 204 { |