comparison Engine/Objects/Actor.cpp @ 2497:82d5d92a097c

for MVS2012
author Ritor1
date Thu, 18 Sep 2014 23:59:29 +0600
parents
children 68cdef6879a0
comparison
equal deleted inserted replaced
2496:5abd8fc8f1c6 2497:82d5d92a097c
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6
7 #include "Engine/Graphics/PaletteManager.h"
8 #include "ErrorHandling.h"
9
10 #include "Engine/Graphics/DecalBuilder.h"
11
12 #include "Engine/Graphics/Sprites.h"
13 #include "stru6.h"
14
15
16 #include "Actor.h"
17 #include "OurMath.h"
18 #include "Engine/Graphics/Outdoor.h"
19 #include "AudioPlayer.h"
20 #include "Game.h"
21 #include "ObjectList.h"
22 #include "Engine/Graphics/Overlays.h"
23 #include "FactionTable.h"
24 #include "TurnEngine.h"
25 #include "CastSpellInfo.h"
26 #include "Timer.h"
27 #include "LOD.h"
28 #include "Party.h"
29 #include "GUIWindow.h"
30
31 #include "MM7.h"
32 #include "SpriteObject.h"
33 #include "stru298.h"
34 #include "Log.h"
35 #include "Texts.h"
36 #include "Engine/Graphics/Level/Decoration.h"
37 #include "Engine/Graphics/Viewport.h"
38 #include "Engine/Graphics/Vis.h"
39
40
41
42
43
44 std::array<Actor, 500> pActors;
45 size_t uNumActors;
46
47 stru319 stru_50C198; // idb
48
49
50 std::array<uint, 5> _4DF380_hostilityRanges = {0, 1024, 2560, 5120, 10240};
51
52
53
54
55 //----- (0042FB5C) --------------------------------------------------------
56 // True if monster should play attack animation when casting this spell.
57 bool ShouldMonsterPlayAttackAnim(signed int spell_id)
58 {
59 switch (spell_id)
60 {
61 case SPELL_FIRE_HASTE:
62 case SPELL_AIR_SHIELD:
63 case SPELL_EARTH_STONESKIN:
64 case SPELL_SPIRIT_BLESS:
65 case SPELL_SPIRIT_FATE:
66 case SPELL_SPIRIT_HEROISM:
67 case SPELL_BODY_HAMMERHANDS:
68 case SPELL_BODY_POWER_CURE:
69 case SPELL_LIGHT_DISPEL_MAGIC:
70 case SPELL_LIGHT_DAY_OF_PROTECTION:
71 case SPELL_LIGHT_HOUR_OF_POWER:
72 case SPELL_DARK_PAIN_REFLECTION:
73 return false;
74 }
75
76 return true;
77 }
78
79
80 //----- (0041AF52) --------------------------------------------------------
81 void Actor::DrawHealthBar(Actor *actor, GUIWindow *window)
82 {
83 unsigned int bar_length; // esi@1
84 unsigned int uX; // ebx@10
85 unsigned int v9; // [sp+14h] [bp-Ch]@4
86 unsigned int v10; // [sp+1Ch] [bp-4h]@4
87
88 if (actor->pMonsterInfo.uHP <= 25)
89 bar_length = 25;
90 else if ( actor->pMonsterInfo.uHP < 200 )
91 bar_length = actor->pMonsterInfo.uHP;
92 else
93 bar_length = 200;
94
95 v10 = bar_length;
96 if ( actor->sCurrentHP <= (0.34 * actor->pMonsterInfo.uHP) )
97 v9 = uTextureID_mhp_red;
98 else if ( actor->sCurrentHP <= ( 0.67 * actor->pMonsterInfo.uHP) )
99 v9 = uTextureID_mhp_yel;
100 else
101 v9 = uTextureID_mhp_grn;
102
103 if ( actor->sCurrentHP < (int)actor->pMonsterInfo.uHP )
104 v10 = bar_length / actor->pMonsterInfo.uHP * actor->sCurrentHP;
105
106 uX = window->uFrameX + (signed int)(window->uFrameWidth - bar_length) / 2;
107
108 pRenderer->SetTextureClipRect(uX, window->uFrameY + 32, uX + bar_length, window->uFrameY + 52);
109 pRenderer->DrawTextureIndexed(uX, window->uFrameY + 32, pIcons_LOD->GetTexture(uTextureID_mhp_bd));
110 pRenderer->SetTextureClipRect(uX, window->uFrameY + 32, uX + v10, window->uFrameY + 52);
111 pRenderer->DrawTextureIndexed(uX, window->uFrameY + 34, pIcons_LOD->GetTexture(v9));
112
113 pRenderer->ResetTextureClipRect();
114 pRenderer->DrawTextureIndexed(uX - 5, window->uFrameY + 32, pIcons_LOD->GetTexture(uTextureID_mhp_capl));
115 pRenderer->DrawTextureIndexed(uX + bar_length, window->uFrameY + 32, pIcons_LOD->GetTexture(uTextureID_mhp_capr));
116 }
117
118 //----- (00448A40) --------------------------------------------------------
119 void Actor::ToggleFlag(signed int uActorID, unsigned int uFlag, int bToggle)
120 {
121 if ( uActorID >= 0 && uActorID <= (signed int)(uNumActors - 1) )
122 {
123 if ( bToggle )
124 pActors[uActorID].uAttributes |= uFlag;
125 else
126 {
127 if ( uFlag == 0x10000 )
128 {
129 if (pActors[uActorID].uAIState == Disabled )
130 pActors[uActorID].uAIState = Standing;
131 }
132 pActors[uActorID].uAttributes &= ~uFlag;
133 }
134 }
135 }
136
137 //----- (00448518) --------------------------------------------------------
138 void __fastcall sub_448518_npc_set_item(int npc, unsigned int item, int a3)
139 {
140 for (uint i = 0; i < uNumActors; i++)
141 {
142 if (pActors[uNumActors].sNPC_ID == npc)
143 Actor::GiveItem(i, item, a3);
144 }
145 }
146
147 //----- (004485A7) --------------------------------------------------------
148 void Actor::GiveItem(signed int uActorID, unsigned int uItemID, unsigned int bGive)
149 {
150 if ( (uActorID >= 0) && (signed int)uActorID <= (signed int)(uNumActors - 1) )
151 {
152 if ( bGive )
153 {
154 if ( pActors[uActorID].uCarriedItemID == 0)
155 pActors[uActorID].uCarriedItemID = uItemID;
156 else if ( pActors[uActorID].ActorHasItems[0].uItemID == 0)
157 pActors[uActorID].ActorHasItems[0].uItemID = uItemID;
158 else if ( pActors[uActorID].ActorHasItems[1].uItemID == 0)
159 pActors[uActorID].ActorHasItems[1].uItemID = uItemID;
160 }
161 else
162 {
163 if ( pActors[uActorID].uCarriedItemID == uItemID )
164 pActors[uActorID].uCarriedItemID = 0;
165 else if ( pActors[uActorID].ActorHasItems[0].uItemID == uItemID )
166 pActors[uActorID].ActorHasItems[0].Reset();
167 else if ( pActors[uActorID].ActorHasItems[1].uItemID == uItemID )
168 pActors[uActorID].ActorHasItems[1].Reset();
169 }
170 }
171 }
172
173 //----- (0040894B) --------------------------------------------------------
174 bool Actor::CanAct()
175 {
176 bool isparalyzed; // esi@1
177 bool isstoned; // edi@2
178
179 isstoned = (signed __int64)this->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0;// stoned
180 isparalyzed = (signed __int64)this->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0;// paralyzed
181 return !(isstoned || isparalyzed || this->uAIState == Dying || this->uAIState == Dead
182 || this->uAIState == Removed || this->uAIState == Summoned || this->uAIState == Disabled);
183 }
184
185 //----- (004089C7) --------------------------------------------------------
186 bool Actor::IsNotAlive()
187 {
188 bool isstoned; // esi@1
189
190 isstoned = (signed __int64)this->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0;// stoned
191 return (isstoned || (uAIState == Dying) || (uAIState == Dead) || (uAIState == Removed) || (uAIState == Summoned) || (uAIState == Disabled));
192 }
193
194 //----- (004086E9) --------------------------------------------------------
195 void Actor::SetRandomGoldIfTheresNoItem()
196 {
197 int v2; // edi@1
198
199 v2 = 0;
200 if ( !this->ActorHasItems[3].uItemID )
201 {
202 if ( this->pMonsterInfo.uTreasureDiceRolls )
203 {
204 for (int i = 0; i < this->pMonsterInfo.uTreasureDiceRolls; i++)
205 v2 += rand() % this->pMonsterInfo.uTreasureDiceSides + 1;
206 if ( v2 )
207 {
208 this->ActorHasItems[3].uItemID = 197;
209 this->ActorHasItems[3].uSpecEnchantmentType = v2; //actual gold amount
210 }
211 }
212 }
213 if ( rand() % 100 < this->pMonsterInfo.uTreasureDropChance )
214 {
215 if ( this->pMonsterInfo.uTreasureLevel )
216 pItemsTable->GenerateItem(this->pMonsterInfo.uTreasureLevel, this->pMonsterInfo.uTreasureType, &this->ActorHasItems[2]);
217 }
218 this->uAttributes |= ACTOR_HAS_ITEM;
219 }
220
221 //----- (00404AC7) --------------------------------------------------------
222 void Actor::AI_SpellAttack(unsigned int uActorID, AIDirection *pDir, int uSpellID, int a4, unsigned int uSkillLevel)
223 {
224 Actor *actorPtr; // esi@1
225 unsigned int realPoints; // edi@1
226 unsigned int masteryLevel; // eax@1
227 int v8; // edi@16
228 signed int v10; // ecx@22
229 int v19; // edi@34
230 int v20; // eax@35
231 signed int v23; // eax@41
232 int v28; // st6@50
233 int v30; // esi@50
234 int v31; // ST3C_4@51
235 unsigned int v32; // edi@51
236 signed int v36; // eax@67
237 int v39; // ecx@75
238 int v42; // ecx@91
239 int v44; // ecx@100
240 int v48; // ecx@110
241 int v51; // ecx@130
242 int v54; // ecx@138
243 int v59; // edi@146
244 int v61; // edi@146
245 signed int v63; // edi@146
246 int v68; // edi@168
247 signed int v70; // ecx@172
248 int v79; // edx@185
249 int v80; // eax@185
250 signed int v91; // eax@200
251 int v94; // ecx@208
252 int v96; // ecx@217
253 int pitch; // [sp+2Ch] [bp-A4h]@51
254 int v114; // [sp+48h] [bp-88h]@41
255 SpriteObject a1; // [sp+4Ch] [bp-84h]@1
256 int v116; // [sp+BCh] [bp-14h]@49
257 int v118; // [sp+C4h] [bp-Ch]@29
258 int v119; // [sp+C8h] [bp-8h]@48
259 int v120; // [sp+CCh] [bp-4h]@1
260 int spellnuma; // [sp+D8h] [bp+8h]@29
261 int spellnumb; // [sp+D8h] [bp+8h]@48
262 int spellnumc; // [sp+D8h] [bp+8h]@50
263 int spellnume; // [sp+D8h] [bp+8h]@179
264 int a1a; // [sp+E0h] [bp+10h]@34
265 int a1c; // [sp+E0h] [bp+10h]@184
266
267
268 actorPtr = &pActors[uActorID];
269 realPoints = uSkillLevel & 0x3F;
270 masteryLevel = SkillToMastery(uSkillLevel);
271
272 switch (uSpellID)
273 {
274 case SPELL_FIRE_FIRE_BOLT:
275 case SPELL_FIRE_FIREBALL:
276 case SPELL_FIRE_INCINERATE:
277 case SPELL_AIR_LIGHNING_BOLT:
278 case SPELL_WATER_ICE_BOLT:
279 case SPELL_WATER_ACID_BURST:
280 case SPELL_EARTH_BLADES:
281 case SPELL_EARTH_ROCK_BLAST:
282 case SPELL_MIND_MIND_BLAST:
283 case SPELL_MIND_PSYCHIC_SHOCK:
284 case SPELL_BODY_HARM:
285 case SPELL_LIGHT_LIGHT_BOLT:
286 case SPELL_DARK_TOXIC_CLOUD:
287 case SPELL_DARK_DRAGON_BREATH:
288 a1.uType = stru_4E3ACC[uSpellID].uType;
289 a1.uObjectDescID = GetObjDescId(uSpellID);
290 a1.stru_24.Reset();
291 a1.spell_id = uSpellID;
292 a1.spell_level = uSkillLevel;
293 a1.vPosition.x = actorPtr->vPosition.x;
294 a1.spell_skill = 0;
295 a1.vPosition.y = actorPtr->vPosition.y;
296 a1.vPosition.z = actorPtr->vPosition.z + ((signed int)actorPtr->uActorHeight >> 1);
297 a1.uFacing = LOWORD(pDir->uYawAngle);
298 a1.uSoundID = 0;
299 a1.uAttributes = 0;
300 a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, a1.vPosition.z);
301 a1.uSpriteFrameID = 0;
302 a1.spell_caster_pid = PID(OBJECT_Actor, uActorID);
303 a1.spell_target_pid = 0;
304 if ((double)pDir->uDistance < 307.2 )
305 a1.field_60_distance_related_prolly_lod = 0;
306 else if ( pDir->uDistance < 1024 )
307 a1.field_60_distance_related_prolly_lod = 1;
308 else if ( pDir->uDistance < 2560 )
309 a1.field_60_distance_related_prolly_lod = 2;
310 else
311 a1.field_60_distance_related_prolly_lod = 3;
312
313 a1.field_61 = 2;
314 v91 = a1.Create(pDir->uYawAngle, pDir->uPitchAngle, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
315 if ( v91 != -1 )
316 {
317 pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], PID(OBJECT_Item, v91), 0, -1, 0, 0, 0, 0);
318 return;
319 }
320 return;
321 break;
322
323 case SPELL_FIRE_HASTE:
324 if (masteryLevel == 1 || masteryLevel == 2)
325 v39 = 60 * (realPoints + 60);
326 else if (masteryLevel == 3 )
327 v39 = 180 * (realPoints + 20);
328 else if (masteryLevel == 4 )
329 v39 = 240 * (realPoints + 15);
330 else
331 v39 = 0;
332 actorPtr->pActorBuffs[ACTOR_BUFF_HASTE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(v39 << 7) * 0.033333335),
333 masteryLevel, 0, 0, 0);
334 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFF3C1Eu);
335 pAudioPlayer->PlaySound((SoundID)10040, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
336 return;
337
338 case SPELL_FIRE_METEOR_SHOWER:
339 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
340 return;
341 v114 = pParty->vPosition.z + 2500;
342 v23 = 8;
343 if (masteryLevel == 2)
344 v23 = 10;
345 else if (masteryLevel == 3)
346 v23 = 12;
347 else if (masteryLevel == 4)
348 v23 = 14;
349 spellnumb = 0;
350 v28 = 0;
351 for ( int i = 0; i < v23; i++)
352 {
353 v30 = rand() % 1000;
354 spellnumc = v30 - 2500;
355 v120 = v28 * v28;
356 v119 = spellnumb * spellnumb;
357 if ( sqrt((float)(spellnumc * spellnumc + v119 + v120)) <= 1.0 )
358 {
359 v32 = 0;
360 pitch = 0;
361 }
362 else
363 {
364 v31 = (signed __int64)sqrt((float)(v119 + v120));
365 v32 = stru_5C6E00->Atan2(spellnumb, (int)v28);
366 pitch = stru_5C6E00->Atan2(v31, (int)spellnumc);
367 }
368 a1.stru_24.Reset();
369 a1.uType = stru_4E3ACC[uSpellID].uType;
370 a1.uObjectDescID = GetObjDescId(uSpellID);
371 a1.spell_level = uSkillLevel;
372 a1.vPosition.x = pParty->vPosition.x;
373 a1.vPosition.y = pParty->vPosition.y;
374 a1.vPosition.z = v30 + v114;
375 a1.spell_id = SPELL_FIRE_METEOR_SHOWER;
376 a1.spell_skill = 0;
377 a1.uAttributes = 0;
378 a1.uSectorID = 0;
379 a1.uSpriteFrameID = 0;
380 a1.spell_caster_pid = PID(OBJECT_Actor, uActorID);
381 a1.spell_target_pid = 0;
382 a1.field_60_distance_related_prolly_lod = stru_50C198._427546(v30 + 2500);
383 a1.uFacing = v32;
384 a1.uSoundID = 0;
385 if (pDir->uDistance < 307.2 )
386 a1.field_60_distance_related_prolly_lod = 0;
387 else if ( pDir->uDistance < 1024 )
388 a1.field_60_distance_related_prolly_lod = 1;
389 else if ( pDir->uDistance < 2560 )
390 a1.field_60_distance_related_prolly_lod = 2;
391 else
392 a1.field_60_distance_related_prolly_lod = 3;
393 a1.field_61 = 2;
394 v36 = a1.Create(v32, pitch, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
395 if ( v36 != -1 )
396 pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[9], PID(OBJECT_Item, v36), 0, -1, 0, 0, 0, 0);
397 spellnumb = rand() % 1024 - 512;
398 v28 = rand() % 1024 - 512;
399 }
400 return;
401 break;
402
403 case SPELL_AIR_SPARKS:
404 if (masteryLevel == 2 )
405 v10 = 5;
406 else if (masteryLevel == 3 )
407 v10 = 7;
408 else if (masteryLevel == 4 )
409 v10 = 9;
410 else
411 v10 = 3;
412 spellnuma = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360;
413 a1.uType = stru_4E3ACC[uSpellID].uType;
414 v118 = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360 / (v10 - 1);
415 a1.uObjectDescID = GetObjDescId(uSpellID);
416
417 a1.stru_24.Reset();
418 a1.spell_id = SPELL_AIR_SPARKS;
419 a1.spell_level = uSkillLevel;
420 a1.vPosition.x = actorPtr->vPosition.x;
421 a1.spell_skill = 0;
422 a1.vPosition.y = actorPtr->vPosition.y;
423 a1.vPosition.z = actorPtr->vPosition.z + ((signed int)actorPtr->uActorHeight >> 1);
424 a1.uFacing = pDir->uYawAngle;
425 a1.uSoundID = 0;
426 a1.uAttributes = 0;
427 a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, a1.vPosition.z);
428 a1.spell_caster_pid = PID(OBJECT_Actor, uActorID);
429 a1.uSpriteFrameID = 0;
430 a1.spell_target_pid = 0;
431 a1.field_60_distance_related_prolly_lod = 3;
432 v19 = spellnuma / -2;
433 a1a = spellnuma / 2;
434 if ( spellnuma / -2 > spellnuma / 2 )
435 v20 = spellnuma / 2;
436 else
437 {
438 do
439 {
440 a1.uFacing = v19 + LOWORD(pDir->uYawAngle);
441 v20 = a1.Create((signed __int16)a1.uFacing, pDir->uPitchAngle,
442 pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
443 v19 += v118;
444 }
445 while ( v19 <= a1a );
446 }
447 if ( v20 != -1 )
448 {
449 pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[15], PID(OBJECT_Item, v20), 0, -1, 0, 0, 0, 0);
450 return;
451 }
452 return;
453 break;
454
455 case SPELL_AIR_SHIELD:
456 if (masteryLevel == 1 || masteryLevel == 2)
457 v8 = 300 * realPoints + 3840;
458 else if (masteryLevel == 3 )
459 v8 = 900 * realPoints + 3840;
460 else if (masteryLevel == 4 )
461 v8 = 3600 * (realPoints + 64);
462 else
463 v8 = 0;
464 actorPtr->pActorBuffs[ACTOR_BUFF_SHIELD].Apply(
465 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v8 << 7) * 0.033333335),
466 masteryLevel, 0, 0, 0);
467 return;
468
469 case SPELL_EARTH_STONESKIN:
470 if (masteryLevel == 1 || masteryLevel == 2)
471 v44 = 300 * realPoints + 3840;
472 else if (masteryLevel == 3 )
473 v44 = 900 * realPoints + 3840;
474 else if (masteryLevel == 4 )
475 v44 = 3600 * (realPoints + 64);
476 else
477 v44 = 0;
478 actorPtr->pActorBuffs[ACTOR_BUFF_STONESKIN].Apply(
479 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v44 << 7) * 0.033333335),
480 masteryLevel, realPoints + 5, 0, 0);
481 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0x5C310Eu);
482 pAudioPlayer->PlaySound((SoundID)13040, PID(OBJECT_Actor,uActorID), 0, -1, 0, 0, 0, 0);
483 return;
484
485 case SPELL_SPIRIT_BLESS:
486 if (masteryLevel == 1 || masteryLevel == 2)
487 v42 = 300 * realPoints + 3840;
488 else if (masteryLevel == 3 )
489 v42 = 900 * realPoints + 3840;
490 else if (masteryLevel == 4 )
491 v42 = 1200 * realPoints + 3840;
492 else
493 v42 = 0;
494 actorPtr->pActorBuffs[ACTOR_BUFF_BLESS].Apply(
495 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v42 << 7) * 0.033333335),
496 masteryLevel, realPoints + 5, 0, 0);
497 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
498 pAudioPlayer->PlaySound((SoundID)14010, PID(OBJECT_Actor,uActorID), 0, -1, 0, 0, 0, 0);
499 return;
500 break;
501
502 case SPELL_SPIRIT_FATE:
503 if (masteryLevel == 1 || masteryLevel == 2)
504 v48 = 2 * realPoints + 40;
505 else if (masteryLevel == 3 )
506 v48 = 3 * realPoints + 60;
507 else if (masteryLevel == 4 )
508 v48 = 2 * (3 * realPoints + 60);
509 else
510 v48 = 0;
511 actorPtr->pActorBuffs[ACTOR_BUFF_FATE].Apply(pParty->uTimePlayed + 1280, masteryLevel, v48, 0, 0);
512 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
513 pAudioPlayer->PlaySound((SoundID)14020, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
514 return;
515
516 case SPELL_SPIRIT_HEROISM:
517 if (masteryLevel == 1 || masteryLevel == 2)
518 v54 = 300 * realPoints + 3840;
519 else if (masteryLevel == 3 )
520 v54 = 900 * realPoints + 3840;
521 else if (masteryLevel == 4 )
522 v54 = 1200 * realPoints + 3840;
523 else
524 v54 = 0;
525 actorPtr->pActorBuffs[ACTOR_BUFF_HEROISM].Apply(
526 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v54 << 7) * 0.033333335),
527 masteryLevel, realPoints + 5, 0, 0);
528 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0xC8C805u);
529 pAudioPlayer->PlaySound((SoundID)14060, PID(OBJECT_Actor,uActorID), 0, -1, 0, 0, 0, 0);
530 return;
531
532 case SPELL_BODY_HAMMERHANDS:
533 if ( (signed int)masteryLevel <= 0 || (signed int)masteryLevel > 4 )
534 v51 = 0;
535 else
536 v51 = 3600 * realPoints;
537 actorPtr->pActorBuffs[ACTOR_BUFF_PAIN_HAMMERHANDS].Apply(
538 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v51 << 7) * 0.033333335),
539 masteryLevel,
540 realPoints,
541 0,
542 0);
543 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xA81376u);
544 pAudioPlayer->PlaySound((SoundID)16060, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
545 return;
546
547 case SPELL_BODY_POWER_CURE:
548 actorPtr->sCurrentHP += 5 * realPoints + 10;
549 if ( actorPtr->sCurrentHP >= (signed int)actorPtr->pMonsterInfo.uHP )
550 actorPtr->sCurrentHP = LOWORD(actorPtr->pMonsterInfo.uHP);
551 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xA81376u);
552 pAudioPlayer->PlaySound((SoundID)14020, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
553 return;
554
555 case SPELL_LIGHT_DISPEL_MAGIC:
556 for (int i = 0; i < 20; i++ )
557 pParty->pPartyBuffs[i].Reset();
558 for (int i = 1; i <= 4; i++)
559 {
560 v59 = pPlayers[i]->GetParameterBonus(pPlayers[i]->GetActualWillpower());
561 v61 = (pPlayers[i]->GetParameterBonus(pPlayers[i]->GetActualIntelligence()) + v59) / 2;
562 v63 = v61 + pPlayers[i]->GetParameterBonus(pPlayers[i]->GetActualLuck()) + 30;
563 if ( rand() % v63 < 30 )
564 {
565 for (uint k = 0; k < pPlayers[i]->pPlayerBuffs.size(); k++)
566 pPlayers[i]->pPlayerBuffs[k].Reset();
567 pOtherOverlayList->_4418B1(11210, i + 99, 0, 65536);
568 }
569 }
570 pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[80], PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
571 return;
572
573 case SPELL_LIGHT_DAY_OF_PROTECTION:
574 if (masteryLevel == 1 || masteryLevel == 2)
575 v96 = 300 * realPoints + 3840;
576 else if (masteryLevel == 3 )
577 {
578 LOWORD(realPoints) = 3 * realPoints;
579 v96 = 900 * (uSkillLevel & 0x3F) + 3840;
580 }
581 else if (masteryLevel == 4 )
582 {
583 v96 = 1200 * realPoints + 3840;
584 LOWORD(realPoints) = 4 * realPoints;
585 }
586 else
587 {
588 LOWORD(realPoints) = uSkillLevel;
589 v96 = 0;
590 }
591 actorPtr->pActorBuffs[ACTOR_BUFF_DAY_OF_PROTECTION].Apply(
592 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v96 << 7) * 0.033333335),
593 masteryLevel, realPoints, 0, 0);
594 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFFFFFFu);
595 pAudioPlayer->PlaySound((SoundID)17070, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
596 return;
597
598 case SPELL_LIGHT_HOUR_OF_POWER:
599 if (masteryLevel == 1 || masteryLevel == 2)
600 v94 = 300 * realPoints + 3840;
601 else if (masteryLevel == 3)
602 v94 = 900 * realPoints + 3840;
603 else if (masteryLevel == 4)
604 v94 = 1200 * realPoints + 3840;
605 else
606 v94 = 0;
607 actorPtr->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].Apply(
608 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v94 << 7) * 0.033333335),
609 masteryLevel, realPoints + 5, 0, 0);
610 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr, 0xFFFFFFu);
611 pAudioPlayer->PlaySound((SoundID)17080, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
612 return;
613
614 case SPELL_DARK_SHARPMETAL:
615 if (masteryLevel == 2)
616 v70 = 5;
617 else if (masteryLevel == 3)
618 v70 = 7;
619 else if (masteryLevel == 4)
620 v70 = 9;
621 else
622 v70 = 3;
623
624 spellnume = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360;
625 a1.uType = stru_4E3ACC[uSpellID].uType;
626 v116 = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360 / (v70 - 1);
627 a1.uObjectDescID = GetObjDescId(uSpellID);
628 a1.stru_24.Reset();
629 a1.spell_id = uSpellID;
630 a1.spell_level = uSkillLevel;
631 a1.vPosition.x = actorPtr->vPosition.x;
632 a1.spell_skill = 0;
633 a1.vPosition.y = actorPtr->vPosition.y;
634 a1.vPosition.z = actorPtr->vPosition.z + ((signed int)actorPtr->uActorHeight >> 1);
635 a1.uFacing = pDir->uYawAngle;
636 a1.uSoundID = 0;
637 a1.uAttributes = 0;
638 a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, a1.vPosition.z);
639 a1.spell_caster_pid = PID(OBJECT_Actor, uActorID);
640 a1.uSpriteFrameID = 0;
641 a1.spell_target_pid = 0;
642 a1.field_60_distance_related_prolly_lod = 3;
643 a1c = spellnume / -2;
644 if ( spellnume / -2 > spellnume / 2 )
645 v80 = spellnume / -2;
646 else
647 {
648 do
649 {
650 v79 = pDir->uYawAngle;
651 a1.uFacing = a1c + LOWORD(pDir->uYawAngle);
652 v80 = a1.Create(v79, pDir->uPitchAngle,
653 pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
654 a1c += v116;
655 }
656 while ( a1c <= spellnume / 2 );
657 }
658 if ( v80 != -1 )
659 {
660 pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[93], PID(OBJECT_Item, v80), 0, -1, 0, 0, 0, 0);
661 return;
662 }
663 return;
664 break;
665
666 case SPELL_DARK_PAIN_REFLECTION:
667 if (masteryLevel == 0)
668 v68 = 0;
669 else if (masteryLevel == 1 || (masteryLevel == 2) || (masteryLevel == 3))
670 v68 = 300 * realPoints + 3840;
671 else
672 v68 = 900 * realPoints + 3840;
673 actorPtr->pActorBuffs[ACTOR_BUFF_PAIN_REFLECTION].Apply(
674 pParty->uTimePlayed + (signed int)(signed __int64)((double)(v68 << 7) * 0.033333335),
675 masteryLevel, 0, 0, 0);
676 pGame->pStru6Instance->_4A7E89_sparkles_on_actor_after_it_casts_buff(actorPtr,0x7E7E7Eu);
677 pAudioPlayer->PlaySound((SoundID)18060, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
678 return;
679 }
680 }
681
682 //----- (new func) --------------------------------------------------------
683 unsigned short Actor::GetObjDescId( int spellId )
684 {
685 for (unsigned int i = 0; i < pObjectList->uNumObjects; i++)
686 {
687 if (stru_4E3ACC[spellId].uType == pObjectList->pObjects[i].uObjectID)
688 {
689 return i;
690 break;
691 }
692 }
693 return 0;
694 }
695
696
697 //----- (0043ABB0) --------------------------------------------------------
698 bool Actor::ArePeasantsOfSameFaction(Actor *a1, Actor *a2)
699 {
700 unsigned int v2; // esi@1
701 unsigned int v3; // edi@1
702
703 v2 = a1->uAlly;
704 if ( !a1->uAlly )
705 v2 = (a1->pMonsterInfo.uID - 1) / 3 + 1;
706
707 v3 = a2->uAlly;
708 if ( !a2->uAlly )
709 v3 = (a2->pMonsterInfo.uID - 1) / 3 + 1;
710
711 if ( v2 >= 39 && v2 <= 44 && v3 >= 39 && v3 <= 44
712 || v2 >= 45 && v2 <= 50 && v3 >= 45 && v3 <= 50
713 || v2 >= 51 && v2 <= 62 && v3 >= 51 && v3 <= 62
714 || v2 >= 78 && v2 <= 83 && v3 >= 78 && v3 <= 83
715 || v2 == v3
716 )
717 return true;
718 else
719 return false;
720 }
721
722 //----- (0043AC45) --------------------------------------------------------
723 void Actor::AggroSurroundingPeasants(unsigned int uActorID, int a2)
724 {
725 int v4; // ebx@8
726 int v5; // ST1C_4@8
727 int v6; // eax@8
728
729 int x = 0; x |= 0x80000;
730 int y = 0; y |= 0x80000;
731 Actor* victim = &pActors[uActorID];
732 if ( a2 == 1 )
733 victim->uAttributes |= ACTOR_AGGRESSOR;
734
735 for (uint i = 0; i < uNumActors; ++i)
736 {
737 Actor* actor = &pActors[i];
738 if (!actor->CanAct() || i == uActorID)
739 continue;
740
741 if (Actor::ArePeasantsOfSameFaction(victim, actor))
742 {
743 v4 = abs(actor->vPosition.x - victim->vPosition.x);
744 v5 = abs(actor->vPosition.y - victim->vPosition.y);
745 v6 = abs(actor->vPosition.z - victim->vPosition.z);
746 if (int_get_vector_length(v4, v5, v6) < 4096)
747 {
748 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
749 if ( a2 == 1 )
750 actor->uAttributes |= ACTOR_AGGRESSOR;
751
752 }
753 }
754 }
755 }
756
757 //----- (00404874) --------------------------------------------------------
758 void Actor::AI_RangedAttack( unsigned int uActorID, struct AIDirection *pDir, int type, char a4 )
759 {
760 char specAb; // al@1
761 int v13; // edx@28
762
763 SpriteObject a1; // [sp+Ch] [bp-74h]@1
764
765 switch ( type )
766 {
767 case 1:
768 a1.uType = 545;
769 break;
770 case 2:
771 a1.uType = 550;
772 break;
773 case 3:
774 a1.uType = 510;
775 break;
776 case 4:
777 a1.uType = 500;
778 break;
779 case 5:
780 a1.uType = 515;
781 break;
782 case 6:
783 a1.uType = 505;
784 break;
785 case 7:
786 a1.uType = 530;
787 break;
788 case 8:
789 a1.uType = 525;
790 break;
791 case 9:
792 a1.uType = 520;
793 break;
794 case 10:
795 a1.uType = 535;
796 break;
797 case 11:
798 a1.uType = 540;
799 break;
800 case 13:
801 a1.uType = 555;
802 break;
803 default:
804 return;
805 }
806 bool found = false;
807 for ( uint i = 0; i < pObjectList->uNumObjects; i++)
808 {
809 if (pObjectList->pObjects[i].uObjectID == a1.uType)
810 {
811 a1.uObjectDescID = i;
812 found = true;
813 break;
814 }
815 }
816 if (!found)
817 {
818 Error("Item not found");
819 return;
820 }
821 a1.stru_24.Reset();
822 a1.spell_id = 0;
823 a1.vPosition.x = pActors[uActorID].vPosition.x;
824 a1.vPosition.y = pActors[uActorID].vPosition.y;
825 a1.vPosition.z = pActors[uActorID].vPosition.z - (unsigned int)(pActors[uActorID].uActorHeight * -0.75);
826 a1.spell_level = 0;
827 a1.spell_skill = 0;
828 a1.uFacing = pDir->uYawAngle;
829 a1.uSoundID = 0;
830 a1.uAttributes = 0;
831 a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, a1.vPosition.z);
832 a1.uSpriteFrameID = 0;
833 a1.spell_caster_pid = PID(OBJECT_Actor, uActorID);
834 a1.spell_target_pid = 0;
835 if (pDir->uDistance < 307.2 )
836 a1.field_60_distance_related_prolly_lod = 0;
837 else if ( pDir->uDistance < 1024 )
838 a1.field_60_distance_related_prolly_lod = 1;
839 else if ( pDir->uDistance < 2560 )
840 a1.field_60_distance_related_prolly_lod = 2;
841 else
842 a1.field_60_distance_related_prolly_lod = 3;
843
844 a1.field_61 = a4;
845 a1.Create(pDir->uYawAngle, pDir->uPitchAngle, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
846 if ( pActors[uActorID].pMonsterInfo.uSpecialAbilityType == 1 )
847 {
848 specAb = pActors[uActorID].pMonsterInfo.uSpecialAbilityDamageDiceBonus;
849 if ( specAb == 2 )
850 {
851 a1.vPosition.z += 40;
852 v13 = pDir->uYawAngle;
853 }
854 else
855 {
856 if ( specAb != 3 )
857 return;
858 a1.Create(pDir->uYawAngle + 30, //TODO find out why the YawAngle change
859 pDir->uPitchAngle, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
860 v13 = pDir->uYawAngle - 30;
861 }
862 a1.Create(v13, pDir->uPitchAngle, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
863 }
864 return;
865 }
866
867 //----- (00404736) --------------------------------------------------------
868 void Actor::Explode( unsigned int uActorID )
869 {
870 SpriteObject a1; // [sp+Ch] [bp-78h]@1
871
872 a1.uType = 600;
873 a1.uObjectDescID = GetObjDescId(a1.uType);
874 a1.stru_24.Reset();
875 a1.spell_id = 0;
876 a1.spell_level = 0;
877 a1.spell_skill = 0;
878 a1.vPosition.x = pActors[uActorID].vPosition.x;
879 a1.vPosition.y = pActors[uActorID].vPosition.y;
880 a1.vPosition.z = pActors[uActorID].vPosition.z - (unsigned int)(pActors[uActorID].uActorHeight * -0.75);
881 a1.uFacing = 0;
882 a1.uSoundID = 0;
883 a1.uAttributes = 0;
884 a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, a1.vPosition.z);
885 a1.uSpriteFrameID = 0;
886 a1.spell_caster_pid = PID(OBJECT_Actor, uActorID);
887 a1.spell_target_pid = 0;
888 a1.field_60_distance_related_prolly_lod = 3;
889 a1.field_61 = 4;
890 a1.Create(0, 0, 0, 0);
891 return;
892 }
893
894 //----- (004040E9) --------------------------------------------------------
895 // // Get direction vector from object1 to object2,
896 // // distance from object1 to object2 and Euler angles of the direction vector
897 // //
898 // //
899 // // object1 & object2 format : objectType | (objectID << 3)
900 // // objectType == 2 - SpriteObject
901 // // objectType == 3 - Actor
902 // // objectType == 4 - Party
903 // // objectType == 5 - Decoration
904 // //
905 // // originally this function had following prototype:
906 // // struct DirectionInfo GetDirectionInfo(signed int object1, signed int object2, signed int a4)
907 // // but compiler converts functions returning structures by value in the such way
908 void Actor::GetDirectionInfo( unsigned int uObj1ID, unsigned int uObj2ID, struct AIDirection *pOut, int a4 )
909 {
910 signed int v4; // eax@1
911 signed int v5; // ecx@1
912 int v18; // edx@15
913 float v31; // st7@45
914 float v32; // st6@45
915 float v33; // st7@45
916 Vec3_int_ v37; // [sp-10h] [bp-5Ch]@15
917 AIDirection v41; // [sp+14h] [bp-38h]@46
918 float outy2; // [sp+38h] [bp-14h]@33
919 float outx2; // [sp+3Ch] [bp-10h]@33
920 int outz; // [sp+40h] [bp-Ch]@6
921 int outy; // [sp+44h] [bp-8h]@6
922 int outx; // [sp+48h] [bp-4h]@6
923 float a4a; // [sp+58h] [bp+Ch]@45
924
925 v4 = PID_ID(uObj1ID);
926 //v6 = uObj2ID;
927 v5 = PID_ID(uObj2ID);
928 switch( PID_TYPE(uObj1ID) )
929 {
930 case OBJECT_Item:
931 {
932 outx = pSpriteObjects[v4].vPosition.x;
933 outy = pSpriteObjects[v4].vPosition.y;
934 outz = pSpriteObjects[v4].vPosition.z;
935 break;
936 }
937 case OBJECT_Actor:
938 {
939 outx = pActors[v4].vPosition.x;
940 outy = pActors[v4].vPosition.y;
941 outz = pActors[v4].vPosition.z - (unsigned int)(signed __int64)((double)pActors[v4].uActorHeight * -0.75);
942 break;
943 }
944 case OBJECT_Player:
945 {
946 if ( !v4 )
947 {
948 outx = pParty->vPosition.x;
949 outy = pParty->vPosition.y;
950 outz = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
951 break;
952 }
953 if ( v4 == 4 )
954 {
955 v18 = pParty->sRotationY - stru_5C6E00->uIntegerHalfPi;
956 v37.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
957 v37.x = pParty->vPosition.x;
958 v37.y = pParty->vPosition.y;
959 Vec3_int_::Rotate(24, v18, 0, v37, &outx, &outy, &outz);
960 break;
961 }
962 if ( v4 == 3 )
963 {
964 v18 = pParty->sRotationY - stru_5C6E00->uIntegerHalfPi;
965 v37.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
966 v37.x = pParty->vPosition.x;
967 v37.y = pParty->vPosition.y;
968 Vec3_int_::Rotate(8, v18, 0, v37, &outx, &outy, &outz);
969 break;
970 }
971 if ( v4 == 2 )
972 {
973 v37.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
974 v18 = stru_5C6E00->uIntegerHalfPi + pParty->sRotationY;
975 v37.x = pParty->vPosition.x;
976 v37.y = pParty->vPosition.y;
977 Vec3_int_::Rotate(8, v18, 0, v37, &outx, &outy, &outz);
978 break;
979 }
980 if ( v4 == 1 )
981 {
982 v37.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
983 v18 = stru_5C6E00->uIntegerHalfPi + pParty->sRotationY;
984 v37.x = pParty->vPosition.x;
985 v37.y = pParty->vPosition.y;
986 Vec3_int_::Rotate(24, v18, 0, v37, &outx, &outy, &outz);
987 break;
988 }
989 }
990 case OBJECT_Decoration:
991 {
992 outx = pLevelDecorations[v4].vPosition.x;
993 outy = pLevelDecorations[v4].vPosition.y;
994 outz = pLevelDecorations[v4].vPosition.z;
995 break;
996 }
997 default:
998 {
999 outz = 0;
1000 outy = 0;
1001 outx = 0;
1002 break;
1003 }
1004 case OBJECT_BModel:
1005 {
1006 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
1007 {
1008 outx = (pIndoor->pFaces[v4].pBounding.x1 + pIndoor->pFaces[v4].pBounding.x2) >> 1;
1009 outy = (pIndoor->pFaces[v4].pBounding.y1 + pIndoor->pFaces[v4].pBounding.y2) >> 1;
1010 outz = (pIndoor->pFaces[v4].pBounding.z1 + pIndoor->pFaces[v4].pBounding.z2) >> 1;
1011 }
1012 break;
1013 }
1014 }
1015
1016 switch( PID_TYPE(uObj2ID) )
1017 {
1018 case OBJECT_Item:
1019 {
1020 outx2 = (float)pSpriteObjects[v5].vPosition.x;
1021 outy2 =(float) pSpriteObjects[v5].vPosition.y;
1022 a4 = pSpriteObjects[v5].vPosition.z;
1023 break;
1024 }
1025 case OBJECT_Actor:
1026 {
1027 outx2 = (float)pActors[v5].vPosition.x;
1028 outy2 = (float)pActors[v5].vPosition.y;
1029 a4 = pActors[v5].vPosition.z - (unsigned int)(signed __int64)((double)pActors[v5].uActorHeight * -0.75);
1030 break;
1031 }
1032 case OBJECT_Player:
1033 {
1034 outx2 = (float)pParty->vPosition.x;
1035 outy2 = (float)pParty->vPosition.y;
1036 if ( !a4 )
1037 a4 = pParty->sEyelevel;
1038 a4 = pParty->vPosition.z + a4;
1039 break;
1040 }
1041 case OBJECT_Decoration:
1042 {
1043 outx2 = (float)pLevelDecorations[v5].vPosition.x;
1044 outy2 = (float)pLevelDecorations[v5].vPosition.y;
1045 a4 = pLevelDecorations[v5].vPosition.z;
1046 break;
1047 }
1048 default:
1049 {
1050 outx2 = 0.0;
1051 outy2 = 0.0;
1052 a4 = 0;
1053 break;
1054 }
1055 case OBJECT_BModel:
1056 {
1057 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
1058 {
1059 outx2 = (float)((pIndoor->pFaces[v5].pBounding.x1 + pIndoor->pFaces[v5].pBounding.x2) >> 1);
1060 outy2 = (float)((pIndoor->pFaces[v5].pBounding.y1 + pIndoor->pFaces[v5].pBounding.y2) >> 1);
1061 a4 = (pIndoor->pFaces[v5].pBounding.z1 + pIndoor->pFaces[v5].pBounding.z2) >> 1;
1062 }
1063 break;
1064 }
1065 }
1066
1067 v31 = (float)outx2 - (float)outx;
1068 v32 = (float)outy2 - (float)outy;
1069 a4a = (float)a4 - (float)outz;
1070 outx2 = v32 * v32;
1071 outy2 = v31 * v31;
1072 v33 = sqrt(a4a * a4a + outy2 + outx2);
1073 if ( v33 <= 1.0 )
1074 {
1075 pOut->vDirection.x = 65536;
1076 pOut->vDirection.y = 0;
1077 pOut->vDirection.z = 0;
1078 pOut->uDistance = 1;
1079 pOut->uDistanceXZ = 1;
1080 pOut->uYawAngle = 0;
1081 pOut->uPitchAngle = 0;
1082 }
1083 else
1084 {
1085 pOut->vDirection.x = (int32_t)(1.0 / v33 * v31 * 65536.0);
1086 pOut->vDirection.y = (int32_t)(1.0 / v33 * v32 * 65536.0);
1087 pOut->vDirection.z = (int32_t)(1.0 / v33 * a4a * 65536.0);
1088 pOut->uDistance = (uint)v33;
1089 pOut->uDistanceXZ = (uint)sqrt(outy2 + outx2);
1090 pOut->uYawAngle = stru_5C6E00->Atan2((signed __int64)v31, (signed __int64)v32);
1091 pOut->uPitchAngle = stru_5C6E00->Atan2(pOut->uDistanceXZ, (signed __int64)a4a);
1092 }
1093 }
1094
1095 //----- (00404030) --------------------------------------------------------
1096 void Actor::AI_FaceObject(unsigned int uActorID, unsigned int uObjID, int _48, AIDirection *a4)
1097 {
1098 AIDirection *v7; // eax@3
1099 AIDirection v1; // eax@3
1100 AIDirection a3; // [sp+8h] [bp-38h]@4
1101
1102 if ( rand() % 100 >= 5 )
1103 {
1104 //v9 = &pActors[uActorID];
1105 if ( !a4 )
1106 {
1107 Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), uObjID, &v1, 0);
1108 v7 = &v1;
1109 }
1110 else
1111 v7 = a4;
1112 pActors[uActorID].uYawAngle = v7->uYawAngle;
1113 pActors[uActorID].uCurrentActionTime = 0;
1114 pActors[uActorID].vVelocity.z = 0;
1115 pActors[uActorID].vVelocity.y = 0;
1116 pActors[uActorID].vVelocity.x = 0;
1117 pActors[uActorID].uPitchAngle = v7->uPitchAngle;
1118 pActors[uActorID].uCurrentActionLength = 256;
1119 pActors[uActorID].uAIState = Interacting;
1120 pActors[uActorID].UpdateAnimation();
1121 }
1122 else
1123 Actor::AI_Bored(uActorID, uObjID, a4);
1124 }
1125
1126 //----- (00403F58) --------------------------------------------------------
1127 void Actor::AI_StandOrBored(unsigned int uActorID, signed int uObjID, int uActionLength, AIDirection *a4)
1128 {
1129 if (rand() % 2)//0 or 1
1130 AI_Bored(uActorID, uObjID, a4);
1131 else
1132 AI_Stand(uActorID, uObjID, uActionLength, a4);
1133 }
1134
1135 //----- (00403EB6) --------------------------------------------------------
1136 void Actor::AI_Stand(unsigned int uActorID, unsigned int object_to_face_pid, unsigned int uActionLength, AIDirection *a4)
1137 {
1138 assert(uActorID < uNumActors);
1139 // Actor* actor = &pActors[uActorID];
1140
1141 AIDirection a3;
1142 if (!a4)
1143 {
1144 Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), object_to_face_pid, &a3, 0);
1145 a4 = &a3;
1146 }
1147
1148 pActors[uActorID].uAIState = Standing;
1149 if (!uActionLength)
1150 pActors[uActorID].uCurrentActionLength = rand() % 256 + 256;// от 256 до 256 + 256
1151 else
1152 pActors[uActorID].uCurrentActionLength = uActionLength;
1153 pActors[uActorID].uCurrentActionTime = 0;
1154 pActors[uActorID].uYawAngle = a4->uYawAngle;
1155 pActors[uActorID].uPitchAngle = a4->uPitchAngle;
1156 pActors[uActorID].vVelocity.z = 0;
1157 pActors[uActorID].vVelocity.y = 0;
1158 pActors[uActorID].vVelocity.x = 0;
1159 pActors[uActorID].UpdateAnimation();
1160 }
1161
1162 //----- (00403E61) --------------------------------------------------------
1163 void __fastcall Actor::StandAwhile(unsigned int uActorID)
1164 {
1165 pActors[uActorID].uCurrentActionLength = rand() % 128 + 128;
1166 pActors[uActorID].uCurrentActionTime = 0;
1167 pActors[uActorID].uAIState = Standing;
1168 pActors[uActorID].vVelocity.z = 0;
1169 pActors[uActorID].vVelocity.y = 0;
1170 pActors[uActorID].vVelocity.x = 0;
1171 pActors[uActorID].UpdateAnimation();
1172 }
1173
1174 //----- (00403C6C) --------------------------------------------------------
1175 void Actor::AI_MeleeAttack(unsigned int uActorID, signed int sTargetPid, struct AIDirection *arg0)
1176 {
1177 int16_t v6; // esi@6
1178 int16_t v7; // edi@6
1179 signed int v8; // eax@7
1180 Vec3_int_ v10; // ST04_12@9
1181 AIDirection *v12; // eax@11
1182 AIDirection a3; // [sp+Ch] [bp-48h]@12
1183 AIDirection v20; // [sp+28h] [bp-2Ch]@12
1184 int v23; // [sp+4Ch] [bp-8h]@6
1185 unsigned int v25; // [sp+5Ch] [bp+8h]@13
1186
1187 assert(uActorID < uNumActors);
1188
1189 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY && pActors[uActorID].pMonsterInfo.uAIType == 1 )
1190 {
1191 Actor::AI_Stand(uActorID, sTargetPid, 0, arg0);
1192 return;
1193 }
1194
1195 if ( PID_TYPE(sTargetPid) == OBJECT_Actor)
1196 {
1197 v8 = PID_ID(sTargetPid);
1198 v6 = pActors[v8].vPosition.x;
1199 v7 = pActors[v8].vPosition.y;
1200 v23 = (int)(pActors[v8].uActorHeight * 0.75 + pActors[v8].vPosition.z);
1201 }
1202 else if ( PID_TYPE(sTargetPid) == OBJECT_Player)
1203 {
1204 v6 = pParty->vPosition.x;
1205 v7 = pParty->vPosition.y;
1206 v23 = pParty->vPosition.z + pParty->sEyelevel;
1207 }
1208 else
1209 {
1210 Error("Should not get here");
1211 return;
1212 }
1213
1214 v10.x = pActors[uActorID].vPosition.x;
1215 v10.y = pActors[uActorID].vPosition.y;
1216 v10.z = (int32_t)(pActors[uActorID].uActorHeight * 0.75 + pActors[uActorID].vPosition.z);
1217
1218 if ( sub_407A1C((int)v6, (int)v7, v23, v10) )
1219 {
1220 if (arg0 != nullptr)
1221 v12 = arg0;
1222 else
1223 {
1224 Actor::GetDirectionInfo(PID(OBJECT_Actor, uActorID), sTargetPid, &a3, 0);
1225 v12 = &a3;
1226 }
1227 pActors[uActorID].uYawAngle = LOWORD(v12->uYawAngle);
1228 pActors[uActorID].uCurrentActionLength = pSpriteFrameTable->pSpriteSFrames[pActors[uActorID].pSpriteIDs[ANIM_AtkMelee]].uAnimLength * 8;
1229 pActors[uActorID].uCurrentActionTime = 0;
1230 pActors[uActorID].uAIState = AttackingMelee;
1231 Actor::PlaySound(uActorID, 0);
1232 v25 = pMonsterStats->pInfos[pActors[uActorID].pMonsterInfo.uID].uRecoveryTime;
1233 if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0 )
1234 v25 *= 2;
1235 if ( pParty->bTurnBasedModeOn != 1 )
1236 pActors[uActorID].pMonsterInfo.uRecoveryTime = (int)(flt_6BE3A8_debug_recmod2 * v25 * 2.133333333333333);
1237 else
1238 pActors[uActorID].pMonsterInfo.uRecoveryTime = v25;
1239 pActors[uActorID].vVelocity.z = 0;
1240 pActors[uActorID].vVelocity.y = 0;
1241 pActors[uActorID].vVelocity.x = 0;
1242 pActors[uActorID].UpdateAnimation();
1243 }
1244 else
1245 Actor::AI_Pursue1(uActorID, sTargetPid, rand() % 2, 64, arg0);
1246 }
1247
1248 //----- (00438CF3) --------------------------------------------------------
1249 void Actor::ApplyFineForKillingPeasant(unsigned int uActorID)
1250 {
1251 if ( uLevelMapStatsID == 0 || !pActors[uActorID].IsPeasant())
1252 return;
1253
1254 if ( (uLevelMapStatsID == 6 || uLevelMapStatsID == 7) && pParty->IsPartyEvil()) //celeste and bracada
1255 return;
1256
1257 if ( (uLevelMapStatsID == 5 || uLevelMapStatsID == 8) && pParty->IsPartyGood()) // the pit and deyja
1258 return;
1259
1260 pParty->uFine += 100 * (pMapStats->pInfos[uLevelMapStatsID]._steal_perm + pActors[uActorID].pMonsterInfo.uLevel + pParty->GetPartyReputation());
1261 if ( pParty->uFine < 0 )
1262 pParty->uFine = 0;
1263 if ( pParty->uFine > 4000000 )
1264 pParty->uFine = 4000000;
1265
1266 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
1267 {
1268 if (pOutdoor->ddm.uReputation < 10000)
1269 pOutdoor->ddm.uReputation++;
1270 }
1271 else if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
1272 {
1273 if (pIndoor->dlv.uReputation < 10000)
1274 pIndoor->dlv.uReputation++;
1275 }
1276 else assert(false);
1277
1278 if ( pParty->uFine )
1279 {
1280 for ( int i = 1; i <= 4; i++)
1281 {
1282 if ( !_449B57_test_bit(pPlayers[i]->_achieved_awards_bits, 1) )
1283 _449B7E_toggle_bit(pPlayers[i]->_achieved_awards_bits, 1, 1u);
1284 }
1285 }
1286 }
1287
1288 //----- (0043AE80) --------------------------------------------------------
1289 void Actor::AddBloodsplatOnDamageOverlay(unsigned int uActorID, int a2, signed int a3)
1290 {
1291 unsigned int v4; // esi@1
1292
1293 v4 = PID(OBJECT_Actor,uActorID);
1294 switch ( a2 )
1295 {
1296 case 1:
1297 if ( a3 )
1298 pOtherOverlayList->_4418B6(904, v4, 0, (int)(sub_43AE12(a3) * 65536.0), 0);
1299 return;
1300 case 2:
1301 if ( a3 )
1302 pOtherOverlayList->_4418B6(905, v4, 0, (int)(sub_43AE12(a3) * 65536.0), 0);
1303 return;
1304 case 3:
1305 if ( a3 )
1306 pOtherOverlayList->_4418B6(906, v4, 0, (int)(sub_43AE12(a3) * 65536.0), 0);
1307 return;
1308 case 4:
1309 if ( a3 )
1310 pOtherOverlayList->_4418B6(907, v4, 0, (int)(sub_43AE12(a3) * 65536.0), 0);
1311 return;
1312 case 5:
1313 pOtherOverlayList->_4418B6(901, v4, 0, PID(OBJECT_Actor,uActorID), 0);
1314 return;
1315 case 6:
1316 pOtherOverlayList->_4418B6(902, v4, 0, PID(OBJECT_Actor,uActorID), 0);
1317 return;
1318 case 7:
1319 pOtherOverlayList->_4418B6(903, v4, 0, PID(OBJECT_Actor,uActorID), 0);
1320 return;
1321 case 8:
1322 pOtherOverlayList->_4418B6(900, v4, 0, PID(OBJECT_Actor,uActorID), 0);
1323 return;
1324 case 9:
1325 pOtherOverlayList->_4418B6(909, v4, 0, PID(OBJECT_Actor,uActorID), 0);
1326 return;
1327 case 10:
1328 pOtherOverlayList->_4418B6(908, v4, 0, PID(OBJECT_Actor,uActorID), 0);
1329 return;
1330 default:
1331 return;
1332 }
1333 return;
1334 }
1335
1336 //----- (0043B3E0) --------------------------------------------------------
1337 int Actor::_43B3E0_CalcDamage( signed int dmgSource )
1338 {
1339 signed int v2; // ebp@1
1340 int v3; // eax@9
1341 signed int v4; // edi@9
1342 int v5; // esi@9
1343 unsigned __int16 v8; // si@21
1344 int v9; // edi@21
1345 signed int v10; // eax@23
1346 int v11; // [sp+10h] [bp-4h]@1
1347
1348 v2 = 0;
1349 v11 = 0;
1350
1351 switch( dmgSource )
1352 {
1353 case 0:
1354 if ( this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 )
1355 v2 = this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower;
1356 if ( this->pActorBuffs[ACTOR_BUFF_HEROISM].uExpireTime > 0 && this->pActorBuffs[ACTOR_BUFF_HEROISM].uPower > v2 )
1357 v2 = this->pActorBuffs[ACTOR_BUFF_HEROISM].uPower;
1358 if ( this->pActorBuffs[ACTOR_BUFF_PAIN_HAMMERHANDS].uExpireTime > 0 )
1359 v2 += this->pActorBuffs[ACTOR_BUFF_PAIN_HAMMERHANDS].uPower;
1360 v3 = this->pMonsterInfo.uAttack1DamageDiceRolls;
1361 v4 = this->pMonsterInfo.uAttack1DamageDiceSides;
1362 v5 = this->pMonsterInfo.uAttack1DamageBonus;
1363 break;
1364 case 1:
1365 v3 = this->pMonsterInfo.uAttack2DamageDiceRolls;
1366 v4 = this->pMonsterInfo.uAttack2DamageDiceSides;
1367 v5 = this->pMonsterInfo.uAttack2DamageBonus;
1368 break;
1369 case 2:
1370 v8 = this->pMonsterInfo.uSpellSkillAndMastery1;
1371 v9 = this->pMonsterInfo.uSpell1ID;
1372 v10 = SkillToMastery(v8);
1373 return _43AFE3_calc_spell_damage(v9, v8 & 0x3F, v10, 0);
1374 break;
1375 case 3:
1376 v8 = this->pMonsterInfo.uSpellSkillAndMastery2;
1377 v9 = this->pMonsterInfo.uSpell2ID;
1378 v10 = SkillToMastery(v8);
1379 return _43AFE3_calc_spell_damage(v9, v8 & 0x3F, v10, 0);
1380 break;
1381 case 4:
1382 v3 = this->pMonsterInfo.uSpecialAbilityDamageDiceRolls;
1383 v4 = this->pMonsterInfo.uSpecialAbilityDamageDiceSides;
1384 v5 = this->pMonsterInfo.uSpecialAbilityDamageDiceBonus;
1385 default:
1386 return 0;
1387 }
1388 for ( int i = 0; i < v3; i++)
1389 v11 += rand() % v4 + 1;
1390 return v11 + v5 + v2;
1391 }
1392
1393 //----- (00438B9B) --------------------------------------------------------
1394 bool Actor::IsPeasant()
1395 {
1396 unsigned int InHostile_Id; // eax@1
1397
1398 InHostile_Id = this->uAlly;
1399 if ( !this->uAlly )
1400 InHostile_Id = (this->pMonsterInfo.uID - 1) / 3 + 1;
1401 return (signed int)InHostile_Id >= 39 && (signed int)InHostile_Id <= 44//Dwarfs peasants
1402 || (signed int)InHostile_Id >= 45 && (signed int)InHostile_Id <= 50//Elves peasants
1403 || (signed int)InHostile_Id >= 51 && (signed int)InHostile_Id <= 62//Humans peasants
1404 || (signed int)InHostile_Id >= 78 && (signed int)InHostile_Id <= 83;//Goblins peasants
1405 }
1406
1407 //----- (0042EBEE) --------------------------------------------------------
1408 void Actor::StealFrom( unsigned int uActorID )
1409 {
1410 Player *pPlayer; // edi@1
1411 int v4; // ebx@2
1412 unsigned int v5; // eax@2
1413 DDM_DLV_Header *v6; // esi@4
1414 int v8; // [sp+8h] [bp-4h]@6
1415
1416 pPlayer = &pParty->pPlayers[uActiveCharacter-1];
1417 if ( pPlayer->CanAct() )
1418 {
1419 CastSpellInfoHelpers::_427D48();
1420 v4 = 0;
1421 v5 = pMapStats->GetMapInfo(pCurrentMapName);
1422 if ( v5 )
1423 v4 = pMapStats->pInfos[v5]._steal_perm;
1424 v6 = &pOutdoor->ddm;
1425 if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor)
1426 v6 = &pIndoor->dlv;
1427 pPlayer->StealFromActor(uActorID, v4, v6->uReputation++);
1428 v8 = pPlayer->GetAttackRecoveryTime(0);
1429 if ( v8 < 30 )
1430 v8 = 30;
1431 if ( !pParty->bTurnBasedModeOn )
1432 pPlayer->SetRecoveryTime((int)(flt_6BE3A4_debug_recmod1 * v8 * 2.133333333333333));
1433 pTurnEngine->ApplyPlayerAction();
1434 }
1435 return;
1436 }
1437
1438 //----- (00403A60) --------------------------------------------------------
1439 void Actor::AI_SpellAttack2(unsigned int uActorID, signed int edx0, AIDirection *pDir)
1440 {
1441 Actor *v3; // ebx@1
1442 int16_t v4; // esi@3
1443 int16_t v5; // edi@3
1444 signed int v6; // eax@4
1445 Vec3_int_ v7; // ST04_12@6
1446 AIDirection *v9; // eax@8
1447 __int16 v13; // ax@10
1448 AIDirection a3; // [sp+Ch] [bp-48h]@9
1449 AIDirection v18; // [sp+28h] [bp-2Ch]@9
1450 int v19; // [sp+44h] [bp-10h]@6
1451 signed int a2; // [sp+48h] [bp-Ch]@1
1452 int v21; // [sp+4Ch] [bp-8h]@3
1453 unsigned int pDira; // [sp+5Ch] [bp+8h]@10
1454
1455 v3 = &pActors[uActorID];
1456 a2 = edx0;
1457 if ( PID_TYPE(edx0) == OBJECT_Actor)
1458 {
1459 v6 = PID_ID(edx0);
1460 v4 = pActors[v6].vPosition.x;
1461 v5 = pActors[v6].vPosition.y;
1462 v21 = (int)(pActors[v6].uActorHeight * 0.75 + pActors[v6].vPosition.z);
1463 }
1464 else if ( PID_TYPE(edx0) == OBJECT_Player)
1465 {
1466 v4 = pParty->vPosition.x;
1467 v5 = pParty->vPosition.y;
1468 v21 = pParty->vPosition.z + pParty->sEyelevel;
1469 }
1470 else
1471 {
1472 Error("Should not get here");
1473 return;
1474 }
1475 v19 = v3->uActorHeight;
1476 v7.z = v3->vPosition.z - (int)(v19 * -0.75);
1477 v7.y = v3->vPosition.y;
1478 v7.x = v3->vPosition.x;
1479 if ( sub_407A1C(v4, v5, v21, v7) )
1480 {
1481 if ( pDir == nullptr)
1482 {
1483 Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), a2, &a3, 0);
1484 v9 = &a3;
1485 }
1486 else
1487 v9 = pDir;
1488 v3->uYawAngle = LOWORD(v9->uYawAngle);
1489 v13 = pSpriteFrameTable->pSpriteSFrames[v3->pSpriteIDs[ANIM_AtkRanged]].uAnimLength;
1490 v3->uCurrentActionLength = 8 * v13;
1491 v3->uCurrentActionTime = 0;
1492 v3->uAIState = AttackingRanged4;
1493 Actor::PlaySound(uActorID, 0);
1494 pDira = pMonsterStats->pInfos[v3->pMonsterInfo.uID].uRecoveryTime;
1495 if (v3->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0)
1496 pDira *= 2;
1497 if ( pParty->bTurnBasedModeOn == 1 )
1498 v3->pMonsterInfo.uRecoveryTime = pDira;
1499 else
1500 v3->pMonsterInfo.uRecoveryTime = v3->uCurrentActionLength + (int)(flt_6BE3A8_debug_recmod2 * pDira * 2.133333333333333);
1501 v3->vVelocity.z = 0;
1502 v3->vVelocity.y = 0;
1503 v3->vVelocity.x = 0;
1504 if ( ShouldMonsterPlayAttackAnim(v3->pMonsterInfo.uSpell2ID) )
1505 {
1506 v3->uCurrentActionLength = 64;
1507 v3->uCurrentActionTime = 0;
1508 v3->uAIState = Fidgeting;
1509 v3->UpdateAnimation();
1510 v3->uAIState = AttackingRanged4;
1511 }
1512 else
1513 v3->UpdateAnimation();
1514 }
1515 else
1516 Actor::AI_Pursue1(uActorID, a2, uActorID, 64, pDir);
1517 }
1518
1519 //----- (00403854) --------------------------------------------------------
1520 void Actor::AI_SpellAttack1(unsigned int uActorID, signed int sTargetPid, AIDirection *pDir)
1521 {
1522 Actor *v3; // ebx@1
1523 int16_t v4; // esi@3
1524 int16_t v5; // edi@3
1525 signed int v6; // eax@4
1526 Vec3_int_ v7; // ST04_12@6
1527 AIDirection *v9; // eax@8
1528 __int16 v13; // ax@10
1529 signed int v16; // ecx@17
1530 AIDirection a3; // [sp+Ch] [bp-48h]@9
1531 AIDirection v18; // [sp+28h] [bp-2Ch]@9
1532 int v19; // [sp+44h] [bp-10h]@6
1533 int v21; // [sp+4Ch] [bp-8h]@3
1534 unsigned int pDira; // [sp+5Ch] [bp+8h]@10
1535
1536 v3 = &pActors[uActorID];
1537 if ( PID_TYPE(sTargetPid) == OBJECT_Actor)
1538 {
1539 v6 = PID_ID(sTargetPid);
1540 v4 = pActors[v6].vPosition.x;
1541 v5 = pActors[v6].vPosition.y;
1542 v21 = (int)(pActors[v6].uActorHeight * 0.75 + pActors[v6].vPosition.z);
1543 }
1544 else if ( PID_TYPE(sTargetPid) == OBJECT_Player)
1545 {
1546 v4 = pParty->vPosition.x;
1547 v5 = pParty->vPosition.y;
1548 v21 = pParty->vPosition.z + pParty->sEyelevel;
1549 }
1550 else
1551 {
1552 Error("Should not get here");
1553 return;
1554 }
1555 v19 = v3->uActorHeight;
1556 v7.z = v3->vPosition.z - (int)(v19 * -0.75);
1557 v7.y = v3->vPosition.y;
1558 v7.x = v3->vPosition.x;
1559 if ( sub_407A1C(v4, v5, v21, v7) )
1560 {
1561 if ( pDir == nullptr )
1562 {
1563 Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
1564 v9 = &a3;
1565 }
1566 else
1567 v9 = pDir;
1568 v3->uYawAngle = LOWORD(v9->uYawAngle);
1569 v13 = pSpriteFrameTable->pSpriteSFrames[v3->pSpriteIDs[ANIM_AtkRanged]].uAnimLength;
1570 v3->uCurrentActionLength = 8 * v13;
1571 v3->uCurrentActionTime = 0;
1572 v3->uAIState = AttackingRanged3;
1573 Actor::PlaySound(uActorID, 0);
1574 pDira = pMonsterStats->pInfos[v3->pMonsterInfo.uID].uRecoveryTime;
1575 if (v3->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0)
1576 pDira *= 2;
1577 if ( pParty->bTurnBasedModeOn == 1 )
1578 v3->pMonsterInfo.uRecoveryTime = pDira;
1579 else
1580 v3->pMonsterInfo.uRecoveryTime = v3->uCurrentActionLength + (int)(flt_6BE3A8_debug_recmod2 * pDira * 2.133333333333333);
1581 v16 = v3->pMonsterInfo.uSpell1ID;
1582 v3->vVelocity.z = 0;
1583 v3->vVelocity.y = 0;
1584 v3->vVelocity.x = 0;
1585 if ( ShouldMonsterPlayAttackAnim(v3->pMonsterInfo.uSpell1ID) )
1586 {
1587 v3->uCurrentActionLength = 64;
1588 v3->uCurrentActionTime = 0;
1589 v3->uAIState = Fidgeting;
1590 v3->UpdateAnimation();
1591 v3->uAIState = AttackingRanged3;
1592 }
1593 else
1594 v3->UpdateAnimation();
1595 }
1596 else
1597 Actor::AI_Pursue1(uActorID, sTargetPid, uActorID, 64, pDir);
1598 }
1599
1600 //----- (0040368B) --------------------------------------------------------
1601 void Actor::AI_MissileAttack2(unsigned int uActorID, signed int sTargetPid, AIDirection *pDir)
1602 {
1603 Actor *v3; // ebx@1
1604 int16_t v4; // esi@3
1605 int16_t v5; // edi@3
1606 signed int v6; // eax@4
1607 Vec3_int_ v7; // ST04_12@6
1608 AIDirection *v9; // eax@8
1609 __int16 v13; // ax@10
1610 AIDirection a3; // [sp+Ch] [bp-48h]@9
1611 AIDirection v17; // [sp+28h] [bp-2Ch]@9
1612 int v18; // [sp+44h] [bp-10h]@6
1613 int v20; // [sp+4Ch] [bp-8h]@3
1614 unsigned int pDira; // [sp+5Ch] [bp+8h]@10
1615
1616 v3 = &pActors[uActorID];
1617 if ( PID_TYPE(sTargetPid) == OBJECT_Actor)
1618 {
1619 v6 = PID_ID(sTargetPid);
1620 v4 = pActors[v6].vPosition.x;
1621 v5 = pActors[v6].vPosition.y;
1622 v20 = (int)(pActors[v6].uActorHeight * 0.75 + pActors[v6].vPosition.z);
1623 }
1624 else if ( PID_TYPE(sTargetPid) == OBJECT_Player)
1625 {
1626 v4 = pParty->vPosition.x;
1627 v5 = pParty->vPosition.y;
1628 v20 = pParty->vPosition.z + pParty->sEyelevel;
1629 }
1630 else
1631 {
1632 Error("Should not get here");
1633 return;
1634 }
1635 v18 = v3->uActorHeight;
1636 v7.z = v3->vPosition.z - (int)(v18 * -0.75);
1637 v7.y = v3->vPosition.y;
1638 v7.x = v3->vPosition.x;
1639 if ( sub_407A1C(v4, v5, v20, v7) )
1640 {
1641 if ( pDir == nullptr )
1642 {
1643 Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
1644 v9 = &a3;
1645 }
1646 else
1647 v9 = pDir;
1648 v3->uYawAngle = LOWORD(v9->uYawAngle);
1649 v13 = pSpriteFrameTable->pSpriteSFrames[v3->pSpriteIDs[ANIM_AtkRanged]].uAnimLength;
1650 v3->uCurrentActionLength = 8 * v13;
1651 v3->uCurrentActionTime = 0;
1652 v3->uAIState = AttackingRanged2;
1653 Actor::PlaySound(uActorID, 0);
1654 pDira = pMonsterStats->pInfos[v3->pMonsterInfo.uID].uRecoveryTime;
1655 if ( v3->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0 )
1656 pDira *= 2;
1657 if ( pParty->bTurnBasedModeOn != 1 )
1658 v3->pMonsterInfo.uRecoveryTime = (int)(flt_6BE3A8_debug_recmod2 * pDira * 2.133333333333333);
1659 else
1660 v3->pMonsterInfo.uRecoveryTime = pDira;
1661 v3->vVelocity.z = 0;
1662 v3->vVelocity.y = 0;
1663 v3->vVelocity.x = 0;
1664 v3->UpdateAnimation();
1665 }
1666 else
1667 Actor::AI_Pursue1(uActorID, sTargetPid, uActorID, 64, pDir);
1668 }
1669
1670 //----- (00403476) --------------------------------------------------------
1671 void Actor::AI_MissileAttack1(unsigned int uActorID, signed int sTargetPid, AIDirection *pDir)
1672 {
1673 Actor *v3; // ebx@1
1674 int v4; // esi@3
1675 int v5; // edi@3
1676 signed int v6; // eax@4
1677 Vec3_int_ v7; // ST04_12@6
1678 AIDirection *v10; // eax@9
1679 __int16 v14; // ax@11
1680 AIDirection a3; // [sp+Ch] [bp-48h]@10
1681 AIDirection v18; // [sp+28h] [bp-2Ch]@10
1682 int v19; // [sp+44h] [bp-10h]@6
1683 //signed int a2; // [sp+48h] [bp-Ch]@1
1684 int v22; // [sp+50h] [bp-4h]@3
1685 unsigned int pDira; // [sp+5Ch] [bp+8h]@11
1686
1687 v3 = &pActors[uActorID];
1688 //a2 = edx0;
1689 if ( PID_TYPE(sTargetPid) == OBJECT_Actor)
1690 {
1691 v6 = PID_ID(sTargetPid);
1692 v4 = pActors[v6].vPosition.x;
1693 v5 = pActors[v6].vPosition.y;
1694 v22 = (int)(pActors[v6].uActorHeight * 0.75 + pActors[v6].vPosition.z);
1695 }
1696 else
1697 {
1698 if ( PID_TYPE(sTargetPid) == OBJECT_Player)
1699 {
1700 v4 = pParty->vPosition.x;
1701 v5 = pParty->vPosition.y;
1702 v22 = pParty->vPosition.z + pParty->sEyelevel;
1703 }
1704 else
1705 {
1706 v4 = (int)pDir;
1707 v5 = (int)pDir;
1708 }
1709 }
1710 v19 = v3->uActorHeight;
1711 v7.z = v3->vPosition.z - (unsigned int)(signed __int64)((double)v19 * -0.75);
1712 v7.y = v3->vPosition.y;
1713 v7.x = v3->vPosition.x;
1714 if ( sub_407A1C(v4, v5, v22, v7) || sub_407A1C(v7.x, v7.y, v7.z, Vec3_int_(v4, v5, v22)))
1715 {
1716 if ( pDir == nullptr )
1717 {
1718 Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), sTargetPid, &a3, 0);
1719 v10 = &a3;
1720 }
1721 else
1722 v10 = pDir;
1723 v3->uYawAngle = LOWORD(v10->uYawAngle);
1724 v14 = pSpriteFrameTable->pSpriteSFrames[v3->pSpriteIDs[ANIM_AtkRanged]].uAnimLength;
1725 v3->uCurrentActionLength = 8 * v14;
1726 v3->uCurrentActionTime = 0;
1727 v3->uAIState = AttackingRanged1;
1728 Actor::PlaySound(uActorID, 0);
1729 pDira = pMonsterStats->pInfos[v3->pMonsterInfo.uID].uRecoveryTime;
1730 if ( v3->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0 )
1731 pDira *= 2;
1732 if ( pParty->bTurnBasedModeOn == 1 )
1733 v3->pMonsterInfo.uRecoveryTime = pDira;
1734 else
1735 v3->pMonsterInfo.uRecoveryTime = v3->uCurrentActionLength - (int)(flt_6BE3A8_debug_recmod2 * pDira * -2.133333333333333);
1736 v3->vVelocity.z = 0;
1737 v3->vVelocity.y = 0;
1738 v3->vVelocity.x = 0;
1739 v3->UpdateAnimation();
1740 }
1741 else
1742 Actor::AI_Pursue1(uActorID, sTargetPid, uActorID, 64, pDir);
1743 }
1744
1745 //----- (004032B2) --------------------------------------------------------
1746 void Actor::AI_RandomMove( unsigned int uActor_id, unsigned int uTarget_id, int radius, int uActionLength )
1747 {
1748 int x; // ebx@1
1749 int absy; // eax@1
1750 unsigned int v9; // ebx@11
1751 int v10; // ebx@13
1752 AIDirection doNotInitializeBecauseShouldBeRandom; // [sp+Ch] [bp-30h]@7
1753 int y; // [sp+30h] [bp-Ch]@1
1754 int absx; // [sp+38h] [bp-4h]@1
1755
1756 x = pActors[uActor_id].vInitialPosition.x - pActors[uActor_id].vPosition.x;
1757 y = pActors[uActor_id].vInitialPosition.y - pActors[uActor_id].vPosition.y;
1758 absx = abs(x);
1759 absy = abs(y);
1760 if ( absx <= absy )
1761 absx = absy + (absx / 2 );
1762 else
1763 absx = absx + absy / 2;
1764 if ( MonsterStats::BelongsToSupertype(pActors[uActor_id].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
1765 {
1766 if ( !uActionLength )
1767 uActionLength = 256;
1768 Actor::AI_StandOrBored(uActor_id, OBJECT_Player, uActionLength, &doNotInitializeBecauseShouldBeRandom);
1769 return;
1770 }
1771 if ( pActors[uActor_id].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_GLOBAL && absx < 128 )
1772 {
1773 Actor::AI_Stand(uActor_id, uTarget_id, 256, &doNotInitializeBecauseShouldBeRandom);
1774 return;
1775 }
1776 absx += ((rand() & 0xF) * radius) / 16;
1777 v9 = (stru_5C6E00->uIntegerDoublePi - 1) & stru_5C6E00->Atan2(x, y);
1778 if ( rand() % 100 < 25 )
1779 {
1780 Actor::StandAwhile(uActor_id);
1781 return;
1782 }
1783 v10 = v9 + rand() % 256 - 128;
1784 if ( abs(v10 - pActors[uActor_id].uYawAngle) > 256 && !(pActors[uActor_id].uAttributes & ACTOR_ANIMATION) )
1785 {
1786 Actor::AI_Stand(uActor_id, uTarget_id, 256, &doNotInitializeBecauseShouldBeRandom);
1787 return;
1788 }
1789 pActors[uActor_id].uYawAngle = v10;
1790 if ( pActors[uActor_id].uMovementSpeed)
1791 pActors[uActor_id].uCurrentActionLength = 32 * absx / pActors[uActor_id].uMovementSpeed;
1792 else
1793 pActors[uActor_id].uCurrentActionLength = 0;
1794 pActors[uActor_id].uCurrentActionTime = 0;
1795 pActors[uActor_id].uAIState = Tethered;
1796 if ( rand() % 100 < 2 )
1797 Actor::PlaySound(uActor_id, 3);
1798 pActors[uActor_id].UpdateAnimation();
1799 }
1800
1801 //----- (004031C1) --------------------------------------------------------
1802 char __fastcall Actor::_4031C1_update_job_never_gets_called(unsigned int uActorID, signed int a2, int a3) //attempted to implement something like jobs for actors, but apparently was never finished
1803 {
1804 return 0;
1805 /*unsigned int v3; // edi@1
1806 Actor *v4; // esi@1
1807 ActorJob *v5; // eax@1
1808 signed int v6; // edx@2
1809 ActorJob *v7; // eax@2
1810 signed int v8; // edi@2
1811 ActorJob *v9; // ecx@2
1812 __int16 v10; // cx@15
1813 signed int v12; // [sp+8h] [bp-4h]@1
1814
1815 v3 = uActorID;
1816 v12 = a2;
1817 v4 = &pActors[uActorID];
1818 v5 = (ActorJob *)pActors[uActorID].CanAct();
1819 if ( v5 )
1820 {
1821 v6 = 65535;
1822 v7 = &v4->pScheduledJobs[v3];
1823 v8 = 7;
1824 v9 = &v7[7];//(char *)&v7[7].uHour;
1825 while ( !(v9->uAttributes & 1) || v9->uHour > v12 )
1826 {
1827 --v8;
1828 --v9;
1829 if ( v8 < 0 )
1830 break;
1831 }
1832 if( v8 >= 0 )
1833 v6 = v8;
1834 if ( !v8 && v6 == 65535 )
1835 v6 = 7;
1836 v5 = &v7[v6];
1837 if ( v4->vInitialPosition.x != v5->vPos.x
1838 || v4->vInitialPosition.y != v5->vPos.y
1839 || v4->vInitialPosition.z != v5->vPos.z
1840 || v4->pMonsterInfo.uMovementType != v5->uAction )
1841 {
1842 v4->vInitialPosition.x = v5->vPos.x;
1843 v4->vInitialPosition.y = v5->vPos.y;
1844 v10 = v5->vPos.z;
1845 v4->vInitialPosition.z = v10;
1846 LOBYTE(v5) = v5->uAction;
1847 v4->pMonsterInfo.uMovementType = MONSTER_MOVEMENT_TYPE_STAIONARY;
1848 if ( a3 == 1 )
1849 {
1850 v4->vPosition.x = v4->vInitialPosition.x;
1851 v4->vPosition.y = v4->vInitialPosition.y;
1852 LOBYTE(v5) = v10;
1853 v4->vPosition.z = v10;
1854 }
1855 }
1856 }
1857 return (char)v5;*/
1858 }
1859
1860 //----- (004030AD) --------------------------------------------------------
1861 void Actor::AI_Stun(unsigned int uActorID, signed int edx0, int stunRegardlessOfState)
1862 {
1863 __int16 v7; // ax@16
1864 AIDirection a3; // [sp+Ch] [bp-40h]@16
1865
1866 if ( pActors[uActorID].uAIState == Fleeing )
1867 pActors[uActorID].uAttributes |= ACTOR_FLEEING;
1868 if ( pActors[uActorID].pMonsterInfo.uHostilityType != 4 )
1869 {
1870 pActors[uActorID].uAttributes &= 0xFFFFFFFB;//~0x4
1871 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
1872 }
1873 if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 )
1874 pActors[uActorID].pActorBuffs[ACTOR_BUFF_CHARM].Reset();
1875 if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0 )
1876 pActors[uActorID].pActorBuffs[ACTOR_BUFF_AFRAID].Reset();
1877 if ( stunRegardlessOfState || (pActors[uActorID].uAIState != Stunned
1878 && pActors[uActorID].uAIState != AttackingRanged1
1879 && pActors[uActorID].uAIState != AttackingRanged2
1880 && pActors[uActorID].uAIState != AttackingRanged3
1881 && pActors[uActorID].uAIState != AttackingRanged4
1882 && pActors[uActorID].uAIState != AttackingMelee))
1883 {
1884 Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), edx0, &a3, 0);
1885 //v10 = &a3;
1886 pActors[uActorID].uYawAngle = LOWORD(a3.uYawAngle);
1887 v7 = pSpriteFrameTable->pSpriteSFrames[pActors[uActorID].pSpriteIDs[ANIM_GotHit]].uAnimLength;
1888 pActors[uActorID].uCurrentActionTime = 0;
1889 pActors[uActorID].uAIState = Stunned;
1890 pActors[uActorID].uCurrentActionLength = 8 * v7;
1891 Actor::PlaySound(uActorID, 2);
1892 pActors[uActorID].UpdateAnimation();
1893 }
1894 }
1895
1896 //----- (00402F87) --------------------------------------------------------
1897 void Actor::AI_Bored(unsigned int uActorID, unsigned int uObjID, AIDirection *a4)
1898 {
1899 unsigned int v7; // eax@3
1900 unsigned int v9; // eax@3
1901
1902 Actor* actor = &pActors[uActorID];
1903
1904 AIDirection a3; // [sp+Ch] [bp-5Ch]@2
1905 if (!a4)
1906 {
1907 Actor::GetDirectionInfo(PID(OBJECT_Actor,uActorID), uObjID, &a3, 0);
1908 a4 = &a3;
1909 }
1910
1911 actor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[actor->pSpriteIDs[ANIM_Bored]].uAnimLength;
1912
1913 v7 = stru_5C6E00->Atan2(actor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, actor->vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y);
1914 v9 = stru_5C6E00->uIntegerPi + actor->uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7;
1915
1916 if ( v9 & 0x700 ) // turned away - just stand
1917 Actor::AI_Stand(uActorID, uObjID, actor->uCurrentActionLength, a4);
1918 else // facing player - play bored anim
1919 {
1920 actor->uAIState = Fidgeting;
1921 actor->uCurrentActionTime = 0;
1922 actor->uYawAngle = a4->uYawAngle;
1923 actor->vVelocity.z = 0;
1924 actor->vVelocity.y = 0;
1925 actor->vVelocity.x = 0;
1926 if ( rand() % 100 < 5 )
1927 Actor::PlaySound(uActorID, 3);
1928 actor->UpdateAnimation();
1929 }
1930 }
1931
1932 //----- (00402F27) --------------------------------------------------------
1933 void Actor::Resurrect(unsigned int uActorID)
1934 {
1935 Actor *pActor; // esi@1
1936
1937 pActor = &pActors[uActorID];
1938 pActor->uCurrentActionTime = 0;
1939 pActor->uAIState = Resurrected;
1940 pActor->uCurrentActionAnimation = ANIM_Dying;
1941 pActor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[pActor->pSpriteIDs[ANIM_Dying]].uAnimLength;
1942 pActor->sCurrentHP = LOWORD(pActor->pMonsterInfo.uHP);
1943 Actor::PlaySound(uActorID, 1);
1944 pActor->UpdateAnimation();
1945 }
1946
1947 //----- (00402D6E) --------------------------------------------------------
1948 void Actor::Die(unsigned int uActorID)
1949 {
1950 Actor* actor = &pActors[uActorID];
1951
1952 actor->uCurrentActionTime = 0;
1953 actor->uAIState = Dying;
1954 actor->uCurrentActionAnimation = ANIM_Dying;
1955 actor->sCurrentHP = 0;
1956 actor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[actor->pSpriteIDs[ANIM_Dying]].uAnimLength;
1957 actor->pActorBuffs[ACTOR_BUFF_PARALYZED].Reset();
1958 actor->pActorBuffs[ACTOR_BUFF_STONED].Reset();
1959 Actor::PlaySound(uActorID, 1);
1960 actor->UpdateAnimation();
1961
1962 for (uint i = 0; i < 5; ++i)
1963 if (pParty->monster_id_for_hunting[i] == actor->pMonsterInfo.uID)
1964 pParty->monster_for_hunting_killed[i] = true;
1965
1966 for (uint i = 0; i < 22; ++i)
1967 actor->pActorBuffs[i].Reset();
1968
1969 ItemGen drop;
1970 drop.Reset();
1971 switch (actor->pMonsterInfo.uID)
1972 {
1973 case MONSTER_HARPY_1: case MONSTER_HARPY_2: case MONSTER_HARPY_3:
1974 drop.uItemID = ITEM_HARPY_FEATHER;
1975 break;
1976
1977 case MONSTER_OOZE_1: case MONSTER_OOZE_2: case MONSTER_OOZE_3:
1978 drop.uItemID = ITEM_OOZE_ECTOPLASM_BOTTLE;
1979 break;
1980
1981 case MONSTER_TROLL_1: case MONSTER_TROLL_2: case MONSTER_TROLL_3:
1982 drop.uItemID = ITEM_TROLL_BLOOD;
1983 break;
1984
1985 case MONSTER_DEVIL_1: case MONSTER_DEVIL_2: case MONSTER_DEVIL_3:
1986 drop.uItemID = ITEM_DEVIL_ICHOR;
1987 break;
1988
1989 case MONSTER_DRAGON_1: case MONSTER_DRAGON_2: case MONSTER_DRAGON_3:
1990 drop.uItemID = ITEM_DRAGON_EYE;
1991 break;
1992 }
1993
1994 if (rand() % 100 < 20 && drop.uItemID != 0)
1995 {
1996 SpriteObject::sub_42F7EB_DropItemAt(pItemsTable->pItems[drop.uItemID].uSpriteID,
1997 actor->vPosition.x,
1998 actor->vPosition.y,
1999 actor->vPosition.z + 16,
2000 rand() % 200 + 200,
2001 1,
2002 1,
2003 0,
2004 &drop);
2005 }
2006
2007 if (actor->pMonsterInfo.uSpecialAbilityType == MONSTER_SPECIAL_ABILITY_EXPLODE)
2008 Actor::Explode(uActorID);
2009 }
2010
2011 //----- (00402CED) --------------------------------------------------------
2012 void Actor::PlaySound(unsigned int uActorID, unsigned int uSoundID)
2013 {
2014 unsigned __int16 v3; // dx@1
2015
2016 v3 = pActors[uActorID].pSoundSampleIDs[uSoundID];
2017 if ( v3 )
2018 {
2019 if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0 )
2020 pAudioPlayer->PlaySound((SoundID)v3, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
2021 else
2022 {
2023 switch(pActors[uActorID].pActorBuffs[ACTOR_BUFF_SHRINK].uPower)
2024 {
2025 case 1:
2026 pAudioPlayer->PlaySound((SoundID)v3, PID(OBJECT_Actor, uActorID), 0, 0, 0, 0, 0, 33075);
2027 break;
2028 case 2:
2029 pAudioPlayer->PlaySound((SoundID)v3, PID(OBJECT_Actor, uActorID), 0, 0, 0, 0, 0, 33075);
2030 break;
2031 case 3:
2032 case 4:
2033 pAudioPlayer->PlaySound((SoundID)v3, PID(OBJECT_Actor, uActorID), 0, 0, 0, 0, 0, 33075);
2034 break;
2035 default:
2036 pAudioPlayer->PlaySound((SoundID)v3, PID(OBJECT_Actor, uActorID), 0, -1, 0, 0, 0, 0);
2037 break;
2038 }
2039 }
2040 }
2041 }
2042
2043 //----- (00402AD7) --------------------------------------------------------
2044 void Actor::AI_Pursue1(unsigned int uActorID, unsigned int a2, signed int arg0, signed int uActionLength, AIDirection *pDir)
2045 {
2046 int v6; // eax@1
2047 Actor *v7; // ebx@1
2048 unsigned int v8; // ecx@1
2049 AIDirection *v10; // esi@6
2050 AIDirection a3; // [sp+Ch] [bp-5Ch]@7
2051 unsigned int v18; // [sp+64h] [bp-4h]@1
2052
2053 v6 = 0;
2054 v7 = &pActors[uActorID];
2055 v8 = PID(OBJECT_Actor,uActorID);
2056 if ( v7->pMonsterInfo.uFlying != 0 && !pParty->bFlying ) //TODO: Does v6 have a point?
2057 {
2058 if ( v7->pMonsterInfo.uMissleAttack1Type )
2059 v6 = v7->uActorRadius + 512;
2060 else
2061 v6 = pParty->uPartyHeight;
2062 }
2063
2064 if ( pDir == nullptr )
2065 {
2066 Actor::GetDirectionInfo(v8, a2, &a3, v6);
2067 v10 = &a3;
2068 }
2069 else
2070 v10 = pDir;
2071 if ( MonsterStats::BelongsToSupertype(v7->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
2072 {
2073 if ( !uActionLength )
2074 uActionLength = 256;
2075 Actor::AI_StandOrBored(uActorID, 4, uActionLength, v10);
2076 return;
2077 }
2078 if ( v10->uDistance < 307.2 )
2079 {
2080 if ( !uActionLength )
2081 uActionLength = 256;
2082 Actor::AI_Stand(uActorID, a2, uActionLength, v10);
2083 return;
2084 }
2085 if ( v7->uMovementSpeed == 0 )
2086 {
2087 Actor::AI_Stand(uActorID, a2, uActionLength, v10);
2088 return;
2089 }
2090 if ( arg0 % 2 )
2091 v18 = -16;
2092 else
2093 v18 = 16;
2094
2095 v7->uYawAngle = stru_5C6E00->Atan2(
2096 pParty->vPosition.x + (int)fixpoint_mul(stru_5C6E00->Cos(v18 + stru_5C6E00->uIntegerPi + v10->uYawAngle), v10->uDistanceXZ) - v7->vPosition.x,
2097 pParty->vPosition.y + (int)fixpoint_mul(stru_5C6E00->Sin(v18 + stru_5C6E00->uIntegerPi + v10->uYawAngle), v10->uDistanceXZ) - v7->vPosition.y);
2098 if ( uActionLength )
2099 v7->uCurrentActionLength = uActionLength;
2100 else
2101 v7->uCurrentActionLength = 128;
2102 v7->uPitchAngle = LOWORD(v10->uPitchAngle);
2103 v7->uAIState = Pursuing;
2104 v7->UpdateAnimation();
2105 }
2106
2107 //----- (00402968) --------------------------------------------------------
2108 void Actor::AI_Flee(unsigned int uActorID, signed int sTargetPid, int uActionLength, AIDirection *a4)
2109 {
2110 Actor *v5; // ebx@1
2111 int v7; // ecx@2
2112 unsigned __int16 v9; // ax@15
2113 AIDirection v10; // [sp+8h] [bp-7Ch]@4
2114 AIDirection a3; // [sp+24h] [bp-60h]@3
2115 AIDirection* v13; // [sp+5Ch] [bp-28h]@4
2116
2117 v5 = &pActors[uActorID];
2118 if ( v5->CanAct() )
2119 {
2120 v7 = PID(OBJECT_Actor,uActorID);
2121 if ( !a4 )
2122 {
2123 Actor::GetDirectionInfo(v7, sTargetPid, &a3, v5->pMonsterInfo.uFlying);
2124 a4 = &a3;
2125 }
2126 Actor::GetDirectionInfo(v7, 4u, &v10, 0);
2127 v13 = &v10;
2128 if ( MonsterStats::BelongsToSupertype(v5->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT)
2129 || PID_TYPE(sTargetPid) == OBJECT_Actor && v13->uDistance < 307.2 )
2130 {
2131 if ( !uActionLength )
2132 uActionLength = 256;
2133 Actor::AI_StandOrBored(uActorID, 4, uActionLength, v13);
2134 }
2135 else
2136 {
2137 if ( v5->uMovementSpeed )
2138 v5->uCurrentActionLength = (signed int)(a4->uDistanceXZ << 7) / v5->uMovementSpeed;
2139 else
2140 v5->uCurrentActionLength = 0;
2141 if ( v5->uCurrentActionLength > 256 )
2142 v5->uCurrentActionLength = 256;
2143 v5->uYawAngle = LOWORD(stru_5C6E00->uIntegerHalfPi) + LOWORD(a4->uYawAngle);
2144 v5->uYawAngle = LOWORD(stru_5C6E00->uDoublePiMask) & (v5->uYawAngle + rand() % (signed int)stru_5C6E00->uIntegerPi);
2145 v9 = LOWORD(a4->uPitchAngle);
2146 v5->uCurrentActionTime = 0;
2147 v5->uPitchAngle = v9;
2148 v5->uAIState = Fleeing;
2149 v5->UpdateAnimation();
2150 }
2151 }
2152 }
2153
2154 //----- (0040281C) --------------------------------------------------------
2155 void Actor::AI_Pursue2(unsigned int uActorID, unsigned int a2, signed int uActionLength, AIDirection *pDir, int a5)
2156 {
2157 int v6; // eax@1
2158 Actor *v7; // ebx@1
2159 unsigned int v8; // ecx@1
2160 AIDirection *v10; // esi@7
2161 signed __int16 v13; // cx@19
2162 unsigned __int16 v14; // ax@25
2163 AIDirection a3; // [sp+Ch] [bp-40h]@8
2164 AIDirection v18; // [sp+28h] [bp-24h]@8
2165
2166 v6 = 0;
2167 v7 = &pActors[uActorID];
2168 v8 = PID(OBJECT_Actor,uActorID);
2169 if ( v7->pMonsterInfo.uFlying != 0 && !pParty->bFlying )
2170 {
2171 if ( v7->pMonsterInfo.uMissleAttack1Type && uCurrentlyLoadedLevelType == LEVEL_Outdoor )
2172 v6 = v7->uActorRadius + 512;
2173 else
2174 v6 = pParty->uPartyHeight;
2175 }
2176 v10 = pDir;
2177 if ( !pDir )
2178 {
2179 Actor::GetDirectionInfo(v8, a2, &a3, v6);
2180 v10 = &a3;
2181 }
2182 if ( MonsterStats::BelongsToSupertype(v7->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
2183 {
2184 if ( !uActionLength )
2185 uActionLength = 256;
2186 Actor::AI_StandOrBored(uActorID, 4, uActionLength, v10);
2187 return;
2188 }
2189 if ( (signed int)v10->uDistance < a5 )
2190 {
2191 if ( !uActionLength )
2192 uActionLength = 256;
2193 Actor::AI_StandOrBored(uActorID, a2, uActionLength, v10);
2194 return;
2195 }
2196 if ( uActionLength )
2197 {
2198 v7->uCurrentActionLength = uActionLength;
2199 }
2200 else
2201 {
2202 v13 = v7->uMovementSpeed;
2203 if ( v13 )
2204 v7->uCurrentActionLength = (signed int)(v10->uDistanceXZ << 7) / v13;
2205 else
2206 v7->uCurrentActionLength = 0;
2207 if ( v7->uCurrentActionLength > 32 )
2208 v7->uCurrentActionLength = 32;
2209 }
2210 v7->uYawAngle = LOWORD(v10->uYawAngle);
2211 v14 = LOWORD(v10->uPitchAngle);
2212 v7->uCurrentActionTime = 0;
2213 v7->uPitchAngle = v14;
2214 v7->uAIState = Pursuing;
2215 v7->UpdateAnimation();
2216 }
2217
2218 //----- (00402686) --------------------------------------------------------
2219 void Actor::AI_Pursue3(unsigned int uActorID, unsigned int a2, signed int uActionLength, AIDirection *a4)
2220 {
2221 int v5; // eax@1
2222 Actor *v6; // ebx@1
2223 int v7; // ecx@1
2224 signed __int16 v12; // cx@19
2225 __int16 v14; // ax@25
2226 unsigned __int16 v16; // ax@28
2227 AIDirection a3; // [sp+Ch] [bp-40h]@8
2228 AIDirection* v20; // [sp+28h] [bp-24h]@8
2229
2230 v5 = 0;
2231 v6 = &pActors[uActorID];
2232 v7 = PID(OBJECT_Actor,uActorID);
2233 if ( v6->pMonsterInfo.uFlying != 0 && !pParty->bFlying )
2234 {
2235 if ( v6->pMonsterInfo.uMissleAttack1Type && uCurrentlyLoadedLevelType == LEVEL_Outdoor )
2236 v5 = v6->uActorRadius + 512;
2237 else
2238 v5 = pParty->uPartyHeight;
2239 }
2240 if ( !a4 )
2241 {
2242 Actor::GetDirectionInfo(v7, a2, &a3, v5);
2243 v20 = &a3;
2244 }
2245 if ( MonsterStats::BelongsToSupertype(v6->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
2246 {
2247 if ( !uActionLength )
2248 uActionLength = 256;
2249 return Actor::AI_StandOrBored(uActorID, 4, uActionLength, a4);
2250 }
2251 if ( a4->uDistance < 307.2 )
2252 {
2253 if ( !uActionLength )
2254 uActionLength = 256;
2255 return Actor::AI_StandOrBored(uActorID, a2, uActionLength, a4);
2256 }
2257 if ( uActionLength )
2258 v6->uCurrentActionLength = uActionLength + rand() % uActionLength;
2259 else
2260 {
2261 v12 = v6->uMovementSpeed;
2262 if ( v12 )
2263 v6->uCurrentActionLength = (signed int)(a4->uDistanceXZ << 7) / v12;
2264 else
2265 v6->uCurrentActionLength = 0;
2266 if ( v6->uCurrentActionLength > 128 )
2267 v6->uCurrentActionLength = 128;
2268 }
2269 v14 = LOWORD(a4->uYawAngle);
2270 if ( rand() % 2 )
2271 v14 += 256;
2272 else
2273 v14 -= 256;
2274 v6->uYawAngle = v14;
2275 v16 = LOWORD(a4->uPitchAngle);
2276 v6->uCurrentActionTime = 0;
2277 v6->uPitchAngle = v16;
2278 v6->uAIState = Pursuing;
2279 if ( rand() % 100 < 2 )
2280 Actor::PlaySound(uActorID, 2u);
2281 v6->UpdateAnimation();
2282 }
2283
2284 //----- (00401221) --------------------------------------------------------
2285 void Actor::_SelectTarget(unsigned int uActorID, int *a2, bool can_target_party)
2286 {
2287 int v5; // ecx@1
2288 signed int v10; // eax@13
2289 uint v11; // ebx@16
2290 uint v12; // eax@16
2291 signed int v14; // eax@31
2292 uint v15; // edi@43
2293 uint v16; // ebx@45
2294 uint v17; // eax@45
2295 signed int closestId; // [sp+14h] [bp-1Ch]@1
2296 uint v23; // [sp+1Ch] [bp-14h]@16
2297 unsigned int lowestRadius; // [sp+24h] [bp-Ch]@1
2298 uint v27; // [sp+2Ch] [bp-4h]@16
2299 uint v28; // [sp+2Ch] [bp-4h]@45
2300
2301 lowestRadius = UINT_MAX;
2302 v5 = 0;
2303 *a2 = 0;
2304 closestId = 0;
2305 assert(uActorID < uNumActors);
2306 Actor* thisActor = &pActors[uActorID];
2307
2308 for (uint i = 0; i < uNumActors; ++i)
2309 {
2310 Actor* actor = &pActors[i];
2311 if (actor->uAIState == Dead || actor->uAIState == Dying ||
2312 actor->uAIState == Removed || actor->uAIState == Summoned || actor->uAIState == Disabled || uActorID == i )
2313 continue;
2314
2315 if (thisActor->uLastCharacterIDToHit == 0 || PID(OBJECT_Actor,v5) != thisActor->uLastCharacterIDToHit )
2316 {
2317 v10 = thisActor->GetActorsRelation(actor);
2318 if ( v10 == 0 )
2319 continue;
2320 }
2321 else if (thisActor->IsNotAlive())
2322 {
2323 thisActor->uLastCharacterIDToHit = 0;
2324 v10 = thisActor->GetActorsRelation(actor);
2325 if ( v10 == 0 )
2326 continue;
2327 }
2328 else
2329 {
2330 if ( (actor->uGroup != 0 || thisActor->uGroup != 0) && actor->uGroup == thisActor->uGroup )
2331 continue;
2332 v10 = 4;
2333 }
2334 if ( thisActor->pMonsterInfo.uHostilityType )
2335 v10 = pMonsterStats->pInfos[thisActor->pMonsterInfo.uID].uHostilityType;
2336 v11 = _4DF380_hostilityRanges[v10];
2337 v23 = abs(thisActor->vPosition.x - actor->vPosition.x);
2338 v27 = abs(thisActor->vPosition.y - actor->vPosition.y);
2339 v12 = abs(thisActor->vPosition.z - actor->vPosition.z);
2340 if ( v23 <= v11
2341 && v27 <= v11
2342 && v12 <= v11
2343 && sub_4070EF_prolly_detect_player(PID(OBJECT_Actor, i), PID(OBJECT_Actor, uActorID))
2344 && v23 * v23 + v27 * v27 + v12 * v12 < lowestRadius )
2345 {
2346 lowestRadius = v23 * v23 + v27 * v27 + v12 * v12;
2347 closestId = i;
2348 }
2349 }
2350
2351 if ( lowestRadius != UINT_MAX )
2352 {
2353 *a2 = PID(OBJECT_Actor, closestId);
2354 }
2355
2356 if (can_target_party && !pParty->Invisible())
2357 {
2358 if ( thisActor->ActorEnemy()
2359 && thisActor->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime <= 0
2360 && thisActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime <= 0
2361 && thisActor->pActorBuffs[ACTOR_BUFF_SUMMONED].uExpireTime <= 0 )
2362 v14 = 4;
2363 else
2364 v14 = thisActor->GetActorsRelation(0);
2365 if ( v14 != 0 )
2366 {
2367 if ( !thisActor->pMonsterInfo.uHostilityType )
2368 v15 = _4DF380_hostilityRanges[v14];
2369 else
2370 v15 = _4DF380_hostilityRanges[4];
2371 v16 = abs(thisActor->vPosition.x - pParty->vPosition.x);
2372 v28 = abs(thisActor->vPosition.y - pParty->vPosition.y);
2373 v17 = abs(thisActor->vPosition.z - pParty->vPosition.z);
2374 if ( v16 <= v15 && v28 <= v15 && v17 <= v15 && (v16 * v16 + v28 * v28 + v17 * v17 < lowestRadius))
2375 {
2376 *a2 = OBJECT_Player;
2377 }
2378 }
2379 }
2380 }
2381 // 4DF380: using guessed type int dword_4DF380[];
2382 // 4DF390: using guessed type int dword_4DF390;
2383
2384 //----- (0040104C) --------------------------------------------------------
2385 signed int Actor::GetActorsRelation(Actor *otherActPtr)
2386 {
2387 unsigned int thisGroup; // ebp@19
2388 int otherGroup; // eax@22
2389 unsigned int thisAlly; // edx@25
2390 unsigned int otherAlly; // edx@33
2391
2392 if ( otherActPtr)
2393 {
2394 if ( otherActPtr->uGroup != 0 && this->uGroup != 0 && otherActPtr->uGroup == this->uGroup )
2395 return 0;
2396 }
2397
2398 if (this->pActorBuffs[ACTOR_BUFF_BERSERK].uExpireTime > 0)
2399 return 4;
2400 thisAlly = this->uAlly;
2401 if ( this->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime > 0 || thisAlly == 9999)
2402 thisGroup = 0;
2403 else if ( thisAlly > 0 )
2404 thisGroup = thisAlly;
2405 else
2406 thisGroup = (this->pMonsterInfo.uID - 1) / 3 + 1;
2407
2408 if ( otherActPtr )
2409 {
2410 if (otherActPtr->pActorBuffs[ACTOR_BUFF_BERSERK].uExpireTime > 0)
2411 return 4;
2412 otherAlly = otherActPtr->uAlly;
2413 if ( otherActPtr->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime > 0 || otherAlly == 9999)
2414 otherGroup = 0;
2415 else if ( otherAlly > 0 )
2416 otherGroup = otherAlly;
2417 else
2418 otherGroup = (otherActPtr->pMonsterInfo.uID - 1) / 3 + 1;
2419 }
2420 else
2421 otherGroup = 0;
2422
2423 if ( this->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 && !otherGroup
2424 || otherActPtr && otherActPtr->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 && !thisGroup )
2425 return 0;
2426 if ( this->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime <= 0 && this->ActorEnemy() && !otherGroup )
2427 return 4;
2428 if (thisGroup >= 89 || otherGroup >= 89)
2429 return 0;
2430
2431 if ( thisGroup == 0 )
2432 {
2433 if ( (!otherActPtr || this->pActorBuffs[ACTOR_BUFF_ENSLAVED].uExpireTime > 0 && otherActPtr->ActorFriend()) && !pFactionTable->relations[otherGroup][0])
2434 return pFactionTable->relations[0][otherGroup];
2435 else
2436 return 4;
2437 }
2438 else
2439 return pFactionTable->relations[thisGroup][otherGroup];
2440 }
2441
2442 //----- (0045976D) --------------------------------------------------------
2443 void Actor::UpdateAnimation()
2444 {
2445 ResetAnimation();
2446 switch (uAIState)
2447 {
2448 case Tethered:
2449 uCurrentActionAnimation = ANIM_Walking;
2450 break;
2451
2452 case AttackingMelee:
2453 uCurrentActionAnimation = ANIM_AtkMelee;
2454 uAttributes |= ACTOR_ANIMATION;
2455 break;
2456
2457 case AttackingRanged1:
2458 case AttackingRanged2:
2459 case AttackingRanged3:
2460 case AttackingRanged4:
2461 uCurrentActionAnimation = ANIM_AtkRanged;
2462 uAttributes |= ACTOR_ANIMATION;
2463 break;
2464
2465 case Dying:
2466 case Resurrected:
2467 uCurrentActionAnimation = ANIM_Dying;
2468 uAttributes |= ACTOR_ANIMATION;
2469 break;
2470
2471 case Pursuing:
2472 case Fleeing:
2473 uCurrentActionAnimation = ANIM_Walking;
2474 uAttributes |= ACTOR_ANIMATION;
2475 break;
2476
2477 case Stunned:
2478 uCurrentActionAnimation = ANIM_GotHit;
2479 uAttributes |= ACTOR_ANIMATION;
2480 break;
2481
2482 case Fidgeting:
2483 uCurrentActionAnimation = ANIM_Bored;
2484 uAttributes |= ACTOR_ANIMATION;
2485 break;
2486
2487 case Standing:
2488 case Interacting:
2489 case Summoned:
2490 uCurrentActionAnimation = ANIM_Standing;
2491 uAttributes |= ACTOR_ANIMATION;
2492 break;
2493
2494 case Dead:
2495 if (pSpriteFrameTable->pSpriteSFrames[pSpriteIDs[ANIM_Dead]].pHwSpriteIDs[0] <= 0)
2496 uAIState = Removed;
2497 else
2498 uCurrentActionAnimation = ANIM_Dead;
2499 break;
2500
2501 case Removed:
2502 case Disabled:
2503 return;
2504
2505 default:
2506 assert(false);
2507 }
2508 }
2509
2510 //----- (00459671) --------------------------------------------------------
2511 void Actor::Reset()
2512 {
2513 this->pActorName[0] = 0;
2514 this->word_000086_some_monster_id = 0;
2515 this->sNPC_ID = 0;
2516 this->vPosition.z = 0;
2517 this->vPosition.y = 0;
2518 this->vPosition.x = 0;
2519 this->vVelocity.z = 0;
2520 this->vVelocity.y = 0;
2521 this->vVelocity.x = 0;
2522 this->uYawAngle = 0;
2523 this->uPitchAngle = 0;
2524 this->uAttributes = 0;
2525 this->uSectorID = 0;
2526 this->uCurrentActionTime = 0;
2527 this->vInitialPosition.z = 0;
2528 this->vInitialPosition.y = 0;
2529 this->vInitialPosition.x = 0;
2530 this->vGuardingPosition.z = 0;
2531 this->vGuardingPosition.y = 0;
2532 this->vGuardingPosition.x = 0;
2533 this->uTetherDistance = 256;
2534 this->uActorRadius = 32;
2535 this->uActorHeight = 128;
2536 this->uAIState = Standing;
2537 this->uCurrentActionAnimation = ANIM_Standing;
2538 this->uMovementSpeed = 200;
2539 this->uCarriedItemID = 0;
2540 this->uGroup = 0;
2541 this->uAlly = 0;
2542 this->uSummonerID = 0;
2543 this->uLastCharacterIDToHit = 0;
2544 this->dword_000334_unique_name = 0;
2545 memset(this->pSpriteIDs, 0, sizeof(pSpriteIDs));
2546 memset(this->pActorBuffs, 0, 0x160u);
2547 }
2548
2549 //----- (0045959A) --------------------------------------------------------
2550 void Actor::PrepareSprites(char load_sounds_if_bit1_set)
2551 {
2552
2553 MonsterDesc *v3; // esi@1
2554 MonsterInfo *v9; // [sp+84h] [bp-10h]@1
2555
2556 v3 = &pMonsterList->pMonsters[pMonsterInfo.uID - 1];
2557 v9 = &pMonsterStats->pInfos[pMonsterInfo.uID - 1 + 1];
2558 //v12 = pSpriteIDs;
2559 //Source = (char *)v3->pSpriteNames;
2560 //do
2561 for (uint i = 0; i < 8; ++i)
2562 {
2563 //strcpy(pSpriteName, v3->pSpriteNames[i]);
2564 pSpriteIDs[i] = pSpriteFrameTable->FastFindSprite(v3->pSpriteNames[i]);
2565 pSpriteFrameTable->InitializeSprite(pSpriteIDs[i]);
2566 }
2567 uActorHeight = v3->uMonsterHeight;
2568 uActorRadius = v3->uMonsterRadius;
2569 uMovementSpeed = v9->uBaseSpeed;
2570 if ( !(load_sounds_if_bit1_set & 1) )
2571 {
2572 for ( int i = 0; i < 4; ++i )
2573 pSoundSampleIDs[i] = v3->pSoundSampleIDs[i];
2574 }
2575 }
2576
2577 //----- (00459667) --------------------------------------------------------
2578 void Actor::Remove()
2579 {
2580 this->uAIState = Removed;
2581 }
2582
2583
2584 //----- (0043B1B0) --------------------------------------------------------
2585 void Actor::ActorDamageFromMonster(signed int attacker_id, unsigned int actor_id, Vec3_int_ *pVelocity, signed int a4)
2586 {
2587 int v4; // ebx@1
2588 int dmgToRecv; // qax@8
2589 signed int v12; // ecx@20
2590 int finalDmg; // edi@30
2591 int pushDistance; // [sp+20h] [bp+Ch]@34
2592
2593 v4 = 0;
2594 if ( PID_TYPE(attacker_id) == OBJECT_Item)
2595 {
2596 v4 = pSpriteObjects[PID_ID(attacker_id)].field_60_distance_related_prolly_lod;
2597 attacker_id = pSpriteObjects[PID_ID(attacker_id)].spell_caster_pid;
2598 }
2599 if ( PID_TYPE(attacker_id) == OBJECT_Actor)
2600 {
2601 if ( !pActors[actor_id].IsNotAlive() )
2602 {
2603 pActors[actor_id].uLastCharacterIDToHit = attacker_id;
2604 if ( pActors[actor_id].uAIState == Fleeing )
2605 pActors[actor_id].uAttributes |= ACTOR_FLEEING;
2606 if ( pActors[PID_ID(attacker_id)]._4273BB_DoesHitOtherActor(&pActors[actor_id], v4, 0) )
2607 {
2608 dmgToRecv = pActors[PID_ID(attacker_id)]._43B3E0_CalcDamage(a4);
2609 if ( pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0 )
2610 {
2611 if ( pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower )
2612 dmgToRecv = dmgToRecv / pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower;
2613 }
2614 if ( pActors[actor_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 )
2615 dmgToRecv = 0;
2616 if ( a4 == 0 )
2617 v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.uAttack1Type;
2618 else if ( a4 == 1 )
2619 {
2620 v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.uAttack2Type;
2621 if ( SHIDWORD(pActors[actor_id].pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime) > 0 )
2622 dmgToRecv = dmgToRecv / 2;
2623 }
2624 else if ( a4 == 2 )
2625 v12 = pSpellStats->pInfos[pActors[actor_id].pMonsterInfo.uSpell1ID].uSchool;
2626 else if ( a4 == 3 )
2627 v12 = pSpellStats->pInfos[pActors[actor_id].pMonsterInfo.uSpell2ID].uSchool;
2628 else if ( a4 == 4 )
2629 v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.field_3C_some_special_attack;
2630 else
2631 v12 = 4;
2632 finalDmg = pActors[actor_id].CalcMagicalDamageToActor((DAMAGE_TYPE)v12, dmgToRecv);
2633 pActors[actor_id].sCurrentHP -= finalDmg;
2634 if ( finalDmg )
2635 {
2636 if ( pActors[actor_id].sCurrentHP > 0 )
2637 Actor::AI_Stun(actor_id, attacker_id, 0);
2638 else
2639 Actor::Die(actor_id);
2640 Actor::AggroSurroundingPeasants(actor_id, 0);
2641 pushDistance = 20 * finalDmg / pActors[actor_id].pMonsterInfo.uHP;
2642 if ( pushDistance > 10 )
2643 pushDistance = 10;
2644 if ( !MonsterStats::BelongsToSupertype(pActors[actor_id].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
2645 {
2646 pVelocity->x = (int32)fixpoint_mul(pushDistance, pVelocity->x);
2647 pVelocity->y = (int32)fixpoint_mul(pushDistance, pVelocity->y);
2648 pVelocity->z = (int32)fixpoint_mul(pushDistance, pVelocity->z);
2649 pActors[actor_id].vVelocity.x = 50 * LOWORD(pVelocity->x);
2650 pActors[actor_id].vVelocity.y = 50 * LOWORD(pVelocity->y);
2651 pActors[actor_id].vVelocity.z = 50 * LOWORD(pVelocity->z);
2652 }
2653 Actor::AddBloodsplatOnDamageOverlay(actor_id, 1, finalDmg);
2654 }
2655 else
2656 Actor::AI_Stun(actor_id, attacker_id, 0);
2657 return;
2658 }
2659 }
2660 }
2661 }
2662
2663 //----- (0044FD29) --------------------------------------------------------
2664 void Actor::SummonMinion( int summonerId )
2665 {
2666 unsigned __int8 extraSummonLevel; // al@1
2667 int summonMonsterBaseType; // esi@1
2668 int v5; // edx@2
2669 int v7; // edi@10
2670 Actor *actor; // esi@10
2671 MonsterInfo *v9; // ebx@10
2672 //MonsterDesc *v10; // edi@10
2673 int v13; // ebx@10
2674 int v15; // edi@10
2675 int v17; // ebx@10
2676 unsigned int v19; // qax@10
2677 int result; // eax@13
2678 unsigned int monsterId; // [sp+10h] [bp-18h]@8
2679 int v27; // [sp+18h] [bp-10h]@10
2680 int actorSector; // [sp+1Ch] [bp-Ch]@8
2681
2682
2683 actorSector = 0;
2684 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
2685 actorSector = pIndoor->GetSector(this->vPosition.x, this->vPosition.y, this->vPosition.z);
2686
2687 v19 = this->uAlly;
2688 if ( !this->uAlly )
2689 {
2690 monsterId = this->pMonsterInfo.uID - 1;
2691 v19 = (uint)(monsterId * 0.33333334);
2692 }
2693 v27 = uCurrentlyLoadedLevelType == LEVEL_Outdoor ? 128 : 64;
2694 v13 = rand() % 2048;
2695 v15 = fixpoint_mul(stru_5C6E00->Cos(v13), v27) + this->vPosition.x;
2696 v17 = fixpoint_mul(stru_5C6E00->Sin(v13), v27) + this->vPosition.y;
2697
2698 if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
2699 {
2700 result = pIndoor->GetSector(v15, v17, this->vPosition.z);
2701 if (result != actorSector)
2702 return;
2703 result = BLV_GetFloorLevel(v15, v17, v27, result, &monsterId);
2704 if (result != -30000)
2705 return;
2706 if (abs(result - v27) > 1024)
2707 return;
2708 }
2709
2710 extraSummonLevel = this->pMonsterInfo.uSpecialAbilityDamageDiceRolls;
2711 summonMonsterBaseType = this->pMonsterInfo.field_3C_some_special_attack;
2712 if ( extraSummonLevel )
2713 {
2714 if ( extraSummonLevel >= 1 && extraSummonLevel <= 3 )
2715 summonMonsterBaseType = summonMonsterBaseType + extraSummonLevel - 1;
2716 }
2717 else
2718 {
2719 v5 = rand() % 100;
2720 if ( v5 >= 90 )
2721 summonMonsterBaseType += 2;
2722 else if ( v5 >= 60 )
2723 summonMonsterBaseType += 1;
2724 }
2725 v7 = summonMonsterBaseType - 1;
2726 actor = &pActors[uNumActors];
2727 v9 = &pMonsterStats->pInfos[v7 + 1];
2728 pActors[uNumActors].Reset();
2729 strcpy(actor->pActorName, v9->pName);
2730 actor->sCurrentHP = LOWORD(v9->uHP);
2731 memcpy(&actor->pMonsterInfo, v9, sizeof(actor->pMonsterInfo));
2732 actor->word_000086_some_monster_id = summonMonsterBaseType;
2733 actor->uActorRadius = pMonsterList->pMonsters[v7].uMonsterRadius;
2734 actor->uActorHeight = pMonsterList->pMonsters[v7].uMonsterHeight;
2735 actor->pMonsterInfo.uTreasureDiceRolls = 0;
2736 actor->pMonsterInfo.uTreasureType = 0;
2737 actor->pMonsterInfo.uExp = 0;
2738 actor->uMovementSpeed = pMonsterList->pMonsters[v7].uMovementSpeed;
2739
2740 actor->vInitialPosition.x = v15;
2741 actor->vInitialPosition.y = v17;
2742 actor->vInitialPosition.z = this->vPosition.z;
2743 actor->vPosition.x = v15;
2744 actor->vPosition.y = v17;
2745 actor->vPosition.z = this->vPosition.z;
2746
2747 actor->uTetherDistance = 256;
2748 actor->uSectorID = actorSector;
2749 actor->PrepareSprites(0);
2750 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
2751 actor->uAlly = v19;
2752 actor->uCurrentActionTime = 0;
2753 actor->uGroup = this->uGroup;
2754 actor->uAIState = Summoned;
2755 actor->uCurrentActionLength = 256;
2756 actor->UpdateAnimation();
2757
2758 ++uNumActors;
2759 ++this->pMonsterInfo.uSpecialAbilityDamageDiceBonus;
2760 if ( ActorEnemy())
2761 actor->uAttributes |= ACTOR_AGGRESSOR;
2762 actor->uSummonerID = PID(OBJECT_Actor,summonerId);
2763
2764 }
2765 // 46DF1A: using guessed type int __fastcall 46DF1A_collide_against_actor(int, int);
2766 //----- (0046DF1A) --------------------------------------------------------
2767 bool Actor::_46DF1A_collide_against_actor( int a1, int a2 )
2768 {
2769 Actor *v2; // edi@1
2770 unsigned __int16 v3; // ax@1
2771 int v4; // esi@6
2772 int v8; // ecx@14
2773 int v9; // eax@14
2774 int v10; // ebx@14
2775 int v11; // esi@14
2776 int v12; // ebx@15
2777 int v13; // ebx@17
2778
2779 v2 = &pActors[a1];
2780 v3 = v2->uAIState;
2781 if ( v3 == Removed || v3 == Dying || v3 == Disabled || v3 == Dead || v3 == Summoned )
2782 return 0;
2783 v4 = v2->uActorRadius;
2784 if ( a2 )
2785 v4 = a2;
2786
2787 if (stru_721530.sMaxX > v2->vPosition.x + v4 ||
2788 stru_721530.sMinX < v2->vPosition.x - v4 ||
2789 stru_721530.sMaxY > v2->vPosition.y + v4 ||
2790 stru_721530.sMinY < v2->vPosition.y - v4 ||
2791 stru_721530.sMaxZ > v2->vPosition.z + v2->uActorHeight ||
2792 stru_721530.sMinZ < v2->vPosition.z)
2793 {
2794 return false;
2795 }
2796 v8 = v2->vPosition.x - stru_721530.normal.x;
2797 v9 = v2->vPosition.y - stru_721530.normal.y;
2798 v10 = stru_721530.prolly_normal_d + v4;
2799 v11 = (v8 * stru_721530.direction.y - v9 * stru_721530.direction.x) >> 16;
2800 v12 = (v8 * stru_721530.direction.x + v9 * stru_721530.direction.y) >> 16;
2801 if ( abs(v11) > v10 || v12 <= 0)
2802 return false;
2803 if (fixpoint_mul(stru_721530.direction.z, v12) + stru_721530.normal.z < v2->vPosition.z)
2804 return false;
2805
2806 v13 = v12 - integer_sqrt(v10 * v10 - v11 * v11);
2807 if ( v13 < 0 )
2808 v13 = 0;
2809 if ( v13 < stru_721530.field_7C )
2810 {
2811 stru_721530.field_7C = v13;
2812 stru_721530.uFaceID = PID(OBJECT_Actor,a1);
2813 }
2814 return true;
2815 }
2816 //----- (00401A91) --------------------------------------------------------
2817 void Actor::UpdateActorAI()
2818 {
2819 signed int v4; // edi@10
2820 signed int sDmg; // eax@14
2821 Player *pPlayer; // ecx@21
2822 Actor *pActor; // esi@34
2823 //unsigned __int16 v22; // ax@86
2824 unsigned int v27; // ecx@123
2825 unsigned int v28; // eax@123
2826 int v33; // eax@144
2827 int v34; // eax@147
2828 char v35; // al@150
2829 unsigned int v36; // edi@152
2830 signed int v37; // eax@154
2831 double v42; // st7@176
2832 double v43; // st6@176
2833 int v45; // eax@192
2834 unsigned __int8 v46; // cl@197
2835 signed int v47; // st7@206
2836 uint v58; // st7@246
2837 unsigned int v65; // [sp-10h] [bp-C0h]@144
2838 int v70; // [sp-10h] [bp-C0h]@213
2839 AIDirection v72; // [sp+0h] [bp-B0h]@246
2840 AIDirection a3; // [sp+1Ch] [bp-94h]@129
2841 int target_pid_type; // [sp+70h] [bp-40h]@83
2842 signed int a1; // [sp+74h] [bp-3Ch]@129
2843 int v78; // [sp+78h] [bp-38h]@79
2844 AIDirection* pDir; // [sp+7Ch] [bp-34h]@129
2845 float radiusMultiplier; // [sp+98h] [bp-18h]@33
2846 int v81; // [sp+9Ch] [bp-14h]@100
2847 signed int target_pid; // [sp+ACh] [bp-4h]@83
2848 AIState uAIState;
2849 uint v38;
2850
2851 //Build AI array
2852 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
2853 Actor::MakeActorAIList_ODM();
2854 else
2855 Actor::MakeActorAIList_BLV();
2856
2857 //Armageddon damage mechanic
2858 if ( uCurrentlyLoadedLevelType != LEVEL_Indoor && pParty->armageddon_timer > 0 )
2859 {
2860 if ( pParty->armageddon_timer > 417 )
2861 pParty->armageddon_timer = 0;
2862 else
2863 {
2864 pParty->sRotationY = (stru_5C6E00->uIntegerDoublePi - 1) & (pParty->sRotationY + rand() % 16 - 8);
2865 pParty->sRotationX = pParty->sRotationX + rand() % 16 - 8;
2866 if ( pParty->sRotationX > 128)
2867 pParty->sRotationX = 128;
2868 else if ( pParty->sRotationX < -128 )
2869 pParty->sRotationX = -128;
2870
2871 pParty->uFlags |= 2u;
2872 pParty->armageddon_timer -= pMiscTimer->uTimeElapsed;
2873 v4 = pParty->armageddonDamage + 50;
2874 if ( pParty->armageddon_timer <= 0 )
2875 {
2876 pParty->armageddon_timer = 0;
2877 for(size_t i = 0; i < uNumActors; i++)
2878 {
2879 pActor=&pActors[i];
2880 if ( pActor->CanAct() )
2881 {
2882 sDmg = pActor->CalcMagicalDamageToActor((DAMAGE_TYPE)5, v4);
2883 pActor->sCurrentHP -= sDmg;
2884 if ( sDmg )
2885 {
2886 if ( pActor->sCurrentHP >= 0 )
2887 Actor::AI_Stun(i, 4, 0);
2888 else
2889 {
2890 Actor::Die(i);
2891 if ( pActor->pMonsterInfo.uExp )
2892 pParty->GivePartyExp(pMonsterStats->pInfos[pActor->pMonsterInfo.uID].uExp);
2893 }
2894 }
2895 }
2896 }
2897 for(int i = 1; i <= 4; i++)
2898 {
2899 pPlayer = pPlayers[i];
2900 if ( !pPlayer->pConditions[Condition_Dead] && !pPlayer->pConditions[Condition_Pertified] && !pPlayer->pConditions[Condition_Eradicated] )
2901 pPlayer->ReceiveDamage(v4, DMGT_MAGICAL);
2902 }
2903 }
2904 if (pTurnEngine->pending_actions)
2905 --pTurnEngine->pending_actions;
2906 }
2907 }
2908
2909 //Turn-based mode: return
2910 if (pParty->bTurnBasedModeOn)
2911 {
2912 pTurnEngine->AITurnBasedAction();
2913 return;
2914 }
2915
2916 for (uint i = 0; i < uNumActors; ++i)
2917 {
2918 pActor = &pActors[i];
2919 ai_near_actors_targets_pid[i] = OBJECT_Player;
2920
2921 //Skip actor if: Dead / Removed / Disabled / uAttributes & 0x0400
2922 if (pActor->uAIState == Dead || pActor->uAIState == Removed || pActor->uAIState == Disabled || pActor->uAttributes & ACTOR_ALIVE)
2923 continue;
2924
2925 //Kill actor if HP == 0
2926 if (!pActor->sCurrentHP && pActor->uAIState != Dying)
2927 Actor::Die(i);
2928
2929 //Kill buffs if expired
2930 for (uint j = 0; j < 22; ++j)
2931 {
2932 if (j != 10)
2933 pActor->pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed);
2934 }
2935
2936 //If shrink expired: reset height
2937 if (pActor->pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime < 0)
2938 pActor->uActorHeight = pMonsterList->pMonsters[pActor->pMonsterInfo.uID - 1].uMonsterHeight;
2939
2940 //If Charm still active: make actor friendly
2941 if (pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0)
2942 pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
2943 //Else: reset hostilty
2944 else if (pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime < 0)
2945 pActor->pMonsterInfo.uHostilityType = pMonsterStats->pInfos[pActor->pMonsterInfo.uID].uHostilityType;
2946
2947 //If actor Paralyzed or Stoned: skip
2948 if (pActor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0 || pActor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0)
2949 continue;
2950
2951 //Calculate RecoveryTime
2952 pActor->pMonsterInfo.uRecoveryTime = max(pActor->pMonsterInfo.uRecoveryTime - pMiscTimer->uTimeElapsed, 0);
2953
2954 pActor->uCurrentActionTime += pMiscTimer->uTimeElapsed;
2955 if (pActor->uCurrentActionTime < pActor->uCurrentActionLength)
2956 continue;
2957
2958 if (pActor->uAIState == Dying)
2959 pActor->uAIState = Dead;
2960 else
2961 {
2962 if (pActor->uAIState != Summoned)
2963 {
2964 Actor::AI_StandOrBored(i, OBJECT_Player, 256, nullptr);
2965 continue;
2966 }
2967 pActor->uAIState = Standing;
2968 }
2969
2970 pActor->uCurrentActionTime = 0;
2971 pActor->uCurrentActionLength = 0;
2972 pActor->UpdateAnimation();
2973 }
2974
2975 for(v78 = 0; v78 < ai_arrays_size; ++v78)
2976 {
2977 uint actor_id = ai_near_actors_ids[v78];
2978 assert(actor_id < uNumActors);
2979
2980 pActor = &pActors[actor_id];
2981
2982 v47 = (signed int)(pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333);
2983
2984 Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true);
2985
2986 if (pActor->pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[actor_id])
2987 pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
2988
2989 target_pid = ai_near_actors_targets_pid[actor_id];
2990 target_pid_type = PID_TYPE(target_pid);
2991
2992 if ( target_pid_type == OBJECT_Actor)
2993 radiusMultiplier = 0.5;
2994 else
2995 radiusMultiplier = 1.0;
2996
2997 //v22 = pActor->uAIState;
2998 if ( pActor->uAIState == Dying || pActor->uAIState == Dead || pActor->uAIState == Removed
2999 || pActor->uAIState == Disabled || pActor->uAIState == Summoned)
3000 continue;
3001
3002 if ( !pActor->sCurrentHP )
3003 Actor::Die(actor_id);
3004
3005 for( int i = 0;i < 22; i++ )
3006 {
3007 if ( i != 10 )
3008 pActor->pActorBuffs[i].IsBuffExpiredToTime(pParty->uTimePlayed);
3009 }
3010
3011 if ( pActor->pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime < 0 )
3012 pActor->uActorHeight = pMonsterList->pMonsters[pActor->pMonsterInfo.uID - 1].uMonsterHeight;
3013 if ( pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime > 0 )
3014 pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
3015 else if ( pActor->pActorBuffs[ACTOR_BUFF_CHARM].uExpireTime < 0 )
3016 pActor->pMonsterInfo.uHostilityType = pMonsterStats->pInfos[pActor->pMonsterInfo.uID].uHostilityType;
3017
3018 //If actor is summoned and buff expired: continue and set state to Removed
3019 if ( pActor->pActorBuffs[ACTOR_BUFF_SUMMONED].uExpireTime < 0 )
3020 {
3021 pActor->uAIState = Removed;
3022 continue;
3023 }
3024
3025 if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 || (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0)
3026 {
3027 continue;
3028 }
3029
3030 v27 = pMiscTimer->uTimeElapsed;
3031 v28 = pActor->pMonsterInfo.uRecoveryTime;
3032 pActor->uCurrentActionTime += pMiscTimer->uTimeElapsed;
3033
3034 if ( (signed int)v28 > 0 )
3035 pActor->pMonsterInfo.uRecoveryTime = v28 - v27;
3036 if ( pActor->pMonsterInfo.uRecoveryTime < 0 )
3037 pActor->pMonsterInfo.uRecoveryTime = 0;
3038 if ( !pActor->ActorNearby() )
3039 pActor->uAttributes |= ACTOR_NEARBY;
3040
3041 a1 = PID(OBJECT_Actor,actor_id);
3042 Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), target_pid, &a3, 0);
3043 pDir = &a3;
3044 uAIState = pActor->uAIState;
3045
3046 if ( pActor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Friendly
3047 || (signed int)pActor->pMonsterInfo.uRecoveryTime > 0
3048 || radiusMultiplier * 307.2 < pDir->uDistance
3049 || uAIState != Pursuing && uAIState != Standing && uAIState != Tethered && uAIState != Fidgeting
3050 && !pActor->pMonsterInfo.uMissleAttack1Type || uAIState != Stunned )
3051 {
3052 if ( (signed int)pActor->uCurrentActionTime < pActor->uCurrentActionLength )
3053 continue;
3054 else if ( pActor->uAIState == AttackingMelee )
3055 {
3056 v35 = pActor->special_ability_use_check(actor_id);
3057 AttackerInfo.Add(a1, 5120, pActor->vPosition.x, pActor->vPosition.y, pActor->vPosition.z + ((signed int)pActor->uActorHeight >> 1), v35, 1 );
3058 }
3059 else if ( pActor->uAIState == AttackingRanged1 )
3060 {
3061 v34 = pActor->pMonsterInfo.uMissleAttack1Type;
3062 Actor::AI_RangedAttack(actor_id, pDir, v34, 0);
3063 }
3064 else if ( pActor->uAIState == AttackingRanged2 )
3065 {
3066 v34 = pActor->pMonsterInfo.uMissleAttack2Type;
3067 Actor::AI_RangedAttack(actor_id, pDir, v34, 1);
3068 }
3069 else if ( pActor->uAIState == AttackingRanged3 )
3070 {
3071 v65 = pActor->pMonsterInfo.uSpellSkillAndMastery1;
3072 v33 = pActor->pMonsterInfo.uSpell1ID;
3073 Actor::AI_SpellAttack(actor_id, pDir, v33, 2, v65);
3074 }
3075 else if ( pActor->uAIState == AttackingRanged4 )
3076 {
3077 v65 = pActor->pMonsterInfo.uSpellSkillAndMastery2;
3078 v33 = pActor->pMonsterInfo.uSpell2ID;
3079 Actor::AI_SpellAttack(actor_id, pDir, v33, 3, v65);
3080 }
3081 }
3082
3083 v36 = pDir->uDistance;
3084
3085 if ( pActor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Friendly)
3086 {
3087 if ( target_pid_type == OBJECT_Actor )
3088 {
3089 v36 = pDir->uDistance;
3090 v37 =pFactionTable->relations[(pActor->pMonsterInfo.uID-1) / 3 + 1][(pActors[PID_ID(target_pid)].pMonsterInfo.uID - 1) / 3 + 1];
3091 }
3092 else
3093 v37 = 4;
3094 v38 = 0;
3095 if ( v37 == 2 )
3096 v38 = 1024;
3097 else if ( v37 == 3 )
3098 v38 = 2560;
3099 else if ( v37 == 4 )
3100 v38 = 5120;
3101 if ( v37 >= 1 && v37 <= 4 && v36 < v38 || v37 == 1 )
3102 pActor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
3103 }
3104
3105 //If actor afraid: flee or if out of range random move
3106 if (pActor->pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0)
3107 {
3108 if ( (signed int)v36 >= 10240 )
3109 Actor::AI_RandomMove(actor_id, target_pid, 1024, 0);
3110 else
3111 Actor::AI_Flee(actor_id, target_pid, 0, pDir);
3112 continue;
3113 }
3114
3115 if ( pActor->pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long && target_pid )
3116 {
3117 if ( pActor->pMonsterInfo.uAIType == 1 )
3118 {
3119 if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3120 Actor::AI_Stand(actor_id, target_pid, (uint)(pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333), pDir);
3121 else
3122 {
3123 Actor::AI_Flee(actor_id, target_pid, 0, pDir);
3124 continue;
3125 }
3126
3127 }
3128 if ( !(pActor->uAttributes & ACTOR_FLEEING) )
3129 {
3130 if ( pActor->pMonsterInfo.uAIType == 2 || pActor->pMonsterInfo.uAIType == 3)
3131 {
3132 if ( pActor->pMonsterInfo.uAIType == 2 )
3133 v43 = (double)(signed int)pActor->pMonsterInfo.uHP * 0.2;
3134 if ( pActor->pMonsterInfo.uAIType == 3 )
3135 v43 = (double)(signed int)pActor->pMonsterInfo.uHP * 0.1;
3136 v42 = (double)pActor->sCurrentHP;
3137 if ( v43 > v42 && (signed int)v36 < 10240 )
3138 {
3139 Actor::AI_Flee(actor_id, target_pid, 0, pDir);
3140 continue;
3141 }
3142 }
3143 }
3144
3145 v81 = v36 - pActor->uActorRadius;
3146 if ( target_pid_type == OBJECT_Actor )
3147 v81 -= pActors[PID_ID(target_pid)].uActorRadius;
3148 if ( v81 < 0 )
3149 v81 = 0;
3150 rand();
3151 pActor->uAttributes &= ~ACTOR_UNKNOW5;//~0x40000
3152 if ( v81 < 5120 )
3153 {
3154 v45 = pActor->special_ability_use_check(actor_id);
3155 if ( v45 == 0 )
3156 {
3157 if ( pActor->pMonsterInfo.uMissleAttack1Type )
3158 {
3159 if ( (signed int)pActor->pMonsterInfo.uRecoveryTime <= 0 )
3160 Actor::AI_MissileAttack1(actor_id, target_pid, pDir);
3161 else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3162 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3163 else
3164 {
3165 if ( radiusMultiplier * 307.2 > (double)v81 )
3166 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3167 else
3168 Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, pDir);
3169 }
3170 }
3171 else
3172 {
3173 if ( (double)v81 >= radiusMultiplier * 307.2 )
3174 {
3175 if (pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY)
3176 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3177 else if ( v81 >= 1024 )//monsters
3178 Actor::AI_Pursue3(actor_id, target_pid, 0, pDir);
3179 else
3180 {
3181 v70 = (signed int)(radiusMultiplier * 307.2);
3182 //monsters
3183 //guard after player runs away
3184 // follow player
3185 Actor::AI_Pursue2(actor_id, target_pid, 0, pDir, v70);
3186 }
3187 }
3188 else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 )
3189 {
3190 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3191 }
3192 else
3193 {
3194 //monsters
3195 Actor::AI_MeleeAttack(actor_id, target_pid, pDir);
3196 }
3197 }
3198 continue;
3199 }
3200 else if ( v45 == 2 || v45 == 3 )
3201 {
3202 if ( v45 == 2 )
3203 v46 = pActor->pMonsterInfo.uSpell1ID;
3204 else
3205 v46 = pActor->pMonsterInfo.uSpell2ID;
3206 if ( v46 )
3207 {
3208 if ( (signed int)pActor->pMonsterInfo.uRecoveryTime <= 0 )
3209 {
3210 if ( v45 == 2 )
3211 Actor::AI_SpellAttack1(actor_id, target_pid, pDir);
3212 else
3213 Actor::AI_SpellAttack2(actor_id, target_pid, pDir);
3214 }
3215 else if ( radiusMultiplier * 307.2 > (double)v81 || pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3216 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3217 else
3218 Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, pDir);
3219 }
3220 else
3221 {
3222 if ( (double)v81 >= radiusMultiplier * 307.2 )
3223 {
3224 if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3225 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3226 else if ( v81 >= 1024 )
3227 Actor::AI_Pursue3(actor_id, target_pid, 256, pDir);
3228 else
3229 {
3230 v70 = (signed int)(radiusMultiplier * 307.2);
3231 Actor::AI_Pursue2(actor_id, target_pid, 0, pDir, v70);
3232 }
3233 }
3234 else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 )
3235 {
3236 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3237 }
3238 else
3239 {
3240 Actor::AI_MeleeAttack(actor_id, target_pid, pDir);
3241 }
3242 }
3243 continue;
3244 }
3245 }
3246 }
3247
3248 if ( pActor->pMonsterInfo.uHostilityType != MonsterInfo::Hostility_Long || !target_pid || v81 >= 5120 || v45 != 1 )
3249 {
3250 if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_SHORT )
3251 Actor::AI_RandomMove(actor_id, 4, 1024, 0);
3252 else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_MEDIUM )
3253 Actor::AI_RandomMove(actor_id, 4, 2560, 0);
3254 else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_LONG )
3255 Actor::AI_RandomMove(actor_id, 4, 5120, 0);
3256 else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_FREE )
3257 Actor::AI_RandomMove(actor_id, 4, 10240, 0);
3258 else if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3259 {
3260 Actor::GetDirectionInfo(a1, 4, &v72, 0);
3261 v58 = (uint)(pActor->pMonsterInfo.uRecoveryTime * 2.133333333333333);
3262 Actor::AI_Stand(actor_id, 4, v58, &v72);
3263 }
3264 }
3265 else if ( !pActor->pMonsterInfo.uMissleAttack2Type )
3266 {
3267 if ( (double)v81 >= radiusMultiplier * 307.2 )
3268 {
3269 if ( pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3270 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3271 else if ( v81 >= 1024 )
3272 Actor::AI_Pursue3(actor_id, target_pid, 256, pDir);
3273 else
3274 {
3275 v70 = (int)(radiusMultiplier * 307.2);
3276 Actor::AI_Pursue2(actor_id, target_pid, 0, pDir, v70);
3277 }
3278 }
3279 else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 )
3280 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3281 else
3282 Actor::AI_MeleeAttack(actor_id, target_pid, pDir);
3283 }
3284 else if ( (signed int)pActor->pMonsterInfo.uRecoveryTime > 0 )
3285 {
3286 if ( radiusMultiplier * 307.2 > (double)v81 || pActor->pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
3287 Actor::AI_Stand(actor_id, target_pid, v47, pDir);
3288 else
3289 Actor::AI_Pursue1(actor_id, target_pid, actor_id, v47, pDir);
3290 }
3291 else
3292 Actor::AI_MissileAttack2(actor_id, target_pid, pDir);
3293 }
3294 }
3295 //----- (0044665D) --------------------------------------------------------
3296 // uType: 0 -> any monster
3297 // 1 -> uParam is GroupID
3298 // 2 -> uParam is MonsterID
3299 // 3 -> uParam is ActorID
3300 // uNumAlive: 0 -> all must be alive
3301 int __fastcall IsActorAlive(unsigned int uType, unsigned int uParam, unsigned int uNumAlive)
3302 {
3303 unsigned int uAliveActors; // eax@6
3304 unsigned int uTotalActors; // [sp+0h] [bp-4h]@1
3305
3306 uTotalActors = 0;
3307 if ( uType )
3308 {
3309 if ( uType == 1 )
3310 uAliveActors = Actor::SearchActorByGroup(&uTotalActors, uParam);
3311 else
3312 {
3313 if ( uType == 2 )
3314 uAliveActors = Actor::SearchActorByMonsterID(&uTotalActors, uParam);
3315 else
3316 {
3317 if ( uType != 3 )
3318 return 0;
3319 uAliveActors = Actor::SearchActorByID(&uTotalActors, uParam);
3320 }
3321 }
3322 }
3323 else
3324 uAliveActors = Actor::SearchAliveActors(&uTotalActors);
3325
3326 if (uNumAlive)
3327 return uAliveActors >= uNumAlive;
3328 else
3329 return uTotalActors == uAliveActors;
3330 }
3331 //----- (00408B54) --------------------------------------------------------
3332 unsigned int Actor::SearchActorByID(unsigned int *pTotalActors, unsigned int a2)
3333 {
3334 //int v4; // eax@1
3335 unsigned int result; // ebx@1
3336
3337 //v4 = GetAlertStatus();
3338 *pTotalActors = 0;
3339 result = 0;
3340 if ( (pActors[a2].uAttributes & ACTOR_UNKNOW7) == GetAlertStatus() )
3341 {
3342 *pTotalActors = 1;
3343 if ( pActors[a2].IsNotAlive() == 1 )
3344 result = 1;
3345 }
3346 return result;
3347 }
3348 //----- (00408AE7) --------------------------------------------------------
3349 unsigned int Actor::SearchActorByGroup(unsigned int *pTotalActors, unsigned int uGroup)
3350 {
3351 unsigned int result; // [sp+10h] [bp-4h]@1
3352
3353 int v8 = GetAlertStatus();
3354 *pTotalActors = 0;
3355 result = 0;
3356 for ( uint i = 0; i < uNumActors; i++)
3357 {
3358 if ( (pActors[i].uAttributes & ACTOR_UNKNOW7) == v8 && pActors[i].uGroup == uGroup)
3359 {
3360 ++*pTotalActors;
3361 if ( pActors[i].IsNotAlive() == 1 )
3362 ++result;
3363 }
3364 }
3365 return result;
3366 }
3367 //----- (00408A7E) --------------------------------------------------------
3368 unsigned int Actor::SearchActorByMonsterID(unsigned int *pTotalActors, int uMonsterID)
3369 {
3370 int v8; // [sp+Ch] [bp-8h]@1
3371 unsigned int result; // [sp+10h] [bp-4h]@1
3372
3373 v8 = GetAlertStatus();
3374 *pTotalActors = 0;
3375 result = 0;
3376 for ( uint i = 0; i < uNumActors; i++)
3377 {
3378 if ( (pActors[i].uAttributes & ACTOR_UNKNOW7) == v8 && pActors[i].pMonsterInfo.field_33 == uMonsterID)
3379 {
3380 ++*pTotalActors;
3381 if ( pActors[i].IsNotAlive() == 1 )
3382 ++result;
3383 }
3384 }
3385 return result;
3386 }
3387 //----- (00408A27) --------------------------------------------------------
3388 unsigned int Actor::SearchAliveActors(unsigned int *pTotalActors)
3389 {
3390 int v2; // eax@1
3391 unsigned int result; // ebp@1
3392
3393 v2 = GetAlertStatus();
3394 result = 0;
3395 *pTotalActors = 0;
3396 for ( uint i = 0; i < uNumActors; i++)
3397 {
3398 if ( (pActors[i].uAttributes & ACTOR_UNKNOW7) == v2 )
3399 {
3400 ++*pTotalActors;
3401 if ( pActors[i].IsNotAlive() == 1 )
3402 ++result;
3403 }
3404 }
3405 return result;
3406 }
3407 //----- (00408768) --------------------------------------------------------
3408 void Actor::InitializeActors()
3409 {
3410 bool evil; // [sp+Ch] [bp-10h]@1
3411 bool bPit; // [sp+10h] [bp-Ch]@1
3412 bool good; // [sp+14h] [bp-8h]@1
3413 bool bCelestia; // [sp+18h] [bp-4h]@1
3414
3415 bCelestia = false;
3416 bPit = false;
3417 good = false;
3418 evil = false;
3419 if ( !_stricmp(pCurrentMapName, "d25.blv") )//the Celestia
3420 bCelestia = true;
3421 if ( !_stricmp(pCurrentMapName, "d26.blv") )//the Pit
3422 bPit = true;
3423 if (pParty->IsPartyGood())
3424 good = true;
3425 if (pParty->IsPartyEvil())
3426 evil = true;
3427
3428 Log::Warning(L"%S %S %u", __FILE__, __FUNCTION__, __LINE__); // ai_near_actors_targets_pid[i] for AI_Stand seems always 0; original code behaviour is identical
3429 for (uint i = 0; i < uNumActors; ++i)
3430 {
3431 Actor* actor = &pActors[i];
3432
3433 if (actor->CanAct() || actor->uAIState == Disabled)
3434 {
3435 actor->vPosition.x = actor->vInitialPosition.x;
3436 actor->vPosition.y = actor->vInitialPosition.y;
3437 actor->vPosition.z = actor->vInitialPosition.z;
3438 actor->sCurrentHP = actor->pMonsterInfo.uHP;
3439 if (actor->uAIState != Disabled)
3440 {
3441 Actor::AI_Stand(i, ai_near_actors_targets_pid[i], actor->pMonsterInfo.uRecoveryTime, 0);
3442 }
3443 }
3444
3445 actor->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
3446
3447 if (!bCelestia || good)
3448 if (!bPit || evil)
3449 if (actor->IsPeasant())
3450 actor->ResetAggressor();//~0x80000
3451
3452 actor->ResetHasItem();//~0x800000
3453 if (actor->uAttributes & ACTOR_UNKNOW9)
3454 Actor::_4031C1_update_job_never_gets_called(i, pParty->uCurrentHour, 1);
3455 }
3456 }
3457 //----- (00439474) --------------------------------------------------------
3458 void Actor::DamageMonsterFromParty(signed int a1, unsigned int uActorID_Monster, Vec3_int_ *pVelocity)
3459 {
3460 SpriteObject *projectileSprite; // ebx@1
3461 Actor *pMonster; // esi@7
3462 unsigned __int16 v16; // cx@25
3463 int v33; // eax@100
3464 int v40; // ebx@107
3465 int extraRecoveryTime; // qax@125
3466 unsigned __int16 v43; // ax@132
3467 unsigned __int16 v45; // ax@132
3468 unsigned __int64 v46; // [sp+Ch] [bp-60h]@6
3469 char *pPlayerName; // [sp+18h] [bp-54h]@12
3470 char *pMonsterName; // [sp+1Ch] [bp-50h]@6
3471 signed int a4; // [sp+44h] [bp-28h]@1
3472 bool IsAdditionalDamagePossible; // [sp+50h] [bp-1Ch]@1
3473 int v61; // [sp+58h] [bp-14h]@1
3474 bool isLifeStealing; // [sp+5Ch] [bp-10h]@1
3475 int uDamageAmount; // [sp+60h] [bp-Ch]@1
3476 DAMAGE_TYPE attackElement; // [sp+64h] [bp-8h]@27
3477
3478 projectileSprite = 0;
3479 uDamageAmount = 0;
3480 a4 = 0;
3481 v61 = 0;
3482 IsAdditionalDamagePossible = false;
3483 isLifeStealing = 0;
3484 if ( PID_TYPE(a1) == OBJECT_Item)
3485 {
3486 projectileSprite = &pSpriteObjects[PID_ID(a1)];
3487 v61 = projectileSprite->field_60_distance_related_prolly_lod;
3488 a1 = projectileSprite->spell_caster_pid;
3489 }
3490 if (PID_TYPE(a1) != OBJECT_Player)
3491 return;
3492
3493 assert(PID_ID(abs(a1)) < 4);
3494 Player* player = &pParty->pPlayers[PID_ID(a1)];
3495 pMonster = &pActors[uActorID_Monster];
3496 if (pMonster->IsNotAlive())
3497 return;
3498
3499 pMonster->uAttributes |= 0xC000;
3500 if ( pMonster->uAIState == Fleeing )
3501 pMonster->uAttributes |= ACTOR_FLEEING;
3502 bool hit_will_stun = false,
3503 hit_will_paralyze = false;
3504 if ( !projectileSprite )
3505 {
3506 int main_hand_idx = player->pEquipment.uMainHand;
3507 IsAdditionalDamagePossible = true;
3508 if ( player->HasItemEquipped(EQUIP_TWO_HANDED) )
3509 {
3510 uint main_hand_skill = player->GetMainHandItem()->GetPlayerSkillType();
3511 uint main_hand_mastery = SkillToMastery(player->pActiveSkills[main_hand_skill]);
3512 switch (main_hand_skill)
3513 {
3514 case PLAYER_SKILL_STAFF:
3515 if (main_hand_mastery >= 3)
3516 {
3517 if (rand() % 100 < (player->GetActualSkillLevel(PLAYER_SKILL_STAFF) & 0x3F)) // stun chance when mastery >= 3
3518 hit_will_stun = true;
3519 }
3520 break;
3521
3522 case PLAYER_SKILL_MACE:
3523 if (main_hand_mastery >= 3)
3524 {
3525 if (rand() % 100 < (player->GetActualSkillLevel(PLAYER_SKILL_MACE) & 0x3F))
3526 hit_will_stun = true;
3527 }
3528 if (main_hand_mastery >= 4)
3529 {
3530 if (rand() % 100 < (player->GetActualSkillLevel(PLAYER_SKILL_MACE) & 0x3F))
3531 hit_will_paralyze = true;
3532 }
3533 break;
3534 }
3535 }
3536 attackElement = DMGT_PHISYCAL;
3537 uDamageAmount = player->CalculateMeleeDamageTo(false, false, pMonster->pMonsterInfo.uID);
3538 if ( !player->PlayerHitOrMiss(pMonster, v61, a4) )
3539 {
3540 player->PlaySound(SPEECH_52, 0);
3541 return;
3542 }
3543 }
3544 else
3545 {
3546 v61 = projectileSprite->field_60_distance_related_prolly_lod;
3547 if ( projectileSprite->spell_id != SPELL_DARK_SOULDRINKER )
3548 {
3549 int d1 = abs(pParty->vPosition.x - projectileSprite->vPosition.x);
3550 int d2 = abs(pParty->vPosition.y - projectileSprite->vPosition.y);
3551 int d3 = abs(pParty->vPosition.z - projectileSprite->vPosition.z);
3552 v61 = int_get_vector_length(d1, d2, d3);
3553
3554 if ( v61 >= 5120 && !(pMonster->uAttributes & ACTOR_ALIVE) )//0x400
3555 return;
3556 else if ( v61 >= 2560 )
3557 v61 = 2;
3558 else
3559 v61 = 1;
3560 }
3561
3562 switch (projectileSprite->spell_id)
3563 {
3564 case SPELL_LASER_PROJECTILE:
3565 v16 = player->pActiveSkills[PLAYER_SKILL_BLASTER];
3566 v61 = 1;
3567 if ( SkillToMastery(v16) >= 3 )
3568 a4 = player->pActiveSkills[PLAYER_SKILL_BLASTER] & 0x3F;
3569 attackElement = DMGT_PHISYCAL;
3570 uDamageAmount = player->CalculateMeleeDamageTo(true, true, 0);
3571 if ( !player->PlayerHitOrMiss(pMonster, v61, a4) )
3572 {
3573 player->PlaySound(SPEECH_52, 0);
3574 return;
3575 }
3576 break;
3577 case SPELL_101:
3578 attackElement = DMGT_FIRE;
3579 uDamageAmount = player->CalculateRangedDamageTo(0);
3580 if ( pMonster->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime > 0 )
3581 uDamageAmount >>= 1;
3582 IsAdditionalDamagePossible = true;
3583 if ( !player->PlayerHitOrMiss(pMonster, v61, a4) )
3584 {
3585 player->PlaySound(SPEECH_52, 0);
3586 return;
3587 }
3588 break;
3589 case SPELL_EARTH_BLADES:
3590 a4 = 5 * projectileSprite->spell_level;
3591 attackElement = (DAMAGE_TYPE)player->GetSpellSchool(SPELL_EARTH_BLADES);
3592 uDamageAmount = _43AFE3_calc_spell_damage(39, projectileSprite->spell_level, projectileSprite->spell_skill, pMonster->sCurrentHP);
3593 if ( pMonster->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime > 0 )
3594 uDamageAmount >>= 1;
3595 IsAdditionalDamagePossible = false;
3596 if ( !player->PlayerHitOrMiss( pMonster, v61, a4) )
3597 {
3598 player->PlaySound(SPEECH_52, 0);
3599 return;
3600 }
3601 break;
3602 case SPELL_EARTH_STUN:
3603 uDamageAmount = 0;
3604 attackElement = DMGT_PHISYCAL;
3605 hit_will_stun = 1;
3606 if ( !player->PlayerHitOrMiss( pMonster, v61, a4) )
3607 {
3608 player->PlaySound(SPEECH_52, 0);
3609 return;
3610 }
3611 break;
3612 case SPELL_BOW_ARROW:
3613 attackElement = DMGT_PHISYCAL;
3614 uDamageAmount = player->CalculateRangedDamageTo(pMonster->word_000086_some_monster_id);
3615 if ( pMonster->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime > 0 )
3616 uDamageAmount /= 2;
3617 IsAdditionalDamagePossible = true;
3618 if ( projectileSprite->stru_24.uItemID != 0 && projectileSprite->stru_24.uSpecEnchantmentType == 3 ) //of carnage
3619 {
3620 attackElement = DMGT_FIRE;
3621 }
3622 else if ( !player->PlayerHitOrMiss( pMonster, v61, a4) )
3623 {
3624 player->PlaySound(SPEECH_52, 0);
3625 return;
3626 }
3627 break;
3628
3629 default:
3630 attackElement = (DAMAGE_TYPE)player->GetSpellSchool(projectileSprite->spell_id);
3631 IsAdditionalDamagePossible = false;
3632 uDamageAmount = _43AFE3_calc_spell_damage(projectileSprite->spell_id, projectileSprite->spell_level, projectileSprite->spell_skill, pMonster->sCurrentHP);
3633 break;
3634 }
3635 }
3636
3637 if (player->IsWeak())
3638 uDamageAmount /= 2;
3639 if ( pMonster->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 )
3640 uDamageAmount = 0;
3641 v61 = pMonster->CalcMagicalDamageToActor(attackElement, uDamageAmount);
3642 if ( !projectileSprite && player->IsUnarmed() && player->pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].uExpireTime > 0 )
3643 {
3644 v61 += pMonster->CalcMagicalDamageToActor((DAMAGE_TYPE)8, player->pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].uPower);
3645 }
3646 uDamageAmount = v61;
3647 if ( IsAdditionalDamagePossible )
3648 {
3649 if ( projectileSprite )
3650 {
3651 a4 = projectileSprite->stru_24._439DF3_get_additional_damage((int*)&attackElement, &isLifeStealing);
3652 if ( isLifeStealing && pMonster->sCurrentHP > 0 )
3653 {
3654 player->sHealth += v61 / 5;
3655 if ( player->sHealth > player->GetMaxHealth() )
3656 player->sHealth = player->GetMaxHealth();
3657 }
3658 uDamageAmount += pMonster->CalcMagicalDamageToActor(attackElement, a4);
3659 }
3660 else
3661 {
3662 for (int i = 0; i < 2; i++)
3663 {
3664 if ( player->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
3665 {
3666 ItemGen* item;
3667 if (i == 0)
3668 item = player->GetOffHandItem();
3669 else
3670 item = player->GetMainHandItem();
3671 a4 = item->_439DF3_get_additional_damage((int*)&attackElement, &isLifeStealing);
3672 if ( isLifeStealing && pMonster->sCurrentHP > 0 )
3673 {
3674 player->sHealth += v61 / 5;
3675 if ( player->sHealth > player->GetMaxHealth() )
3676 player->sHealth = player->GetMaxHealth();
3677 }
3678 uDamageAmount += pMonster->CalcMagicalDamageToActor(attackElement, a4);
3679 }
3680 }
3681 }
3682 }
3683 pMonster->sCurrentHP -= uDamageAmount;
3684 if ( uDamageAmount == 0 && !hit_will_stun )
3685 {
3686 player->PlaySound(SPEECH_52, 0);
3687 return;
3688 }
3689 if ( pMonster->sCurrentHP > 0 )
3690 {
3691 Actor::AI_Stun(uActorID_Monster, a1, 0);
3692 Actor::AggroSurroundingPeasants(uActorID_Monster, 1);
3693 if ( bShowDamage )
3694 {
3695 if ( projectileSprite )
3696 sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[189], player->pName, pMonster->pActorName, uDamageAmount);// "%s shoots %s for %lu points"
3697 else
3698 sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[164], player->pName, pMonster->pActorName, uDamageAmount);// "%s hits %s for %lu damage"
3699 ShowStatusBarString(pTmpBuf.data(), 2u);
3700 }
3701 }
3702 else
3703 {
3704 if ( pMonsterStats->pInfos[pMonster->pMonsterInfo.uID].bQuestMonster & 1 )
3705 {
3706 if ( /*pRenderer->pRenderD3D &&*/ pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
3707 {
3708 v33 = byte_4D864C && pGame->uFlags & 0x80000 ? 10 * pMonster->uActorRadius : pMonster->uActorRadius;
3709 pDecalBuilder->AddBloodsplat((float)pMonster->vPosition.x, (float)pMonster->vPosition.y, (float)pMonster->vPosition.z, 1.0, 0.0, 0.0, (float)v33, 0, 0);
3710 }
3711 }
3712 Actor::Die(uActorID_Monster);
3713 Actor::ApplyFineForKillingPeasant(uActorID_Monster);
3714 Actor::AggroSurroundingPeasants(uActorID_Monster, 1);
3715 if ( pMonster->pMonsterInfo.uExp )
3716 pParty->GivePartyExp(pMonsterStats->pInfos[pMonster->pMonsterInfo.uID].uExp);
3717 v40 = SPEECH_51;
3718 if ( rand() % 100 < 20 )
3719 v40 = ((signed int)pMonster->pMonsterInfo.uHP >= 100) + 1;
3720 player->PlaySound((PlayerSpeech)v40, 0);
3721 if ( bShowDamage )
3722 {
3723 pMonsterName = (char *)uDamageAmount;
3724 pPlayerName = player->pName; // "%s inflicts %lu points killing %s"
3725 sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[175], player->pName, uDamageAmount, pMonster);
3726 ShowStatusBarString(pTmpBuf.data(), 2u);
3727 }
3728 }
3729 if ( pMonster->pActorBuffs[ACTOR_BUFF_PAIN_REFLECTION].uExpireTime > 0
3730 && uDamageAmount != 0 )
3731 player->ReceiveDamage(uDamageAmount, attackElement);
3732 int knockbackValue = 20 * v61 / (signed int)pMonster->pMonsterInfo.uHP;
3733 if ( (player->GetSpecialItemBonus(24) || hit_will_stun) && pMonster->DoesDmgTypeDoDamage(DMGT_EARTH) )
3734 {
3735 extraRecoveryTime = 20;
3736 knockbackValue = 10;
3737 if ( !pParty->bTurnBasedModeOn )
3738 extraRecoveryTime = (int)(flt_6BE3A8_debug_recmod2 * 42.66666666666666);
3739 pMonster->pMonsterInfo.uRecoveryTime += extraRecoveryTime;
3740 if ( bShowDamage )
3741 {
3742 pMonsterName = player->pName; // "%s stuns %s"
3743 sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[635], player->pName, pMonster);
3744 ShowStatusBarString(pTmpBuf.data(), 2u);
3745 }
3746 }
3747 if ( hit_will_paralyze && pMonster->CanAct() && pMonster->DoesDmgTypeDoDamage(DMGT_EARTH))
3748 {
3749 v43 = player->GetActualSkillLevel(PLAYER_SKILL_MACE);
3750 v45 = SkillToMastery(v43);
3751 v46 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)(7680 * (v43 & 0x3F)) * 0.033333335);
3752 pMonster->pActorBuffs[ACTOR_BUFF_PARALYZED].Apply(v46, v45, 0, 0, 0);
3753 if ( bShowDamage )
3754 {
3755 pMonsterName = player->pName; // "%s paralyzes %s"
3756 sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[636], player->pName, pMonster);
3757 ShowStatusBarString(pTmpBuf.data(), 2u);
3758 }
3759 }
3760 if ( knockbackValue > 10 )
3761 knockbackValue = 10;
3762 if ( !MonsterStats::BelongsToSupertype(pMonster->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
3763 {
3764 pVelocity->x = fixpoint_mul(knockbackValue, pVelocity->x);
3765 pVelocity->y = fixpoint_mul(knockbackValue, pVelocity->y);
3766 pVelocity->z = fixpoint_mul(knockbackValue, pVelocity->z);
3767 pMonster->vVelocity.x = 50 * LOWORD(pVelocity->x);
3768 pMonster->vVelocity.y = 50 * LOWORD(pVelocity->y);
3769 pMonster->vVelocity.z = 50 * LOWORD(pVelocity->z);
3770 }
3771 Actor::AddBloodsplatOnDamageOverlay(uActorID_Monster, 1, v61);
3772 }
3773 //----- (004BBF61) --------------------------------------------------------
3774 void Actor::Arena_summon_actor( int monster_id, __int16 x, int y, int z )
3775 {
3776 int v12; // ebx@7
3777 int v13; // eax@8
3778 __int16 v16; // [sp+10h] [bp-4h]@3
3779
3780 if (uNumActors < 500)
3781 {
3782 v16 = 0;
3783 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
3784 v16 = pIndoor->GetSector(x, y, z);
3785 pActors[uNumActors].Reset();
3786 strcpy(pActors[uNumActors].pActorName, pMonsterStats->pInfos[monster_id].pName);
3787 pActors[uNumActors].sCurrentHP = LOWORD(pMonsterStats->pInfos[monster_id].uHP);
3788 memcpy(&pActors[uNumActors].pMonsterInfo, &pMonsterStats->pInfos[monster_id], 0x58u);
3789 pActors[uNumActors].word_000086_some_monster_id = monster_id;
3790 pActors[uNumActors].uActorRadius = pMonsterList->pMonsters[monster_id - 1].uMonsterRadius;
3791 pActors[uNumActors].uActorHeight = pMonsterList->pMonsters[monster_id - 1].uMonsterHeight;
3792 pActors[uNumActors].uMovementSpeed = pMonsterList->pMonsters[monster_id - 1].uMovementSpeed;
3793 pActors[uNumActors].vInitialPosition.x = x;
3794 pActors[uNumActors].vPosition.x = x;
3795 pActors[uNumActors].uAttributes |= ACTOR_AGGRESSOR;
3796 pActors[uNumActors].pMonsterInfo.uTreasureType = 0;
3797 pActors[uNumActors].pMonsterInfo.uTreasureLevel = 0;
3798 pActors[uNumActors].pMonsterInfo.uTreasureDiceSides = 0;
3799 pActors[uNumActors].pMonsterInfo.uTreasureDiceRolls = 0;
3800 pActors[uNumActors].pMonsterInfo.uTreasureDropChance = 0;
3801 pActors[uNumActors].vInitialPosition.y = y;
3802 pActors[uNumActors].vPosition.y = y;
3803 pActors[uNumActors].vInitialPosition.z = z;
3804 pActors[uNumActors].vPosition.z = z;
3805 pActors[uNumActors].uTetherDistance = 256;
3806 pActors[uNumActors].uSectorID = v16;
3807 pActors[uNumActors].uGroup = 1;
3808 pActors[uNumActors].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
3809 pActors[uNumActors].PrepareSprites(0);
3810 for ( int i = 0; i < 4; i++)
3811 pSoundList->LoadSound(pMonsterList->pMonsters[monster_id - 1].pSoundSampleIDs[i], 0);
3812 v12 = 0;
3813 do
3814 {
3815 v13 = pSoundList->LoadSound(v12 + word_4EE088_sound_ids[pMonsterStats->pInfos[monster_id].uSpell1ID], 1);
3816 v12++;
3817 }
3818 while ( v13 );
3819 ++uNumActors;
3820 }
3821 }
3822 //----- (00426E10) --------------------------------------------------------
3823 int stru319::which_player_to_attack(Actor *pActor)
3824 {
3825 signed int v2; // ebx@1
3826 bool flag; // edi@37
3827 int v22; // [sp+8h] [bp-140h]@3
3828 int Victims_list[60]; // [sp+48h] [bp-100h]@48
3829 int for_sex; // [sp+13Ch] [bp-Ch]@1
3830 int for_race; // [sp+140h] [bp-8h]@1
3831 int for_class; // [sp+144h] [bp-4h]@1
3832
3833 for_class = -1;
3834 for_race = -1;
3835 for_sex = -1;
3836 v2 = 0;
3837 if ( pActor->pMonsterInfo.uAttackPreference )
3838 {
3839 for ( uint i = 0; i < 16; i++ )
3840 {
3841 v22 = pActor->pMonsterInfo.uAttackPreference & (1 << i);
3842 if ( v22 )
3843 {
3844 switch ( v22 )
3845 {
3846 case 1:
3847 for_class = 0;
3848 break;
3849 case 2:
3850 for_class = 12;
3851 break;
3852 case 4:
3853 for_class = 16;
3854 break;
3855 case 8:
3856 for_class = 28;
3857 break;
3858 case 16:
3859 for_class = 24;
3860 break;
3861 case 32:
3862 for_class = 32;
3863 break;
3864 case 64:
3865 for_class = 20;
3866 break;
3867 case 128:
3868 for_class = 4;
3869 break;
3870 case 256:
3871 for_class = 8;
3872 break;
3873 case 512:
3874 for_sex = 0;
3875 break;
3876 case 1024:
3877 for_sex = 1;
3878 break;
3879 case 2048:
3880 for_race = 0;
3881 break;
3882 case 4096:
3883 for_race = 1;
3884 break;
3885 case 8192:
3886 for_race = 3;
3887 break;
3888 case 16384:
3889 for_race = 2;
3890 break;
3891 }
3892 v2 = 0;
3893 for ( uint j = 0; j < 4; ++j )
3894 {
3895 flag = 0;
3896 if ( for_class != -1 && for_class == pPlayers[j + 1]->classType )
3897 flag = true;
3898 if ( for_sex != -1 && for_sex == pPlayers[j + 1]->uSex )
3899 flag = true;
3900 if ( for_race != -1 && for_race == pPlayers[j + 1]->GetRace() )
3901 flag = true;
3902 if ( flag == true )
3903 {
3904 if ( !(pPlayers[j + 1]->pConditions[Condition_Paralyzed] | pPlayers[j + 1]->pConditions[Condition_Unconcious]
3905 | pPlayers[j + 1]->pConditions[Condition_Dead] | pPlayers[j + 1]->pConditions[Condition_Pertified] | pPlayers[j + 1]->pConditions[Condition_Eradicated]) )
3906 Victims_list[v2++] = j;
3907 }
3908 }
3909 }
3910 }
3911 if ( v2 )
3912 return Victims_list[rand() % v2];
3913 }
3914 for ( uint i = 0; i < 4; ++i )
3915 {
3916 if ( !(pPlayers[i + 1]->pConditions[Condition_Paralyzed] | pPlayers[i + 1]->pConditions[Condition_Unconcious]
3917 | pPlayers[i + 1]->pConditions[Condition_Dead] | pPlayers[i + 1]->pConditions[Condition_Pertified] | pPlayers[i + 1]->pConditions[Condition_Eradicated]) )
3918 Victims_list[v2++] = i;
3919 }
3920 if ( v2 )
3921 return Victims_list[rand() % v2];
3922 else
3923 return 0;
3924 }
3925 //----- (00427546) --------------------------------------------------------
3926 int stru319::_427546(int a2)
3927 {
3928 int result; // eax@2
3929
3930 if (a2 >= 0)
3931 {
3932 if (a2 >= 1)
3933 result = (a2 >= 2) + 2;
3934 else
3935 result = 1;
3936 }
3937 else
3938 {
3939 result = 0;
3940 }
3941 return result;
3942 }
3943 //----- (0042F184) --------------------------------------------------------
3944 int stru319::FindClosestActor(int pick_depth, int a3, int a4)
3945 {
3946 int v4; // edi@1
3947 stru319 *v5; // esi@1
3948 int v6; // eax@2
3949 int v7; // eax@4
3950 // int result; // eax@5
3951 // int *v9; // edx@8
3952 // signed int v10; // ebx@10
3953 // int v11; // edi@11
3954 //Actor *v12; // esi@12
3955 //unsigned __int16 v13; // ax@12
3956 // int v14; // eax@22
3957 //char v15; // zf@30
3958 // int v16; // esi@32
3959 // int v17; // ecx@34
3960 // stru319 *v18; // eax@39
3961 // int v19; // edx@39
3962 // int v20; // ecx@41
3963 // unsigned __int16 v21; // ax@42
3964 // unsigned int v22; // [sp+8h] [bp-24h]@11
3965 //unsigned int v23; // [sp+Ch] [bp-20h]@7
3966 stru319 *v24; // [sp+10h] [bp-1Ch]@1
3967 // unsigned int v25; // [sp+14h] [bp-18h]@8
3968 // int *v26; // [sp+18h] [bp-14h]@8
3969 // int v27; // [sp+1Ch] [bp-10h]@10
3970 // int *v28; // [sp+20h] [bp-Ch]@10
3971 //unsigned int v29; // [sp+24h] [bp-8h]@7
3972 // int v30; // [sp+28h] [bp-4h]@6
3973 // int i; // [sp+38h] [bp+Ch]@33
3974 // signed int v32; // [sp+3Ch] [bp+10h]@32
3975
3976 v4 = 0;
3977 v5 = this;
3978 v24 = this;
3979 //if ( pRenderer->pRenderD3D )
3980 {
3981 v6 = a3 != 0;
3982 if (a4)
3983 LOBYTE(v6) = v6 | 8;
3984 v7 = pGame->pVisInstance->PickClosestActor(OBJECT_Actor, pick_depth, v6, 657456, -1);
3985 if (v7 != -1)
3986 return (unsigned __int16)v7;
3987 else return 0;
3988 }
3989 /*else // software impl
3990 {
3991 v30 = 0;
3992 if ( pRenderer->pActiveZBuffer )
3993 {
3994 if ( (signed int)viewparams->uScreen_topL_Y < (signed int)viewparams->uScreen_BttmR_Y )
3995 {
3996 v9 = &pRenderer->pActiveZBuffer[viewparams->uScreen_topL_X + 640 * viewparams->uScreen_topL_Y];
3997 v26 = &pRenderer->pActiveZBuffer[viewparams->uScreen_topL_X + 640 * viewparams->uScreen_topL_Y];
3998 for ( v25 = viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y; v25; --v25 )
3999 {
4000 if ( (signed int)viewparams->uScreen_topL_X < (signed int)viewparams->uScreen_BttmR_X )
4001 {
4002 v28 = v9;
4003 v10 = v4;
4004 for ( v27 = viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X; v27; --v27 )
4005 {
4006 v22 = *v28;
4007 v11 = *v28 & 0xFFFF;
4008 if (PID_TYPE(v11) == OBJECT_Actor)
4009 {
4010 if ( pActors[PID_ID(v11)].uAIState != Dead )
4011 {
4012 if ( pActors[PID_ID(v11)].uAIState != Dying && pActors[PID_ID(v11)].uAIState != Removed
4013 && pActors[PID_ID(v11)].uAIState != Summoned && pActors[PID_ID(v11)].uAIState != Disabled
4014 && (!a3 || pActors[PID_ID(v11)].GetActorsRelation(0)) )
4015 {
4016 if ( (!a4 || MonsterStats::BelongsToSupertype(pActors[PID_ID(v11)].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD))
4017 && v22 <= pick_depth << 16 )
4018 {
4019 v14 = 0;
4020 if ( v10 > 0 )
4021 {
4022 for ( v14; v14 < v30; ++v14 )
4023 {
4024 if ( dword_50BDA0[v14] == v11 )
4025 break;
4026 }
4027 }
4028 if ( v14 == v30 && v10 < 100 )
4029 {
4030 ++v30;
4031 dword_50BC10[v10] = v22;
4032 dword_50BDA0[v10] = v11;
4033 ++v10;
4034 }
4035 }
4036 }
4037 }
4038 }
4039 ++v28;
4040 }
4041 v4 = v30;
4042 v5 = v24;
4043 }
4044 v9 = v26 + 640;
4045 v26 += 640;
4046 }
4047 }
4048 if ( v4 > 0 )
4049 {
4050 v16 = (int)dword_50BC10.data();
4051 for ( v32 = 1; v32 - 1 < v4; ++v32 )
4052 {
4053 for ( i = v32; i < v4; ++i )
4054 {
4055 v17 = dword_50BC10[i];
4056 if ( dword_50BC10[i] < *(int *)v16 )
4057 {
4058 dword_50BC10[i] = *(int *)v16;
4059 *(int *)v16 = v17;
4060 }
4061 }
4062 v16 += 4;
4063 }
4064 v5 = v24;
4065 if ( v4 > 0 )
4066 {
4067 v18 = v24;
4068 for ( v19 = v4; v19; --v19 )
4069 {
4070 *(int *)&v18->field_0 = (*(int *)&v18[(char *)dword_50BC10.data() - (char *)v24].field_0 >> 3) & 0x1FFF;
4071 v18 += 4;
4072 }
4073 }
4074 }
4075 v20 = 0;
4076 for ( *(int *)&v5[2000].field_0 = v4; v20 < v4; ++v20 )
4077 {
4078 v21 = pActors[*(int *)&v5[4 * v20].field_0].uAIState;
4079 if ( v21 != 4 && v21 != 5 )
4080 break;
4081 }
4082 if ( v20 != v4 )
4083 {
4084 result = 8 * *(int *)&v5[4 * v20].field_0;
4085 LOBYTE(result) = result | 3;
4086 return result;
4087 }
4088 }
4089 }
4090 return 0;*/
4091 }
4092
4093 //----- (0042F4DA) --------------------------------------------------------
4094 bool CheckActors_proximity()
4095 {
4096 signed int distance; // edi@1
4097 int for_x; // ebx@5
4098 int for_y; // [sp+Ch] [bp-10h]@5
4099 int for_z; // [sp+10h] [bp-Ch]@5
4100
4101
4102 distance = 5120;
4103 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
4104 distance = 2560;
4105
4106 if ( (signed int)uNumActors <= 0 )
4107 return false;
4108 for ( uint i = 0; i < (signed int)uNumActors; ++i )
4109 {
4110 for_x = abs(pActors[i].vInitialPosition.x - pParty->vPosition.x);
4111 for_y = abs(pActors[i].vInitialPosition.y - pParty->vPosition.y);
4112 for_z = abs(pActors[i].vInitialPosition.z - pParty->vPosition.z);
4113 if ( int_get_vector_length(for_x, for_y, for_z) < distance )
4114 {
4115 if ( pActors[i].uAIState != Dead )
4116 {
4117 if ( pActors[i].uAIState != Dying && pActors[i].uAIState != Removed
4118 && pActors[i].uAIState != Disabled && pActors[i].uAIState != Summoned
4119 && (pActors[i].ActorEnemy() || pActors[i].GetActorsRelation(0) ) )
4120 return true;
4121 }
4122 }
4123 }
4124 return false;
4125 }
4126
4127
4128 //----- (00426A5A) --------------------------------------------------------
4129 void Actor::LootActor()
4130 {
4131 signed int v2; // edi@1
4132 unsigned __int8 v7; // al@30
4133 char *v9; // [sp-4h] [bp-3Ch]@10
4134 char *v10; // [sp-4h] [bp-3Ch]@31
4135 char *v11; // [sp-4h] [bp-3Ch]@38
4136 ItemGen Dst; // [sp+Ch] [bp-2Ch]@1
4137 bool itemFound; // [sp+30h] [bp-8h]@1
4138 int v14; // [sp+34h] [bp-4h]@1
4139
4140 pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
4141 Dst.Reset();
4142 v2 = 0;
4143 itemFound = false;
4144 v14 = 0;
4145 if ( !ActorHasItem() )
4146 {
4147 for (uchar i = 0; i < this->pMonsterInfo.uTreasureDiceRolls; i++ )
4148 v14 += rand() % this->pMonsterInfo.uTreasureDiceSides + 1;
4149 if ( v14 )
4150 {
4151 pParty->PartyFindsGold(v14, 0);
4152 viewparams->bRedrawGameUI = 1;
4153 }
4154 }
4155 else
4156 {
4157 if ( this->ActorHasItems[3].uItemID != 0 && this->ActorHasItems[3].GetItemEquipType() == EQUIP_GOLD )
4158 {
4159 v14 = this->ActorHasItems[3].uSpecEnchantmentType;
4160 this->ActorHasItems[3].Reset();
4161 if ( v14 )
4162 {
4163 pParty->PartyFindsGold(v14, 0);
4164 viewparams->bRedrawGameUI = 1;
4165 }
4166 }
4167 }
4168 if ( this->uCarriedItemID )
4169 {
4170 Dst.Reset();
4171 Dst.uItemID = this->uCarriedItemID;
4172 v9 = pItemsTable->pItems[Dst.uItemID].pUnidentifiedName;
4173 if ( v14 )
4174 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[490], v14, v9);
4175 else
4176 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v9);
4177 ShowStatusBarString(pTmpBuf2.data(), 2);
4178 if ( Dst.GetItemEquipType() == 12 )
4179 {
4180 Dst.uNumCharges = rand() % 6 + Dst.GetDamageMod() + 1;
4181 Dst.uMaxCharges = Dst.uNumCharges;
4182 }
4183 if ( pItemsTable->pItems[Dst.uItemID].uEquipType == 14 && Dst.uItemID != 220 )
4184 Dst.uEnchantmentType = 2 * rand() % 4 + 2;
4185 pItemsTable->SetSpecialBonus(&Dst);
4186 if ( !pParty->AddItemToParty(&Dst) )
4187 pParty->SetHoldingItem(&Dst);
4188 this->uCarriedItemID = 0;
4189 if ( this->ActorHasItems[0].uItemID )
4190 {
4191 if ( !pParty->AddItemToParty(this->ActorHasItems) )
4192 {
4193 pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
4194 pParty->SetHoldingItem(this->ActorHasItems);
4195 }
4196 this->ActorHasItems[0].Reset();
4197 }
4198 if ( this->ActorHasItems[1].uItemID )
4199 {
4200 if ( !pParty->AddItemToParty(&this->ActorHasItems[1]) )
4201 {
4202 pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
4203 pParty->SetHoldingItem(&this->ActorHasItems[1]);
4204 }
4205 this->ActorHasItems[1].Reset();
4206 }
4207 this->Remove();
4208 return;
4209 }
4210 if ( this->ActorHasItem() )
4211 {
4212 if ( this->ActorHasItems[3].uItemID )
4213 {
4214 memcpy(&Dst, &this->ActorHasItems[3], sizeof(Dst));
4215 this->ActorHasItems[3].Reset();
4216 //v11 = pItemsTable->pItems[Dst.uItemID].pUnidentifiedName;
4217 if ( v14 )
4218 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[490], v14, pItemsTable->pItems[Dst.uItemID].pUnidentifiedName);
4219 else
4220 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[Dst.uItemID].pUnidentifiedName);
4221 ShowStatusBarString(pTmpBuf2.data(), 2);
4222 if ( !pParty->AddItemToParty(&Dst) )
4223 pParty->SetHoldingItem(&Dst);
4224 itemFound = true;
4225 }
4226 }
4227 else
4228 {
4229 if ( rand() % 100 < this->pMonsterInfo.uTreasureDropChance && (v7 = this->pMonsterInfo.uTreasureLevel) != 0 )
4230 {
4231 pItemsTable->GenerateItem(v7, this->pMonsterInfo.uTreasureType, &Dst);
4232 v10 = pItemsTable->pItems[Dst.uItemID].pUnidentifiedName;
4233 if ( v14 )
4234 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[490], v14, v10);//Вы нашли ^I[%d] золот^L[ой;ых;ых] и предмет (%s)!
4235 else
4236 sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v10);//Вы нашли ^Pv[%s]!
4237 ShowStatusBarString(pTmpBuf2.data(), 2);
4238 if ( !pParty->AddItemToParty(&Dst) )
4239 pParty->SetHoldingItem(&Dst);
4240 itemFound = true;
4241 }
4242 }
4243 if ( this->ActorHasItems[0].uItemID )
4244 {
4245 if ( !pParty->AddItemToParty(this->ActorHasItems) )
4246 {
4247 pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
4248 pParty->SetHoldingItem(this->ActorHasItems);
4249 itemFound = true;
4250 }
4251 this->ActorHasItems[0].Reset();
4252 }
4253 if ( this->ActorHasItems[1].uItemID )
4254 {
4255 if ( !pParty->AddItemToParty(&this->ActorHasItems[1]) )
4256 {
4257 pParty->sub_421B2C_PlaceInInventory_or_DropPickedItem();
4258 pParty->SetHoldingItem(&this->ActorHasItems[1]);
4259 itemFound = true;
4260 }
4261 this->ActorHasItems[1].Reset();
4262 }
4263 if ( !itemFound || rand() % 100 < 90 )//for repeatedly get gold and item
4264 this->Remove();
4265 }
4266
4267
4268 //----- (00427102) --------------------------------------------------------
4269 bool Actor::_427102_IsOkToCastSpell( signed int a2 )
4270 {
4271 switch(a2)
4272 {
4273 case SPELL_BODY_POWER_CURE:
4274 {
4275 if ( this->sCurrentHP >= (signed int)this->pMonsterInfo.uHP )
4276 return false;
4277 return true;
4278 }
4279 case SPELL_LIGHT_DISPEL_MAGIC:
4280 {
4281 for (int i = 0; i < 20; i++)
4282 {
4283 if (pParty->pPartyBuffs[i].uExpireTime > 0)
4284 return true;
4285 }
4286 for ( int i = 1; i <= 4; i++ )
4287 {
4288 for ( int j = 0; j < 22; j++ )
4289 {
4290 if (pPlayers[i]->pPlayerBuffs[j].uExpireTime > 0)
4291 return true;
4292 }
4293 }
4294 return false;
4295 }
4296 case SPELL_LIGHT_DAY_OF_PROTECTION:
4297 {
4298 return this->pActorBuffs[ACTOR_BUFF_DAY_OF_PROTECTION].uExpireTime <= 0;
4299 break;
4300 }
4301 case SPELL_LIGHT_HOUR_OF_POWER:
4302 {
4303 return this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime <= 0;
4304 break;
4305 }
4306 case SPELL_DARK_PAIN_REFLECTION:
4307 {
4308 return this->pActorBuffs[ACTOR_BUFF_PAIN_REFLECTION].uExpireTime <= 0;
4309 break;
4310 }
4311 case SPELL_BODY_HAMMERHANDS:
4312 {
4313 return this->pActorBuffs[ACTOR_BUFF_PAIN_HAMMERHANDS].uExpireTime <= 0;
4314 break;
4315 }
4316 case SPELL_FIRE_HASTE:
4317 {
4318 return this->pActorBuffs[ACTOR_BUFF_HASTE].uExpireTime <= 0;
4319 break;
4320 }
4321 case SPELL_AIR_SHIELD:
4322 {
4323 return this->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime <= 0;
4324 break;
4325 }
4326 case SPELL_EARTH_STONESKIN:
4327 {
4328 return this->pActorBuffs[ACTOR_BUFF_STONESKIN].uExpireTime <= 0;
4329 break;
4330 }
4331 case SPELL_SPIRIT_BLESS:
4332 {
4333 return this->pActorBuffs[ACTOR_BUFF_BLESS].uExpireTime <= 0;
4334 break;
4335 }
4336 case SPELL_SPIRIT_FATE:
4337 {
4338 return this->pActorBuffs[ACTOR_BUFF_FATE].uExpireTime <= 0;
4339 break;
4340 }
4341 case SPELL_SPIRIT_HEROISM:
4342 {
4343 return this->pActorBuffs[ACTOR_BUFF_HEROISM].uExpireTime <= 0;
4344 break;
4345 }
4346 default:
4347 return true;
4348 }
4349 }
4350
4351
4352 //----- (0042704B) --------------------------------------------------------
4353 ABILITY_INDEX Actor::special_ability_use_check( int a2 )
4354 {
4355 signed int okToCastSpell1; // ebx@5
4356 signed int okToCastSpell2; // edi@5
4357
4358 if ( this->pMonsterInfo.uSpecialAbilityType == 2
4359 && this->pMonsterInfo.uSpecialAbilityDamageDiceBonus < 3
4360 && rand() % 100 < 5 )
4361 this->SummonMinion(a2);
4362 okToCastSpell1 = this->_427102_IsOkToCastSpell(this->pMonsterInfo.uSpell1ID);
4363 okToCastSpell2 = this->_427102_IsOkToCastSpell(this->pMonsterInfo.uSpell2ID);
4364 if ( okToCastSpell1 && this->pMonsterInfo.uSpell1UseChance && rand() % 100 < this->pMonsterInfo.uSpell1UseChance )
4365 return ABILITY_SPELL1;
4366 if ( okToCastSpell2 && this->pMonsterInfo.uSpell2UseChance && rand() % 100 < this->pMonsterInfo.uSpell2UseChance )
4367 return ABILITY_SPELL2;
4368 if (this->pMonsterInfo.uAttack2Chance && rand() % 100 < this->pMonsterInfo.uAttack2Chance)
4369 return ABILITY_ATTACK2;
4370 return ABILITY_ATTACK1;
4371 }
4372
4373
4374
4375 //----- (004273BB) --------------------------------------------------------
4376 bool Actor::_4273BB_DoesHitOtherActor( Actor *defender, int a3, int a4 )
4377 {
4378 signed int v6; // ebx@1
4379 signed int v7; // esi@1
4380 int armorSum; // ebx@10
4381 signed int a2a; // [sp+18h] [bp+Ch]@1
4382
4383 v6 = defender->pMonsterInfo.uAC;
4384 v7 = 0;
4385 a2a = 0;
4386 if ( defender->pActorBuffs[ACTOR_BUFF_SOMETHING_THAT_HALVES_AC].uExpireTime > 0 )
4387 v6 /= 2;
4388 if ( defender->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 )
4389 v7 = defender->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower;
4390 if ( defender->pActorBuffs[ACTOR_BUFF_STONESKIN].uExpireTime > 0 && defender->pActorBuffs[ACTOR_BUFF_STONESKIN].uPower > v7 )
4391 v7 = defender->pActorBuffs[ACTOR_BUFF_STONESKIN].uPower;
4392 armorSum = v7 + v6;
4393 if ( this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 )
4394 a2a = this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower;
4395 if ( this->pActorBuffs[ACTOR_BUFF_BLESS].uExpireTime > 0 && this->pActorBuffs[ACTOR_BUFF_BLESS].uPower > a2a )
4396 a2a = this->pActorBuffs[ACTOR_BUFF_BLESS].uPower;
4397 if ( this->pActorBuffs[ACTOR_BUFF_FATE].uExpireTime > 0 )
4398 {
4399 a2a += this->pActorBuffs[ACTOR_BUFF_FATE].uPower;
4400 this->pActorBuffs[ACTOR_BUFF_FATE].Reset();
4401 }
4402 return rand() % (armorSum + 2 * this->pMonsterInfo.uLevel + 10) + a2a + 1 > armorSum + 5;
4403 }
4404
4405 //----- (004274AD) --------------------------------------------------------
4406 bool Actor::ActorHitOrMiss(Player *pPlayer)
4407 {
4408 signed int v3; // edi@1
4409 signed int v4; // esi@8
4410 int v5; // esi@8
4411
4412 v3 = 0;
4413 if ( this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 )
4414 v3 = this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower;
4415 if ( this->pActorBuffs[ACTOR_BUFF_BLESS].uExpireTime > 0 && this->pActorBuffs[ACTOR_BUFF_BLESS].uPower > v3 )
4416 v3 = this->pActorBuffs[ACTOR_BUFF_BLESS].uPower;
4417 if ( this->pActorBuffs[ACTOR_BUFF_FATE].uExpireTime > 0 )
4418 {
4419 v3 += this->pActorBuffs[ACTOR_BUFF_FATE].uPower;
4420 this->pActorBuffs[ACTOR_BUFF_FATE].Reset();
4421 }
4422 v4 = pPlayer->GetActualAC() + 2 * this->pMonsterInfo.uLevel + 10;
4423 v5 = rand() % v4 + 1;
4424 return (v3 + v5 > pPlayer->GetActualAC() + 5);
4425 }
4426
4427
4428 //----- (0042756B) --------------------------------------------------------
4429 int Actor::CalcMagicalDamageToActor(DAMAGE_TYPE dmgType, signed int incomingDmg)
4430 {
4431 int v4; // edx@1
4432 int v5; // ecx@1
4433 signed int v6; // eax@4
4434 signed int result; // eax@17
4435 signed int v8; // esi@18
4436
4437 v4 = 0;
4438 v5 = 0;
4439 if ( this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uExpireTime > 0 )
4440 v5 = this->pActorBuffs[ACTOR_BUFF_HOUR_OF_POWER].uPower;
4441 switch ( dmgType )
4442 {
4443 case DMGT_FIRE:
4444 v6 = this->pMonsterInfo.uResFire;
4445 v4 = v5;
4446 break;
4447 case DMGT_ELECTR:
4448 v6 = this->pMonsterInfo.uResAir;
4449 v4 = v5;
4450 break;
4451 case DMGT_COLD:
4452 v6 = this->pMonsterInfo.uResWater;
4453 v4 = v5;
4454 break;
4455 case DMGT_EARTH:
4456 v6 = this->pMonsterInfo.uResEarth;
4457 v4 = v5;
4458 break;
4459 case DMGT_PHISYCAL:
4460 v6 = this->pMonsterInfo.uResPhysical;
4461 break;
4462 case DMGT_SPIRIT:
4463 v6 = this->pMonsterInfo.uResSpirit;
4464 break;
4465 case DMGT_MIND:
4466 v6 = this->pMonsterInfo.uResMind;
4467 v4 = v5;
4468 break;
4469 case DMGT_BODY:
4470 v6 = this->pMonsterInfo.uResBody;
4471 v4 = v5;
4472 break;
4473 case DMGT_LIGHT:
4474 v6 = this->pMonsterInfo.uResLight;
4475 break;
4476 case DMGT_DARK:
4477 v6 = this->pMonsterInfo.uResDark;
4478 break;
4479 default:
4480 v6 = 0;
4481 break;
4482 }
4483 if ( v6 < 200 )
4484 {
4485 v8 = v4 + v6 + 30;
4486 for (int i = 0; i < 4; i++)
4487 {
4488 if ( rand() % v8 < 30 )
4489 break;
4490 incomingDmg /= 2;
4491 }
4492 result = incomingDmg;
4493 }
4494 else
4495 result = 0;
4496 return result;
4497 }
4498
4499 //----- (00427662) --------------------------------------------------------
4500 bool Actor::DoesDmgTypeDoDamage(DAMAGE_TYPE uType)
4501 {
4502 signed int resist; // esi@2
4503 bool result; // eax@13
4504
4505 switch ( uType )
4506 {
4507 case 0:
4508 resist = this->pMonsterInfo.uResFire;
4509 break;
4510 case 1:
4511 resist = this->pMonsterInfo.uResAir;
4512 break;
4513 case 2:
4514 resist = this->pMonsterInfo.uResWater;
4515 break;
4516 case 3:
4517 resist = this->pMonsterInfo.uResEarth;
4518 break;
4519 case 4:
4520 resist = this->pMonsterInfo.uResPhysical;
4521 break;
4522 case 6:
4523 resist = this->pMonsterInfo.uResSpirit;
4524 break;
4525 case 7:
4526 resist = this->pMonsterInfo.uResMind;
4527 case 8:
4528 resist = this->pMonsterInfo.uResBody;
4529 break;
4530 case 9:
4531 resist = this->pMonsterInfo.uResLight;
4532 break;
4533 case 10:
4534 resist = this->pMonsterInfo.uResDark;
4535 break;
4536 default:
4537 return 1;
4538 }
4539 if ( resist < 200 )
4540 result = rand() % ((this->pMonsterInfo.uLevel >> 2) + resist + 30) < 30;
4541 else
4542 result = 0;
4543 return result;
4544 }
4545
4546 //----- (00448A98) --------------------------------------------------------
4547 void __fastcall ToggleActorGroupFlag(unsigned int uGroupID, unsigned int uFlag, unsigned int bToggle)
4548 {
4549 if ( uGroupID )
4550 {
4551 if ( bToggle )
4552 {
4553 for ( uint i = 0; i < (unsigned int)uNumActors; ++i )
4554 {
4555 if ( pActors[i].uGroup == uGroupID )
4556 {
4557 pActors[i].uAttributes |= uFlag;
4558 if ( uFlag == 0x10000 )
4559 {
4560 pActors[i].uAIState = Disabled;
4561 pActors[i].UpdateAnimation();
4562 }
4563 }
4564 }
4565 }
4566 else
4567 {
4568 for ( uint i = 0; i < (unsigned int)uNumActors; ++i )
4569 {
4570 if ( pActors[i].uGroup == uGroupID )
4571 {
4572 if ( uFlag == 0x10000 )
4573 {
4574 if ( pActors[i].uAIState != Dead )
4575 {
4576 if ( pActors[i].uAIState != 4 && pActors[i].uAIState != 11 )
4577 pActors[i].uAIState = Standing;
4578 }
4579 }
4580 LODWORD(pActors[i].uAttributes) &= ~uFlag;
4581 }
4582 }
4583 }
4584 }
4585 }
4586
4587 //----- (004014E6) --------------------------------------------------------
4588 void Actor::MakeActorAIList_ODM()
4589 {
4590 int v1; // eax@4
4591 unsigned int v7; // ST20_4@10
4592 int distance; // edi@10
4593 int v10; // ebx@14
4594 int v21; // [sp+Ch] [bp-14h]@4
4595 int v22; // [sp+10h] [bp-10h]@4
4596
4597 pParty->uFlags &= 0xFFFFFFCF;//~0x30
4598
4599 ai_arrays_size = 0;
4600 for (uint i = 0; i < uNumActors; ++i)
4601 {
4602 Actor* actor = &pActors[i];
4603
4604 actor->ResetAlive();//~0x400
4605 if (!actor->CanAct())
4606 {
4607 actor->ResetActive();
4608 continue;
4609 }
4610
4611 v22 = abs(pParty->vPosition.z - actor->vPosition.z);
4612 v21 = abs(pParty->vPosition.y - actor->vPosition.y);
4613 v1 = abs(pParty->vPosition.x - actor->vPosition.x);
4614 v7 = int_get_vector_length(v22, v21, v1);
4615 distance = v7 - actor->uActorRadius;
4616 if ( distance < 0 )
4617 distance = 0;
4618
4619 if (distance < 5632)
4620 {
4621 actor->ResetHostile();
4622 if ( actor->ActorEnemy() || actor->GetActorsRelation(0) )
4623 {
4624 //v11 = (pParty->uFlags & 0x10) == 0;
4625 actor->uAttributes |= ACTOR_HOSTILE;
4626 if (distance < 5120 )
4627 pParty->SetYellowAlert();
4628 if (distance < 307)
4629 pParty->SetRedAlert();
4630 }
4631 actor->uAttributes |= ACTOR_ACTIVE;
4632 ai_near_actors_distances[ai_arrays_size] = distance;
4633 ai_near_actors_ids[ai_arrays_size++] = i;
4634 }
4635 else
4636 actor->ResetActive();
4637 }
4638
4639 /*
4640 result = v27;
4641 if ( v27 > 0 )
4642 {
4643 v14 = 0;
4644 v15 = 1;
4645 v26 = 1;
4646 do
4647 {
4648 while ( 1 )
4649 {
4650 v24 = v15;
4651 if ( v15 >= result )
4652 break;
4653 v16 = ai_near_actors_distances[v14];
4654 if ( v16 > ai_near_actors_distances[v15] )
4655 {
4656 v17 = &ai_near_actors_ids[v15];
4657 v18 = ai_near_actors_ids[v14];
4658 ai_near_actors_ids[v14] = *v17;
4659 *v17 = v18;
4660 v15 = v24;
4661 ai_near_actors_distances[v14] = ai_near_actors_distances[v24];
4662 ai_near_actors_distances[v24] = v16;
4663 }
4664 result = v27;
4665 ++v15;
4666 }
4667 ++v14;
4668 v15 = v26 + 1;
4669 v26 = v15;
4670 }
4671 while ( v15 - 1 < result );
4672 }*/
4673
4674 for (uint i = 0; i < ai_arrays_size; ++i)
4675 for (uint j = 0; j < i; ++j)
4676 if (ai_near_actors_distances[j] > ai_near_actors_distances[i])
4677 {
4678 int tmp = ai_near_actors_distances[j];
4679 ai_near_actors_distances[j] = ai_near_actors_distances[i];
4680 ai_near_actors_distances[i] = tmp;
4681
4682 tmp = ai_near_actors_ids[j];
4683 ai_near_actors_ids[j] = ai_near_actors_ids[i];
4684 ai_near_actors_ids[i] = tmp;
4685 }
4686
4687
4688 if (ai_arrays_size > 30)
4689 ai_arrays_size = 30;
4690
4691 for (uint i = 0; i < ai_arrays_size; ++i)
4692 pActors[ai_near_actors_ids[i]].uAttributes |= ACTOR_ALIVE;//0x400
4693 }
4694
4695 //----- (004016FA) --------------------------------------------------------
4696 int Actor::MakeActorAIList_BLV()
4697 {
4698 int v1; // eax@4
4699 int distance; // edi@10
4700 int v13; // edx@24
4701 int v15; // ebx@26
4702 unsigned int v17; // esi@27
4703 int v18; // ecx@31
4704 signed int v19; // edi@31
4705 signed int v25; // eax@40
4706 int j; // edi@45
4707 int v30; // eax@48
4708 int v37; // [sp+Ch] [bp-18h]@1
4709 int v38; // [sp+10h] [bp-14h]@4
4710 int v39; // [sp+14h] [bp-10h]@4
4711 int i; // [sp+18h] [bp-Ch]@31
4712 uint v45; // [sp+20h] [bp-4h]@1
4713
4714 // __debugbreak(); // refactor for blv ai
4715 pParty->uFlags &= 0xFFFFFFCF;//~0x30
4716 v37 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
4717 v45 = 0;
4718 for ( uint i = 0; i < (signed int)uNumActors; ++i )
4719 {
4720 pActors[i].ResetAlive();//~0x0400
4721 if ( !pActors[i].CanAct() )
4722 {
4723 pActors[i].ResetActive();
4724 continue;
4725 }
4726 v1 = abs(pParty->vPosition.x - pActors[i].vPosition.x);
4727 v38 = abs(pParty->vPosition.y - pActors[i].vPosition.y);
4728 v39 = abs(pParty->vPosition.z - pActors[i].vPosition.z);
4729
4730 distance = int_get_vector_length(v39, v38, v1) - pActors[i].uActorRadius;
4731 if ( distance < 0 )
4732 distance = 0;
4733 if ( distance < 10240 )
4734 {
4735 pActors[i].ResetHostile();//~0x01000000
4736 if ( pActors[i].ActorEnemy() || pActors[i].GetActorsRelation(0) )
4737 {
4738 pActors[i].uAttributes |= ACTOR_HOSTILE;
4739 if ( !(pParty->uFlags & 0x10) && (double)distance < 307.2 )
4740 pParty->SetRedAlert();
4741 if ( !(pParty->uFlags & 0x20) && distance < 5120 )
4742 pParty->SetYellowAlert();
4743 }
4744 ai_near_actors_distances[v45] = distance;
4745 ai_near_actors_ids[v45] = i;
4746 v45++;
4747 }
4748 else
4749 pActors[i].ResetActive();
4750 }
4751 v13 = 0;
4752 if ( v45 > 0 )
4753 {
4754 for ( uint i = 1; i < v45; i++ )
4755 {
4756 for ( uint j = 1; j < v45; ++j )
4757 {
4758 v15 = ai_near_actors_distances[v13];
4759 if ( ai_near_actors_distances[v13] > ai_near_actors_distances[j] )
4760 {
4761 v17 = ai_near_actors_ids[v13];
4762 ai_near_actors_ids[v13] = ai_near_actors_ids[j];
4763 ai_near_actors_ids[j] = v17;
4764 ai_near_actors_distances[v13] = ai_near_actors_distances[j];
4765 ai_near_actors_distances[j] = v15;
4766 }
4767 }
4768 ++v13;
4769 }
4770 }
4771 v18 = 0;
4772 v19 = 0;
4773 for ( i = 0; i < v45; i++ )
4774 {
4775 if ( pActors[ai_near_actors_ids[i]].ActorNearby()
4776 || sub_4070EF_prolly_detect_player(PID(OBJECT_Actor,ai_near_actors_ids[i]), 4) )
4777 {
4778 pActors[ai_near_actors_ids[i]].uAttributes |= ACTOR_NEARBY;
4779 ai_array_4F6638_actor_ids[v19] = ai_near_actors_ids[i];
4780 ai_array_4F5E68[v19++] = ai_near_actors_distances[i];
4781 if ( v19 >= 30 )
4782 break;
4783 }
4784 }
4785 ai_arrays_size = v19;
4786 if ( (signed int)uNumActors > 0 )
4787 {
4788 for ( uint i = 0; i < (signed int)uNumActors; ++i )
4789 {
4790 if ( pActors[i].CanAct() && pActors[i].uSectorID == v37 )
4791 {
4792 v25 = 0;
4793 if ( v19 <= 0 )
4794 {
4795 pActors[i].uAttributes |= ACTOR_ACTIVE;
4796 ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
4797 }
4798 else
4799 {
4800 while ( ai_array_4F6638_actor_ids[v25] != i )
4801 {
4802 ++v25;
4803 if ( v25 >= v19 )
4804 {
4805 pActors[i].uAttributes |= ACTOR_ACTIVE;
4806 ai_array_4F6638_actor_ids[ai_arrays_size++] = i;
4807 break;
4808 }
4809 }
4810 }
4811 }
4812 }
4813 }
4814 for ( j = 0; j < v45; ++j )
4815 {
4816 if ( pActors[ai_near_actors_ids[j]].uAttributes & 0xC000 && pActors[ai_near_actors_ids[j]].CanAct() )
4817 {
4818 v30 = 0;
4819 if ( ai_arrays_size <= 0 )
4820 ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
4821 else
4822 {
4823 while ( ai_array_4F6638_actor_ids[v30] != ai_near_actors_ids[j] )
4824 {
4825 ++v30;
4826 if ( v30 >= ai_arrays_size )
4827 {
4828 ai_array_4F6638_actor_ids[ai_arrays_size++] = ai_near_actors_ids[j];
4829 break;
4830 }
4831 }
4832 }
4833 }
4834 }
4835 if ( ai_arrays_size > 30 )
4836 ai_arrays_size = 30;
4837 memcpy(ai_near_actors_ids.data(), ai_array_4F6638_actor_ids.data(), 4 * ai_arrays_size);
4838 memcpy(ai_near_actors_distances.data(), ai_array_4F5E68.data(), 4 * ai_arrays_size);
4839 for ( uint i = 0; i < ai_arrays_size; i++ )
4840 pActors[ai_near_actors_ids[i]].uAttributes |= ACTOR_ALIVE;//0x400
4841 return ai_arrays_size;
4842 }
4843
4844
4845 //----- (004070EF) --------------------------------------------------------
4846 bool __fastcall sub_4070EF_prolly_detect_player(unsigned int uObjID, unsigned int uObj2ID)
4847 {
4848 signed int v2; // eax@1
4849 int obj1_sector; // eax@4
4850 float v8; // ST24_4@5
4851 signed int v12; // eax@7
4852 int obj2_z; // edi@11
4853 int obj2_x; // esi@11
4854 int obj2_sector; // eax@13
4855 float v20; // ST24_4@14
4856 int dist_x; // ebx@16
4857 signed int dist_3d; // ecx@16
4858 int v25; // eax@18
4859 BLVFace *v29; // ebx@32
4860 Vec3_short_ *v30; // esi@32
4861 int v31; // eax@32
4862 int v32; // ST50_4@44
4863 int v33; // ST54_4@44
4864 int v34; // eax@44
4865 signed int v38; // esi@45
4866 __int16 next_sector; // bx@58
4867 int v47; // [sp+18h] [bp-50h]@20
4868 int v48; // [sp+1Ch] [bp-4Ch]@20
4869 int v49; // [sp+20h] [bp-48h]@20
4870 int dist_z; // [sp+24h] [bp-44h]@16
4871 signed int higher_z; // [sp+24h] [bp-44h]@27
4872 signed int lower_z; // [sp+28h] [bp-40h]@26
4873 signed int higher_y; // [sp+2Ch] [bp-3Ch]@23
4874 signed int lower_y; // [sp+30h] [bp-38h]@22
4875 signed int higher_x; // [sp+34h] [bp-34h]@21
4876 signed int lower_x; // [sp+38h] [bp-30h]@20
4877 signed int sectors_visited; // [sp+3Ch] [bp-2Ch]@28
4878 int v58; // [sp+44h] [bp-24h]@50
4879 int v59; // [sp+48h] [bp-20h]@44
4880 int obj2_y; // [sp+50h] [bp-18h]@11
4881 int obj1_x; // [sp+58h] [bp-10h]@4
4882 int obj1_y; // [sp+5Ch] [bp-Ch]@4
4883 int obj1_z; // [sp+60h] [bp-8h]@4
4884 int current_sector; // [sp+64h] [bp-4h]@7
4885 int dist_y;
4886 int v70;
4887
4888 v2 = PID_ID(uObjID);
4889 switch( PID_TYPE(uObjID) )
4890 {
4891 case OBJECT_Decoration:
4892 obj1_x = pLevelDecorations[v2].vPosition.x;
4893 obj1_y = pLevelDecorations[v2].vPosition.y;
4894 obj1_z = pLevelDecorations[v2].vPosition.z;
4895 obj1_sector = pIndoor->GetSector(obj1_x, obj1_y, obj1_z);
4896 break;
4897 case OBJECT_Actor:
4898 obj1_x = pActors[v2].vPosition.x;
4899 obj1_y = pActors[v2].vPosition.y;
4900 v8 = (double)pActors[v2].uActorHeight * 0.69999999;
4901 //v9 = v8 + 6.7553994e15;
4902 //obj1_z = LODWORD(v9) + pActors[v2].vPosition.z;
4903 obj1_z = (int)v8 + pActors[v2].vPosition.z;
4904 obj1_sector = pActors[v2].uSectorID;
4905 break;
4906 case OBJECT_Item:
4907 obj1_x = pSpriteObjects[v2].vPosition.x;
4908 obj1_y = pSpriteObjects[v2].vPosition.y;
4909 obj1_z = pSpriteObjects[v2].vPosition.z;
4910 obj1_sector = pSpriteObjects[v2].uSectorID;
4911 break;
4912 default:
4913 return 0;
4914 }
4915 v12 = PID_ID(uObj2ID);
4916 switch( PID_TYPE(uObj2ID) )
4917 {
4918 case OBJECT_Decoration:
4919 obj2_z = pLevelDecorations[v12].vPosition.z;
4920 obj2_x = pLevelDecorations[v12].vPosition.x;
4921 obj2_y = pLevelDecorations[v12].vPosition.y;
4922 obj2_sector = pIndoor->GetSector(obj2_x, obj2_y, obj2_z);
4923 break;
4924 case OBJECT_Player:
4925 obj2_x = pParty->vPosition.x;
4926 obj2_z = pParty->sEyelevel + pParty->vPosition.z;
4927 obj2_y = pParty->vPosition.y;
4928 obj2_sector = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->sEyelevel + pParty->vPosition.z);
4929 break;
4930 case OBJECT_Actor:
4931 obj2_y = pActors[v12].vPosition.y;
4932 obj2_x = pActors[v12].vPosition.x;
4933 v20 = (double)pActors[v12].uActorHeight * 0.69999999;
4934 //v21 = v20 + 6.7553994e15;
4935 //obj2_z = LODWORD(v21) + pActors[v12].vPosition.z;
4936 obj2_z = (int)v20 + pActors[v12].vPosition.z;
4937 obj2_sector = pActors[v12].uSectorID;
4938 break;
4939 case OBJECT_Item:
4940 obj2_x = pSpriteObjects[v12].vPosition.x;
4941 obj2_z = pSpriteObjects[v12].vPosition.z;
4942 obj2_y = pSpriteObjects[v12].vPosition.y;
4943 obj2_sector = pSpriteObjects[v12].uSectorID;
4944 break;
4945 default:
4946 return 0;
4947 }
4948 dist_x = obj2_x - obj1_x;
4949 dist_z = obj2_z - obj1_z;
4950 dist_y = obj2_y - obj1_y;
4951 dist_3d = integer_sqrt(dist_x * dist_x + dist_y * dist_y + dist_z * dist_z);
4952 //range check
4953 if ( dist_3d > 5120 )
4954 return 0;
4955 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
4956 return 1;
4957 v25 = 65536;
4958 if ( dist_3d )
4959 v25 = 65536 / dist_3d;
4960 v49 = dist_x * v25;
4961 v47 = dist_z * v25;
4962 v48 = dist_y * v25;
4963 if ( obj1_x < obj2_x )
4964 {
4965 lower_x = obj1_x;
4966 higher_x = obj2_x;
4967 }
4968 else
4969 {
4970 lower_x = obj2_x;
4971 higher_x = obj1_x;
4972 }
4973 if ( obj1_y < obj2_y )
4974 {
4975 lower_y = obj1_y;
4976 higher_y = obj2_y;
4977 }
4978 else
4979 {
4980 lower_y = obj2_y;
4981 higher_y = obj1_y;
4982 }
4983 if ( obj1_z < obj2_z )
4984 {
4985 lower_z = obj1_z;
4986 higher_z = obj2_z;
4987 }
4988 else
4989 {
4990 lower_z = obj2_z;
4991 higher_z = obj1_z;
4992 }
4993 sectors_visited = 0;
4994 //monster in same sector with player
4995 if ( obj1_sector == obj2_sector )
4996 return 1;
4997 //search starts from monster
4998 current_sector = obj1_sector;
4999 for( int current_portal = 0; current_portal < pIndoor->pSectors[current_sector].uNumPortals; current_portal++ )
5000 {
5001 v29 = &pIndoor->pFaces[pIndoor->pSectors[current_sector].pPortals[current_portal]];
5002 v30 = &pIndoor->pVertices[*v29->pVertexIDs];
5003 v31 = v29->pFacePlane_old.vNormal.z * (v30->z - obj1_z)
5004 + v29->pFacePlane_old.vNormal.y * (v30->y - obj1_y)
5005 + v29->pFacePlane_old.vNormal.x * (v30->x - obj1_x);
5006
5007 if ( current_sector != v29->uSectorID )
5008 v31 = -v31;
5009
5010 if ( v31 >= 0 && v30->x != obj1_x && v30->y != obj1_y && v30->z != obj1_z)
5011 continue;
5012
5013 if( lower_x > v29->pBounding.x2
5014 || higher_x < v29->pBounding.x1
5015 || lower_y > v29->pBounding.y2
5016 || higher_y < v29->pBounding.y1
5017 || lower_z > v29->pBounding.z2
5018 || higher_z < v29->pBounding.z1 )
5019 {
5020 continue;
5021 }
5022
5023 v32 = fixpoint_mul(v29->pFacePlane_old.vNormal.x,v49);
5024 v34 = fixpoint_mul(v29->pFacePlane_old.vNormal.y,v48);
5025 v33 = fixpoint_mul(v29->pFacePlane_old.vNormal.z,v47);
5026
5027 v59 = v32 + v33 + v34;
5028 if ( v59 )
5029 {
5030 v70 = v29->pFacePlane_old.dist
5031 + obj1_z * v29->pFacePlane_old.vNormal.z
5032 + obj1_x * v29->pFacePlane_old.vNormal.x
5033 + obj1_y * v29->pFacePlane_old.vNormal.y;
5034 v38 = -v70;
5035
5036 // if ( v59 <= 0 ^ v70 <= 0 )
5037
5038 /* TEMPORARY
5039 if ( v59 <= 0 && v70 <= 0 )
5040 {
5041 continue;
5042 }
5043 if ( !(v59 <= 0 && v70 <= 0) )
5044 {
5045 continue;
5046 }
5047 */
5048
5049 if( abs(v38) >> 14 > abs(v59) )
5050 continue;
5051
5052 v58 = fixpoint_div(v38,v59);
5053
5054 if( v58 < 0 )
5055 continue;
5056
5057 if(!sub_4075DB(obj1_x + ((fixpoint_mul(v49,v58) + 32768) >> 16), obj1_y + ((fixpoint_mul(v48,v58) + 32768) >> 16),
5058 obj1_z + ((fixpoint_mul(v47,v58) + 32768) >> 16), v29) )
5059 {
5060 continue;
5061 }
5062
5063 //if there is no next sector turn back
5064 if ( v29->uSectorID == current_sector )
5065 next_sector = v29->uBackSectorID;
5066 else
5067 next_sector = v29->uSectorID;
5068
5069 //no more portals, quit
5070 if ( next_sector == current_sector )
5071 break;
5072
5073 ++sectors_visited;
5074 current_sector = next_sector;
5075
5076 //found player, quit
5077 if ( next_sector == obj2_sector )
5078 return 1;
5079
5080 current_sector = next_sector;
5081
5082 //did we hit limit for portals?
5083 //does the next room have portals?
5084 if ( sectors_visited < 30 && pIndoor->pSectors[current_sector].uNumPortals > 0)
5085 {
5086 current_portal=-1;
5087 continue;
5088 }
5089 else
5090 break;
5091 }
5092 }
5093 //did we stop in the sector where player is?
5094 if ( current_sector != obj2_sector )
5095 return 0;
5096 return 1;
5097 }
5098
5099
5100 //----- (00450B0A) --------------------------------------------------------
5101 bool __fastcall SpawnActor(unsigned int uMonsterID)
5102 {
5103 unsigned int v1; // ebx@1
5104 bool result; // eax@2
5105 unsigned int v6; // ecx@5
5106 Actor actor; // [sp+4h] [bp-350h]@5
5107 Vec3_int_ pOut; // [sp+348h] [bp-Ch]@5
5108
5109 v1 = uMonsterID;
5110 if ( uNumActors == 499 )
5111 result = 0;
5112 else
5113 {
5114 if ( (signed int)uMonsterID >= (signed int)pMonsterList->uNumMonsters )
5115 v1 = 0;
5116 memset(&actor, 0, sizeof(Actor));
5117 strcpy(actor.pActorName, pMonsterStats->pInfos[v1 + 1].pName);
5118 actor.sCurrentHP = LOWORD(pMonsterStats->pInfos[v1 + 1].uHP);
5119 memcpy(&actor.pMonsterInfo, &pMonsterStats->pInfos[v1 + 1], sizeof(MonsterInfo));
5120 actor.word_000086_some_monster_id = v1 + 1;
5121 actor.uActorRadius = pMonsterList->pMonsters[v1].uMonsterRadius;
5122 actor.uActorHeight = pMonsterList->pMonsters[v1].uMonsterHeight;
5123 actor.uMovementSpeed = pMonsterList->pMonsters[v1].uMovementSpeed;
5124
5125 Vec3_int_::Rotate(200, pParty->sRotationY, 0, pParty->vPosition, &pOut.x, &pOut.z, &pOut.y);
5126 actor.vInitialPosition.x = pOut.x;
5127 actor.vPosition.x = pOut.x;
5128 actor.uTetherDistance = 256;
5129 actor.vInitialPosition.y = LOWORD(pOut.z);
5130 actor.vPosition.y = LOWORD(pOut.z);
5131 actor.vInitialPosition.z = LOWORD(pOut.y);
5132 actor.vPosition.z = LOWORD(pOut.y);
5133 pSprites_LOD->DeleteSomeSprites();
5134 pPaletteManager->ResetNonTestLocked();
5135 v6 = uNumActors - 1;
5136 if ( dword_5C6DF8 == 1 )
5137 {
5138 dword_5C6DF8 = 0;
5139 v6 = uNumActors++;
5140 }
5141 memcpy(&pActors[v6], &actor, sizeof(Actor));
5142 pActors[v6].PrepareSprites(1);
5143 result = 1;
5144 }
5145 return result;
5146 }
5147 // 5C6DF8: using guessed type int dword_5C6DF8;
5148
5149
5150 //----- (0044FA4C) --------------------------------------------------------
5151 signed int __fastcall sub_44FA4C_spawn_light_elemental(int a1, int a2, int a3)
5152 {
5153 signed int result; // eax@13
5154 int v10; // ebx@16
5155 const char *v15; // [sp-4h] [bp-24h]@2
5156 unsigned int uFaceID; // [sp+8h] [bp-18h]@16
5157 int v19; // [sp+Ch] [bp-14h]@16
5158 size_t v20; // [sp+10h] [bp-10h]@6
5159 int v21; // [sp+14h] [bp-Ch]@14
5160 unsigned int v23; // [sp+1Ch] [bp-4h]@6
5161
5162 if ( a2 == 4 )
5163 v15 = "Elemental Light C";
5164 else if ( a2 == 3 )
5165 v15 = "Elemental Light B";
5166 else
5167 v15 = "Elemental Light A";
5168
5169 v23 = pMonsterList->GetMonsterIDByName(v15);
5170 v20 = 0;
5171 for ( v20; v20 < uNumActors; v20++ )
5172 {
5173 if ( pActors[v20].uAIState == Removed )
5174 break;
5175 }
5176
5177 result = uNumActors + 1;
5178 if ( v20 != uNumActors || result < 500 )
5179 {
5180 v21 = 0;
5181 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
5182 v21 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z);
5183 v19 = (((uCurrentlyLoadedLevelType != LEVEL_Outdoor) - 1) & 0x40) + 64;
5184 pActors[v20].Reset();
5185 strcpy(pActors[v20].pActorName, pMonsterStats->pInfos[v23 + 1].pName);
5186 pActors[v20].sCurrentHP = pMonsterStats->pInfos[v23 + 1].uHP;
5187 memcpy(&pActors[v20].pMonsterInfo, &pMonsterStats->pInfos[v23 + 1], sizeof(MonsterInfo));
5188 pActors[v20].word_000086_some_monster_id = v23 + 1;
5189 pActors[v20].uActorRadius = pMonsterList->pMonsters[v23].uMonsterRadius;
5190 pActors[v20].uActorHeight = pMonsterList->pMonsters[v23].uMonsterHeight;
5191 pActors[v20].pMonsterInfo.uTreasureDiceRolls = 0;
5192 pActors[v20].pMonsterInfo.uTreasureType = 0;
5193 pActors[v20].pMonsterInfo.uExp = 0;
5194 pActors[v20].uMovementSpeed = pMonsterList->pMonsters[v23].uMovementSpeed;
5195 v10 = rand() % 2048;
5196 pActors[v20].vInitialPosition.x = pParty->vPosition.x + fixpoint_mul(stru_5C6E00->Cos(v10), v19);
5197 pActors[v20].vPosition.x = pActors[v20].vInitialPosition.x;
5198 pActors[v20].vInitialPosition.y = pParty->vPosition.y + fixpoint_mul(stru_5C6E00->Sin(v10), v19);
5199 pActors[v20].vPosition.y = pActors[v20].vInitialPosition.y;
5200 pActors[v20].vInitialPosition.z = pParty->vPosition.z;
5201 pActors[v20].vPosition.z = pActors[v20].vInitialPosition.z;
5202 pActors[v20].uTetherDistance = 256;
5203 pActors[v20].uSectorID = v21;
5204 pActors[v20].PrepareSprites(0);
5205 pActors[v20].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
5206 pActors[v20].uAlly = 9999;
5207 pActors[v20].uGroup = 0;
5208 pActors[v20].uCurrentActionTime = 0;
5209 pActors[v20].uAIState = Summoned;
5210 pActors[v20].uCurrentActionLength = 256;
5211 pActors[v20].UpdateAnimation();
5212
5213 result = pIndoor->GetSector(pActors[v20].vPosition.x, pActors[v20].vPosition.y, pActors[v20].vPosition.z);
5214 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor
5215 || result == v21
5216 && (result = BLV_GetFloorLevel(pActors[v20].vPosition.x, pActors[v20].vPosition.y, pActors[v20].vPosition.z, result, &uFaceID), result != -30000)
5217 && (result = abs(result - pParty->vPosition.z), result <= 1024) )
5218 {
5219 if ( v20 == uNumActors )
5220 ++uNumActors;
5221 pActors[v20].uSummonerID = PID(OBJECT_Player, a1);
5222 result = pActors[v20].pActorBuffs[ACTOR_BUFF_SUMMONED].Apply(pParty->uTimePlayed + (a3 * 128) / 30.0f, a2, a1, 0, 0);
5223 }
5224 }
5225 return result;
5226 }
5227
5228 //----- (0044F57C) --------------------------------------------------------
5229 void SpawnEncounter(MapInfo *pMapInfo, SpawnPointMM7 *spawn, int a3, int a4, int a5)
5230 {
5231 int v7; // eax@2
5232 char v8; // zf@5
5233 int v12; // edx@9
5234 int v18; // esi@31
5235 Actor *pMonster; // esi@35
5236 int v23; // edx@36
5237 signed int v24; // edi@36
5238 int v25; // ecx@36
5239 MonsterDesc *v27; // edi@48
5240 signed int v28; // eax@48
5241 int v32; // eax@50
5242 int v37; // eax@51
5243 int v38; // eax@52
5244 int v39; // edi@52
5245 std::string v40; // [sp-18h] [bp-100h]@60
5246 const char *v44; // [sp-8h] [bp-F0h]@13
5247 char *pTexture; // [sp-4h] [bp-ECh]@9
5248 char Str[32]; // [sp+Ch] [bp-DCh]@60
5249 char Str2[120]; // [sp+2Ch] [bp-BCh]@29
5250 unsigned int uFaceID; // [sp+A4h] [bp-44h]@52
5251 MonsterInfo *Src; // [sp+A8h] [bp-40h]@50
5252 int v50; // [sp+ACh] [bp-3Ch]@47
5253 char Source[32]; // [sp+B0h] [bp-38h]@20
5254 int v52; // [sp+D0h] [bp-18h]@34
5255 int v53; // [sp+D4h] [bp-14h]@34
5256 int pSector; // [sp+D8h] [bp-10h]@32
5257 int pPosX; // [sp+DCh] [bp-Ch]@32
5258 int v56; // [sp+E0h] [bp-8h]@8
5259 int v57; // [sp+E4h] [bp-4h]@1
5260
5261 //auto a2 = spawn;
5262 v57 = 0;
5263 //v5 = pMapInfo;
5264 //v6 = spawn;
5265 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
5266 v7 = pOutdoor->ddm.field_C_alert;
5267 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
5268 v7 = pIndoor->dlv.field_C_alert;
5269 else
5270 v7 = 0;
5271 if (v7)
5272 v8 = (spawn->uAttributes & 1) == 0;
5273 else
5274 v8 = (spawn->uAttributes & 1) == 1;
5275 if (v8)
5276 return;
5277 //result = (void *)(spawn->uIndex - 1);
5278 v56 = 1;
5279 switch (spawn->uIndex - 1)
5280 {
5281 case 0:
5282 //v9 = pMapInfo->uEncounterMonster1AtLeast;
5283 //v10 = rand();
5284 //v11 = pMapInfo->uEncounterMonster1AtMost;
5285 //pTexture = pMapInfo->pEncounterMonster1Texture;
5286 v12 = rand() % (pMapInfo->uEncounterMonster1AtMost - pMapInfo->uEncounterMonster1AtLeast + 1);
5287 //v13 = pMapInfo->Dif_M1;
5288 v57 = pMapInfo->Dif_M1;
5289 v56 = pMapInfo->uEncounterMonster1AtLeast + v12;
5290 strcpy(Source, pMapInfo->pEncounterMonster1Texture);
5291 break;
5292 case 3:
5293 //pTexture = pMapInfo->pEncounterMonster1Texture;
5294 //v44 = "%s A";
5295 sprintf(Source, "%s A", pMapInfo->pEncounterMonster1Texture);
5296 break;
5297 case 4:
5298 //pTexture = pMapInfo->pEncounterMonster2Texture;
5299 //v44 = "%s A";
5300 sprintf(Source, "%s A", pMapInfo->pEncounterMonster2Texture);
5301 break;
5302 case 5:
5303 //pTexture = pMapInfo->pEncounterMonster3Texture;
5304 //v44 = "%s A";
5305 sprintf(Source, "%s A", pMapInfo->pEncounterMonster3Texture);
5306 break;
5307 case 1:
5308 //v9 = pMapInfo->uEncounterMonster2AtLeast;
5309 //v14 = rand();
5310 //v15 = pMapInfo->uEncounterMonster2AtMost;
5311 //pTexture = pMapInfo->pEncounterMonster2Texture;
5312 v12 = rand() % (pMapInfo->uEncounterMonster2AtMost - pMapInfo->uEncounterMonster2AtLeast + 1);
5313 //v13 = pMapInfo->Dif_M2;
5314 v57 = pMapInfo->Dif_M2;
5315 v56 = pMapInfo->uEncounterMonster2AtLeast + v12;
5316 strcpy(Source, pMapInfo->pEncounterMonster2Texture);
5317 break;
5318 case 6:
5319 //pTexture = pMapInfo->pEncounterMonster1Texture;
5320 //v44 = "%s B";
5321 sprintf(Source, "%s B", pMapInfo->pEncounterMonster1Texture);
5322 break;
5323 case 7:
5324 //pTexture = pMapInfo->pEncounterMonster2Texture;
5325 //v44 = "%s B";
5326 sprintf(Source, "%s B", pMapInfo->pEncounterMonster2Texture);
5327 break;
5328 case 8:
5329 //pTexture = pMapInfo->pEncounterMonster3Texture;
5330 //v44 = "%s B";
5331 sprintf(Source, "%s B", pMapInfo->pEncounterMonster3Texture);
5332 break;
5333 case 2:
5334 //v9 = pMapInfo->uEncounterMonster3AtLeast;
5335 //v16 = rand();
5336 //v17 = pMapInfo->uEncounterMonster3AtMost;
5337 //pTexture = pMapInfo->pEncounterMonster3Texture;
5338 v12 = rand() % (pMapInfo->uEncounterMonster3AtMost - pMapInfo->uEncounterMonster3AtLeast + 1);
5339 //v13 = pMapInfo->Dif_M3;
5340 v57 = pMapInfo->Dif_M3;
5341 v56 = pMapInfo->uEncounterMonster3AtLeast + v12;
5342 strcpy(Source, pMapInfo->pEncounterMonster3Texture);
5343 break;
5344 case 9:
5345 //pTexture = pMapInfo->pEncounterMonster1Texture;
5346 //v44 = "%s C";
5347 sprintf(Source, "%s C", pMapInfo->pEncounterMonster1Texture);
5348 break;
5349 case 10:
5350 //pTexture = pMapInfo->pEncounterMonster2Texture;
5351 //v44 = "%s C";
5352 sprintf(Source, "%s C", pMapInfo->pEncounterMonster2Texture);
5353 break;
5354 case 11:
5355 //pTexture = pMapInfo->pEncounterMonster3Texture;
5356 //v44 = "%s C";
5357 sprintf(Source, "%s C", pMapInfo->pEncounterMonster3Texture);
5358 break;
5359 default:
5360 return;
5361 }
5362 if (Source[0] == '0')
5363 return;
5364 v57 += a3;
5365 if ( v57 > 4 )
5366 v57 = 4;
5367 strcpy(Str2, Source);
5368 if ( a4 )
5369 v56 = a4;
5370 v18 = v56;
5371 if ( (signed int)(v56 + uNumActors) >= 500 )
5372 return;
5373 pSector = 0;
5374 pPosX = spawn->vPosition.x;
5375 a4 = spawn->vPosition.y;
5376 a3 = spawn->vPosition.z;
5377 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
5378 pSector = pIndoor->GetSector(spawn->vPosition.x, spawn->vPosition.y, spawn->vPosition.z);
5379 v53 = 0;
5380 v52 = (((uCurrentlyLoadedLevelType != LEVEL_Outdoor) - 1) & 0x40) + 64;
5381 if ( v18 <= 0 )
5382 return;
5383 for (uint i = v53; i < v56; ++i)
5384 {
5385 pMonster = &pActors[uNumActors];
5386 pActors[uNumActors].Reset();
5387 if ( v57 )
5388 {
5389 v23 = rand() % 100;
5390 v24 = 3;
5391 v25 = (unsigned __int16)word_4E8152[3 * v57];
5392 if ( v23 >= v25 )
5393 {
5394 if ( v23 < v25 + (unsigned __int16)word_4E8152[3 * v57 + 1] )
5395 v24 = 2;
5396 }
5397 else
5398 v24 = 1;
5399 if ( v24 == 1 )
5400 {
5401 pTexture = Source;
5402 v44 = "%s A";
5403 }
5404 else
5405 {
5406 if ( v24 == 2 )
5407 {
5408 pTexture = Source;
5409 v44 = "%s B";
5410 }
5411 else
5412 {
5413 if ( v24 != 3 )
5414 continue;
5415 pTexture = Source;
5416 v44 = "%s C";
5417 }
5418 }
5419 sprintf(Str2, v44, pTexture);
5420 }
5421 v50 = pMonsterList->GetMonsterIDByName(Str2);
5422 pTexture = Str2;
5423 if ( (signed __int16)v50 == -1 )
5424 {
5425 sprintf(Str, "Can't create random monster: '%s'! See MapStats.txt and Monsters.txt!", pTexture);
5426 MessageBoxA(nullptr, Str, nullptr, 0);
5427 ExitProcess(0);
5428 }
5429 v27 = &pMonsterList->pMonsters[(signed __int16)v50];
5430 v28 = pMonsterStats->FindMonsterByTextureName(pTexture);
5431 if ( !v28 )
5432 v28 = 1;
5433 Src = &pMonsterStats->pInfos[v28];
5434 strcpy(pMonster->pActorName, Src->pName);
5435 pMonster->sCurrentHP = Src->uHP;
5436 assert(sizeof(MonsterInfo) == 88);
5437 memcpy(&pMonster->pMonsterInfo, Src, sizeof(MonsterInfo));//Uninitialized portail memory access
5438 pMonster->word_000086_some_monster_id = v50 + 1;
5439 pMonster->uActorRadius = v27->uMonsterRadius;
5440 pMonster->uActorHeight = v27->uMonsterHeight;
5441 pMonster->uMovementSpeed = v27->uMovementSpeed;
5442 pMonster->vInitialPosition.x = spawn->vPosition.x;
5443 pMonster->vPosition.x = spawn->vPosition.x;
5444 pMonster->uTetherDistance = 256;
5445 pMonster->vInitialPosition.y = a4;
5446 pMonster->vPosition.y = a4;
5447 pMonster->vInitialPosition.z = a3;
5448 pMonster->vPosition.z = a3;
5449 pMonster->uSectorID = pSector;
5450 pMonster->uGroup = spawn->uGroup;
5451 pMonster->PrepareSprites(0);
5452 pMonster->pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
5453 v32 = rand();
5454 a3 = fixpoint_mul(stru_5C6E00->Cos(v32 % 2048), v52);
5455 pPosX = a3 + spawn->vPosition.x;
5456 a3 = fixpoint_mul(stru_5C6E00->Sin(v32 % 2048), v52);
5457 a4 = a3 + spawn->vPosition.y;
5458 a3 = spawn->vPosition.z;
5459 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
5460 {
5461 if ( a5 )
5462 pMonster->uAttributes |= ACTOR_AGGRESSOR;
5463 ++uNumActors;
5464 continue;
5465 }
5466 v37 = pIndoor->GetSector(pPosX, a4, spawn->vPosition.z);
5467 if ( v37 == pSector )
5468 {
5469 v38 = BLV_GetFloorLevel(pPosX, a4, a3, v37, &uFaceID);
5470 v39 = v38;
5471 if ( v38 != -30000 )
5472 {
5473 if ( abs(v38 - a3) <= 1024 )
5474 {
5475 a3 = v39;
5476 if ( a5 )
5477 pMonster->uAttributes |= ACTOR_AGGRESSOR;
5478 ++uNumActors;
5479 continue;
5480 }
5481 }
5482 }
5483 ;
5484 //v53 = (char *)v53 + 1;
5485 //result = v53;
5486 }
5487 //while ( (signed int)v53 < v56 );
5488 }
5489
5490 //----- (00438F8F) --------------------------------------------------------
5491 void area_of_effect__damage_evaluate()
5492 {
5493 int attacker_type; // ecx@3
5494 signed int v3; // eax@3
5495 unsigned int target_id; // edi@6
5496 int target_type; // eax@6
5497 int v10; // edi@8
5498 Vec3_int_ attacker_coord; // ST04_12@9
5499 // int v12; // ST0C_4@10
5500 int v15; // edx@15
5501 int v19; // edi@15
5502 int v23; // edx@18
5503 int v24; // eax@18
5504 // int v30; // eax@29
5505 int v31; // edx@29
5506 int v32; // eax@29
5507 int v33; // ST24_4@29
5508 SpriteObject *v36; // [sp+0h] [bp-28h]@0
5509 int attacker_id; // [sp+10h] [bp-18h]@1
5510 int v44; // [sp+14h] [bp-14h]@15
5511 //Vec3_int_ *pVelocity; // [sp+1Ch] [bp-Ch]@2
5512 signed int a1; // [sp+20h] [bp-8h]@8
5513 int v48; // [sp+24h] [bp-4h]@8
5514
5515
5516 for (attacker_id = 0; attacker_id < AttackerInfo.count; ++attacker_id)
5517 {
5518 attacker_type = PID_TYPE(AttackerInfo.pIDs[attacker_id]);
5519 v3 = PID_ID(AttackerInfo.pIDs[attacker_id]);
5520
5521 if (attacker_type == 2)
5522 {
5523 v36 = &pSpriteObjects[v3];
5524 attacker_type = PID_TYPE(pSpriteObjects[v3].spell_caster_pid);
5525 v3 = PID_ID(pSpriteObjects[v3].spell_caster_pid);
5526 }
5527
5528 if (AttackerInfo.field_3EC[attacker_id] & 1)
5529 {
5530 target_id = PID_ID(ai_near_actors_targets_pid[v3]);
5531 target_type = PID_TYPE(ai_near_actors_targets_pid[v3]) - 3;
5532 if (target_type)
5533 {
5534 if (target_type == 1)//party damage from monsters(повреждения группе от монстров)
5535 {
5536 v10 = pParty->vPosition.y - AttackerInfo.pYs[attacker_id];
5537 a1 = pParty->vPosition.x - AttackerInfo.pXs[attacker_id];
5538 v48 = pParty->vPosition.y - AttackerInfo.pYs[attacker_id];
5539 if (a1 * a1 + v10 * v10
5540 + ((signed int)(pParty->vPosition.z + pParty->uPartyHeight) >> (1 - AttackerInfo.pZs[attacker_id]))
5541 * ((signed int)(pParty->vPosition.z + pParty->uPartyHeight) >> (1 - AttackerInfo.pZs[attacker_id]))
5542 < (unsigned int)((AttackerInfo.field_324[attacker_id] + 32) * (AttackerInfo.field_324[attacker_id] + 32)))
5543 {
5544 attacker_coord.x = AttackerInfo.pXs[attacker_id];
5545 attacker_coord.y = AttackerInfo.pYs[attacker_id];
5546 attacker_coord.z = AttackerInfo.pZs[attacker_id];
5547 if (sub_407A1C(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + pParty->sEyelevel, attacker_coord))
5548 DamagePlayerFromMonster(AttackerInfo.pIDs[attacker_id], AttackerInfo.field_450[attacker_id], &AttackerInfo.vec_4B4[attacker_id], stru_50C198.which_player_to_attack(&pActors[v3]));
5549 }
5550 }
5551 }
5552 else//Actor damage from monsters(повреждение местного жителя)
5553 {
5554 if (SHIDWORD(pActors[target_id].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime) > 0
5555 || SHIDWORD(pActors[target_id].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime) >= 0
5556 && LODWORD(pActors[target_id].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime)
5557 || pActors[target_id].CanAct())
5558 {
5559 v15 = pActors[target_id].vPosition.y - AttackerInfo.pYs[attacker_id];
5560 a1 = pActors[target_id].vPosition.x - AttackerInfo.pXs[attacker_id];
5561 v44 = pActors[target_id].vPosition.z;
5562 v19 = AttackerInfo.field_324[attacker_id] + pActors[target_id].uActorRadius;
5563 v48 = v15;
5564 if (a1 * a1 + v15 * v15 + (pActors[target_id].vPosition.z + (pActors[target_id].uActorHeight >> 1) - AttackerInfo.pZs[attacker_id])
5565 * (pActors[target_id].vPosition.z + (pActors[target_id].uActorHeight >> 1) - AttackerInfo.pZs[attacker_id]) < (unsigned int)(v19 * v19))
5566 {
5567 attacker_coord.x = AttackerInfo.pXs[attacker_id];
5568 attacker_coord.y = AttackerInfo.pYs[attacker_id];
5569 attacker_coord.z = AttackerInfo.pZs[attacker_id];
5570 if (sub_407A1C(pActors[target_id].vPosition.x, pActors[target_id].vPosition.y, pActors[target_id].vPosition.z + 50, attacker_coord))
5571 {
5572 Vec3_int_::Normalize(&a1, &v48, &v44);
5573 AttackerInfo.vec_4B4[attacker_id].x = a1;
5574 AttackerInfo.vec_4B4[attacker_id].y = v48;
5575 AttackerInfo.vec_4B4[attacker_id].z = v44;
5576 Actor::ActorDamageFromMonster(AttackerInfo.pIDs[attacker_id], target_id, &AttackerInfo.vec_4B4[attacker_id], AttackerInfo.field_450[attacker_id]);
5577 }
5578 }
5579 }
5580 }
5581 }
5582 else //damage from spells(повреждения от заклов(метеоритный дождь))
5583 {
5584 v23 = pParty->vPosition.y - AttackerInfo.pYs[attacker_id];
5585 v24 = ((signed int)pParty->uPartyHeight / 2) - AttackerInfo.pZs[attacker_id];
5586 a1 = pParty->vPosition.x - AttackerInfo.pXs[attacker_id];
5587 v48 = pParty->vPosition.y - AttackerInfo.pYs[attacker_id];
5588 if (a1 * a1 + v23 * v23 + (pParty->vPosition.z + v24) * (pParty->vPosition.z + v24) < (unsigned int)((AttackerInfo.field_324[attacker_id] + 32) * (AttackerInfo.field_324[attacker_id] + 32)))
5589 {//party damage (повреждения группе)
5590 attacker_coord.x = AttackerInfo.pXs[attacker_id];
5591 attacker_coord.y = AttackerInfo.pYs[attacker_id];
5592 attacker_coord.z = AttackerInfo.pZs[attacker_id];
5593 if (sub_407A1C(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + pParty->sEyelevel, attacker_coord))
5594 {
5595 for (uint i = 0; i < 4; ++i)
5596 {
5597 if (!(HIDWORD(pParty->pPlayers[i].pConditions[Condition_Dead]) | LODWORD(pParty->pPlayers[i].pConditions[Condition_Dead]))
5598 && !pParty->pPlayers[i].pConditions[Condition_Pertified] && !pParty->pPlayers[i].pConditions[Condition_Eradicated])
5599 DamagePlayerFromMonster(AttackerInfo.pIDs[attacker_id], AttackerInfo.field_450[attacker_id], &AttackerInfo.vec_4B4[attacker_id], i);
5600 }
5601 }
5602 }
5603 if ((signed int)uNumActors > 0)
5604 {//actors damage(повреждения другим участникам)
5605 for (int actorID = 0; (signed int)actorID < (signed int)uNumActors; ++actorID)
5606 {
5607 if (pActors[actorID].CanAct())
5608 {
5609 //v30 = pActors[actorID].vPosition.y - AttackerInfo.pYs[attacker_id];
5610 a1 = pActors[actorID].vPosition.x - AttackerInfo.pXs[attacker_id];
5611 v31 = pActors[actorID].vPosition.z;
5612 v48 = pActors[actorID].vPosition.y - AttackerInfo.pYs[attacker_id];
5613 v44 = pActors[actorID].vPosition.z;
5614 v32 = (pActors[actorID].uActorHeight / 2) - AttackerInfo.pZs[attacker_id];
5615 v33 = pActors[actorID].uActorRadius + AttackerInfo.field_324[attacker_id];
5616 if (a1 * a1 + v48 * v48 + (v31 + v32) * (v31 + v32) < (unsigned int)(v33 * v33))
5617 {
5618 attacker_coord.x = AttackerInfo.pXs[attacker_id];
5619 attacker_coord.y = AttackerInfo.pYs[attacker_id];
5620 attacker_coord.z = AttackerInfo.pZs[attacker_id];
5621 if (sub_407A1C(pActors[actorID].vPosition.x, pActors[actorID].vPosition.y, pActors[actorID].vPosition.z + 50, attacker_coord))//что делает ф-ция?
5622 {
5623 Vec3_int_::Normalize(&a1, &v48, &v44);
5624 AttackerInfo.vec_4B4[attacker_id].x = a1;
5625 AttackerInfo.vec_4B4[attacker_id].y = v48;
5626 AttackerInfo.vec_4B4[attacker_id].z = v44;
5627 switch (attacker_type)
5628 {
5629 case OBJECT_Player:
5630 Actor::DamageMonsterFromParty(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id]);
5631 break;
5632 case OBJECT_Actor:
5633 if (v36 && pActors[v3].GetActorsRelation(&pActors[actorID]))
5634 Actor::ActorDamageFromMonster(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id], v36->field_61);
5635 break;
5636 case OBJECT_Item:
5637 ItemDamageFromActor(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id]);
5638 break;
5639 }
5640 }
5641 }
5642 }
5643 }
5644 }
5645 }
5646 }
5647 AttackerInfo.count = 0;
5648 }
5649
5650 //----- (0043AE12) --------------------------------------------------------
5651 double __fastcall sub_43AE12(signed int a1)
5652 {
5653 //signed int v1; // ST00_4@1
5654 signed int v2; // ecx@1
5655 double v3; // st7@1
5656 double result; // st7@6
5657
5658 v3 = (double)a1;
5659 for (v2 = 0; v2 < 5; ++v2)
5660 {
5661 if (v3 < flt_4E4A80[v2 + 5])
5662 break;
5663 }
5664 if (v2 <= 0 || v2 >= 5)
5665 {
5666 if (v2)
5667 result = flt_4E4A80[4];
5668 else
5669 result = flt_4E4A80[0];
5670 }
5671 else
5672 result = (flt_4E4A80[v2] - flt_4E4A80[v2 - 1]) * (v3 - flt_4E4A80[v2 + 4]) / (flt_4E4A80[v2 + 5] - flt_4E4A80[v2 + 4]) + flt_4E4A80[v2];
5673 return result;
5674 }
5675
5676 //----- (0043B057) --------------------------------------------------------
5677 void ItemDamageFromActor(unsigned int uObjID, unsigned int uActorID, Vec3_int_ *pVelocity)
5678 {
5679 int v6; // eax@4
5680 int damage; // edi@4
5681 int a2a; // [sp+Ch] [bp-4h]@8
5682
5683 if (!pActors[uActorID].IsNotAlive())
5684 {
5685 if (PID_TYPE(uObjID) == OBJECT_Item)
5686 {
5687 if (pSpriteObjects[PID_ID(uObjID)].spell_id)
5688 {
5689 v6 = _43AFE3_calc_spell_damage(pSpriteObjects[PID_ID(uObjID)].spell_id, pSpriteObjects[PID_ID(uObjID)].spell_level, pSpriteObjects[PID_ID(uObjID)].spell_skill, pActors[uActorID].sCurrentHP);
5690 damage = pActors[uActorID].CalcMagicalDamageToActor((DAMAGE_TYPE)0, v6);
5691 pActors[uActorID].sCurrentHP -= damage;
5692 if (damage)
5693 {
5694 if (pActors[uActorID].sCurrentHP > 0)
5695 Actor::AI_Stun(uActorID, uObjID, 0);
5696 else
5697 Actor::Die(uActorID);
5698 a2a = 20 * damage / (signed int)pActors[uActorID].pMonsterInfo.uHP;
5699 if (20 * damage / (signed int)pActors[uActorID].pMonsterInfo.uHP > 10)
5700 a2a = 10;
5701 if (!MonsterStats::BelongsToSupertype(pActors[uActorID].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT))
5702 {
5703 pVelocity->x = fixpoint_mul(a2a, pVelocity->x);
5704 pVelocity->y = fixpoint_mul(a2a, pVelocity->y);
5705 pVelocity->z = fixpoint_mul(a2a, pVelocity->z);
5706 pActors[uActorID].vVelocity.x = 50 * LOWORD(pVelocity->x);
5707 pActors[uActorID].vVelocity.y = 50 * LOWORD(pVelocity->y);
5708 pActors[uActorID].vVelocity.z = 50 * LOWORD(pVelocity->z);
5709 }
5710 Actor::AddBloodsplatOnDamageOverlay(uActorID, 1, damage);
5711 }
5712 else
5713 Actor::AI_Stun(uActorID, uObjID, 0);
5714 }
5715 }
5716 }
5717 }