Mercurial > mm7
annotate TurnEngine.cpp @ 2426:22ac062b40f7
Слияние
author | Ritor1 |
---|---|
date | Wed, 23 Jul 2014 16:06:33 +0600 |
parents | d922225a6081 |
children | 104fdbea0386 |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2245
diff
changeset
|
5 #define _CRT_SECURE_NO_WARNINGS |
1332 | 6 |
2336 | 7 #include "mm7_unsorted_subs.h" |
1332 | 8 #include "MM7.h" |
9 #include "mm7_data.h" | |
10 #include "Actor.h" | |
11 #include "Player.h" | |
12 #include "Party.h" | |
13 #include "AudioPlayer.h" | |
14 #include "SpriteObject.h" | |
2044 | 15 #include "Timer.h" |
1332 | 16 #include "stru298.h" |
17 #include "IconFrameTable.h" | |
18 #include "Viewport.h" | |
19 #include "FactionTable.h" | |
20 | |
21 #include "TurnEngine.h" | |
22 | |
23 | |
24 #include "TurnEngine.h" | |
25 struct stru262_TurnBased *pTurnEngine = new stru262_TurnBased; | |
26 | |
27 | |
28 //----- (00404544) -------------------------------------------------------- | |
29 void stru262_TurnBased::SortTurnQueue() | |
2242 | 30 { |
31 int active_actors; | |
32 TurnBased_QueueElem *current_top; // eax@16 | |
33 TurnBased_QueueElem *test_element; // ecx@18 | |
34 TurnBased_QueueElem temp_elem; | |
35 int i,j; | |
36 unsigned int p_type; | |
37 unsigned int p_id; | |
1332 | 38 |
2242 | 39 active_actors = this->uActorQueueSize; |
40 //set non active actors in queue initiative that not allow them to paticipate | |
41 for( i = 0; i < uActorQueueSize; ++i) | |
42 { | |
43 p_type = PID_TYPE(pQueue[i].uPackedID); | |
44 p_id = PID_ID(pQueue[i].uPackedID); | |
45 | |
46 if ( p_type == OBJECT_Actor ) | |
47 { | |
48 pActors[p_id].uAttributes |= 0x80; | |
49 if ( !pActors[p_id].CanAct() ) | |
50 { | |
51 --active_actors; | |
52 pQueue[i].actor_initiative = 1001; | |
53 pActors[p_id].uAttributes &= ~0x80; | |
54 } | |
55 } | |
56 else if ( p_type == OBJECT_Player) | |
1332 | 57 { |
2242 | 58 if ( !pParty->pPlayers[p_id].CanAct() ) |
59 { | |
60 --active_actors; | |
61 pQueue[i].actor_initiative = 1001; | |
62 } | |
63 } | |
64 } | |
65 //sort | |
66 if (uActorQueueSize > 0) | |
67 { | |
68 for( i = 0; i < uActorQueueSize-1; ++i) | |
69 { | |
70 current_top=&pQueue[i]; | |
71 for ( j = i+1; j < uActorQueueSize; ++j ) | |
72 { | |
73 test_element=&pQueue[j]; | |
74 if ( test_element->actor_initiative < current_top->actor_initiative || // if less initiative -> top | |
75 ((test_element->actor_initiative == current_top->actor_initiative) && | |
76 (((PID_TYPE(test_element->uPackedID) == OBJECT_Player) && (PID_TYPE(current_top->uPackedID) == OBJECT_Actor)) || //player preferable | |
77 ((PID_TYPE(test_element->uPackedID) == PID_TYPE(current_top->uPackedID)) && (PID_ID(test_element->uPackedID) < PID_ID(current_top->uPackedID)))))) //less id preferable | |
78 { //swap | |
79 memcpy(&temp_elem,current_top,sizeof(TurnBased_QueueElem)); | |
80 memcpy(current_top,test_element, sizeof(TurnBased_QueueElem)); | |
81 memcpy(test_element, &temp_elem, sizeof(TurnBased_QueueElem)); | |
1332 | 82 } |
2242 | 83 } |
1332 | 84 } |
2242 | 85 } |
86 uActorQueueSize = active_actors; | |
87 if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) //we have player at queue top | |
88 { | |
89 uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1; | |
90 field_18 |= TE_PLAYER_TURN; | |
91 } | |
92 else | |
93 { | |
94 uActiveCharacter = 0; | |
95 field_18 &= ~TE_PLAYER_TURN; | |
96 } | |
97 for ( i = 0; i < uActorQueueSize; ++i) | |
98 { | |
99 if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) //set recovery times | |
100 pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 0.46875); | |
101 } | |
102 } | |
1332 | 103 //----- (0040471C) -------------------------------------------------------- |
1448 | 104 void stru262_TurnBased::ApplyPlayerAction() |
2242 | 105 { |
106 if ( pParty->bTurnBasedModeOn == 1 ) | |
107 { | |
108 if ( pTurnEngine->turn_stage == TE_ATTACK ) | |
109 _406457(0); | |
110 } | |
111 } | |
1332 | 112 |
113 //----- (004059DB) -------------------------------------------------------- | |
114 void stru262_TurnBased::Start() | |
2242 | 115 { |
116 int v17; // edx@22 | |
117 AIDirection v30; // [sp+Ch] [bp-68h]@10 | |
118 AIDirection v31; // [sp+28h] [bp-4Ch]@10 | |
119 AIDirection a3; // [sp+44h] [bp-30h]@10 | |
120 int activ_players[4]; | |
121 int players_recovery_time[4]; | |
122 int a_players_count; | |
123 int i,j; | |
124 int temp; | |
1342 | 125 |
2242 | 126 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS; |
127 pEventTimer->TrackGameTime(); | |
128 pAudioPlayer->StopChannels(-1, -1); | |
129 pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0); | |
130 //pPlayer = pParty->pPlayers.data(); | |
131 dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength; | |
132 dword_50C994 = 0; | |
1332 | 133 |
2242 | 134 this->turn_initiative = 100; |
135 this->turns_count = 0; | |
136 this->ai_turn_timer = 64; | |
137 this->turn_stage = TE_WAIT; | |
138 this->uActorQueueSize = 0; | |
1332 | 139 |
2242 | 140 for ( uint pl_id = 0; pl_id < 4 ; ++pl_id ) |
141 { | |
142 if ( pParty->pPlayers[pl_id].CanAct() ) | |
143 { | |
144 this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Player,pl_id); | |
145 this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE; | |
146 this->pQueue[this->uActorQueueSize].uActionLength = 0; | |
147 pParty->pTurnBasedPlayerRecoveryTimes[this->uActorQueueSize] = 0; | |
148 ++this->uActorQueueSize; | |
149 } | |
150 } | |
1332 | 151 |
2242 | 152 for ( int i = 0; i < ai_arrays_size ; ++i ) |
153 { | |
154 if (ai_near_actors_ids[i] == 10) | |
155 continue; | |
156 if ( pActors[ai_near_actors_ids[i]].CanAct() ) | |
157 { | |
158 if ( pActors[ai_near_actors_ids[i]].uAttributes & 0x8000 ) | |
159 { | |
160 pActors[ai_near_actors_ids[i]].uAttributes |= 0x80; | |
161 Actor::GetDirectionInfo(PID(OBJECT_Actor,ai_near_actors_ids[i]), ai_near_actors_targets_pid[ai_near_actors_ids[i]], &v31, 0); | |
162 memcpy(&v30, &v31, sizeof(AIDirection)); | |
163 Actor::AI_StandOrBored(ai_near_actors_ids[i], 4, 32, &v30); | |
164 this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[i]); | |
165 this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE; | |
166 this->pQueue[this->uActorQueueSize].uActionLength = 0; | |
167 ++this->uActorQueueSize; | |
168 } | |
169 } | |
170 } | |
1332 | 171 |
2242 | 172 a_players_count = 0; |
173 for ( int k = 0; k < this->uActorQueueSize; ++k ) | |
174 { | |
175 //set initial initiative for turn actors | |
176 if ( PID_TYPE(this->pQueue[k].uPackedID) == OBJECT_Player ) | |
177 { | |
178 if ( pPlayers[PID_ID(this->pQueue[k].uPackedID) + 1]->uTimeToRecovery != 0 ) | |
179 this->pQueue[k].actor_initiative = (signed int)((double)pPlayers[PID_ID(this->pQueue[k].uPackedID) + 1]->uTimeToRecovery * 0.46875); | |
180 else | |
181 { | |
182 activ_players[a_players_count] = k; | |
183 ++a_players_count; | |
184 } | |
185 } | |
186 else if ( PID_TYPE(this->pQueue[k].uPackedID) == OBJECT_Actor ) | |
187 { | |
188 v17 = rand() % 99; | |
189 if ( v17 < 33 ) | |
190 this->pQueue[k].actor_initiative = 1; | |
191 else | |
192 this->pQueue[k].actor_initiative= (v17 >= 66)? 5 : 3; | |
193 } | |
194 else //fot non player and actor | |
195 this->pQueue[k].actor_initiative = 666; | |
196 this->pQueue[k].actor_initiative += 16; | |
197 } | |
198 | |
199 if ( a_players_count > 0 ) | |
200 { | |
201 for ( i = 0; i < a_players_count; ++i) | |
202 players_recovery_time[i] = pParty->pPlayers[PID_ID(this->pQueue[activ_players[i]].uPackedID)].GetAttackRecoveryTime(0); | |
203 //sort players by recovery time | |
204 for ( i = 0; i < a_players_count-1; ++i) | |
205 { | |
206 for ( j = i + 1; j < a_players_count; ++j ) | |
207 { | |
208 if (players_recovery_time[j] < players_recovery_time[i]) //swap values | |
209 { | |
210 temp = players_recovery_time[i]; | |
211 players_recovery_time[i] = players_recovery_time[j]; | |
212 players_recovery_time[j] = temp; | |
213 temp = activ_players[i]; | |
214 activ_players[i] = activ_players[j]; | |
215 activ_players[j] = temp; | |
1332 | 216 } |
2242 | 217 } |
1332 | 218 } |
2242 | 219 for ( i = 0; i < a_players_count; ++i) |
220 this->pQueue[activ_players[i]].actor_initiative = i + 2; | |
221 } | |
222 this->SortTurnQueue(); | |
223 } | |
1332 | 224 |
225 //----- (00405CFF) -------------------------------------------------------- | |
226 void stru262_TurnBased::End(bool bPlaySound) | |
2242 | 227 { |
228 ObjectType objType; // eax@13 | |
229 int objID; // esi@13 | |
230 int i; | |
1332 | 231 |
2242 | 232 this->turn_stage = TE_NONE; |
233 for( i = 0; i < uActorQueueSize; ++i) | |
234 { | |
235 if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor ) | |
236 pActors[PID_ID(pQueue[i].uPackedID)].uAttributes &= ~0x80; | |
237 } | |
1332 | 238 |
2425 | 239 for( uint i = 0; i < uNumSpriteObjects; ++i) |
2242 | 240 { |
241 if (pSpriteObjects[i].uAttributes & 4) | |
242 pSpriteObjects[i].uAttributes &= ~0x04; | |
243 } | |
1332 | 244 |
2242 | 245 for( i = 0; i < uActorQueueSize; ++i) |
246 { | |
247 objType = (ObjectType)PID_TYPE(pQueue[i].uPackedID); | |
248 objID = PID_ID(pQueue[i].uPackedID); | |
249 if ( objType == OBJECT_Player ) | |
250 pPlayers[objID + 1]->uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333); | |
251 else if ( objType == OBJECT_Actor ) | |
252 pActors[objID].pMonsterInfo.uRecoveryTime = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333); | |
253 } | |
254 pAudioPlayer->StopChannels(-1, -1); | |
255 if ( bPlaySound != 0 ) | |
256 pAudioPlayer->PlaySound(SOUND_206, 0, 0, -1, 0, 0, 0, 0); | |
257 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS; | |
258 pEventTimer->StopGameTime(); | |
259 dword_50C994 = 0; | |
260 dword_50C998_turnbased_icon_1A = 0; | |
261 } | |
1332 | 262 // 50C994: using guessed type int dword_50C994; |
263 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A; | |
264 | |
265 //----- (00405E14) -------------------------------------------------------- | |
1448 | 266 void stru262_TurnBased::AITurnBasedAction() |
2242 | 267 { |
268 AIDirection v6; // esi@21 | |
269 AIDirection a3; // [sp+4h] [bp-68h]@21 | |
270 AIDirection v14; // [sp+20h] [bp-4Ch]@21 | |
271 AIDirection v15; // [sp+3Ch] [bp-30h]@21 | |
272 Actor *curr_actor; // [sp+58h] [bp-14h]@2 | |
273 int target_pid; // [sp+5Ch] [bp-10h]@6 | |
274 int shrinked; | |
2425 | 275 int j; |
2242 | 276 |
2425 | 277 for (uint i = 0; i < uNumActors; ++i ) |
2242 | 278 { |
279 curr_actor=&pActors[i]; | |
280 shrinked=pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0; | |
281 for (j = 0; j < 22; ++j) //check expired spell Buffs | |
1332 | 282 { |
2242 | 283 if (j != 10) |
284 pActors[i].pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed); | |
285 } | |
286 if (shrinked && pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0) //buff 3 expired | |
287 pActors[i].uActorHeight = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].uMonsterHeight; | |
288 if (!(curr_actor->uAttributes & 0x80) && (!curr_actor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) && | |
289 (!curr_actor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime)) | |
290 { | |
291 curr_actor->uCurrentActionTime += pMiscTimer->uTimeElapsed; | |
292 if (curr_actor->uCurrentActionTime>=curr_actor->uCurrentActionLength) | |
293 { | |
294 target_pid = ai_near_actors_targets_pid[i]; | |
295 Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &v6, 0); | |
296 memcpy(&v15, &v6, sizeof(AIDirection)); | |
297 memcpy(&v14, &v15, sizeof(AIDirection)); | |
298 if ( curr_actor->uAIState == Dying ) | |
1332 | 299 { |
2242 | 300 curr_actor->uCurrentActionTime = 0; |
301 curr_actor->uCurrentActionLength = 0; | |
302 curr_actor->uAIState = Dead; | |
303 curr_actor->UpdateAnimation(); | |
1340 | 304 } |
2425 | 305 else if ( (curr_actor->uAIState > Removed) && (curr_actor->uAIState < Disabled)) |
2242 | 306 Actor::AI_StandOrBored(i, target_pid, 32, &v14); |
307 } | |
308 } | |
309 } | |
310 if ( turn_stage == TE_WAIT ) | |
311 { | |
312 if ( ai_turn_timer == 64 ) | |
313 ActorAISetMovementDecision(); | |
314 else if ( ai_turn_timer > 0 ) | |
315 ActorAIDoAdditionalMove(); | |
316 else | |
317 { | |
318 ActorAIStopMovement(); | |
319 turn_initiative = 100; | |
1332 | 320 } |
2242 | 321 ai_turn_timer -= pEventTimer->uTimeElapsed; |
322 } | |
323 else if ( turn_stage == TE_ATTACK ) | |
324 { | |
325 if ( !(field_18 &TE_FLAG_1)) | |
326 { | |
327 if ( turn_initiative == 100 ) | |
328 { | |
329 StartTurn(); | |
330 SetAIRecoveryTimes(); | |
331 return; | |
332 } | |
333 if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 ) | |
334 { | |
335 _4065B0(); | |
336 SetAIRecoveryTimes(); | |
337 return; | |
338 } | |
339 } | |
340 NextTurn(); | |
341 } | |
342 else if ( turn_stage == TE_MOVEMENT ) | |
343 { | |
344 if ( (uActionPointsLeft > 0) && (!(field_18 & TE_FLAG_8)) ) | |
345 ActorAIChooseNewTargets(); | |
346 else | |
347 { | |
348 field_18 &= ~TE_FLAG_8; | |
349 turn_stage = TE_WAIT; | |
350 ai_turn_timer = 64; | |
351 } | |
352 } | |
353 } | |
1332 | 354 |
355 | |
356 //----- (00406051) -------------------------------------------------------- | |
2242 | 357 void stru262_TurnBased::StartTurn() |
358 { | |
359 int player_num, actor_num, i, j; | |
1332 | 360 |
2242 | 361 pending_actions = 0; |
362 //add player to queue if he can act | |
363 for ( player_num = 0; player_num < 4; ++player_num) | |
364 { | |
365 for ( j = 0; j < uActorQueueSize; ++j ) | |
366 { | |
367 if (PID_TYPE(pQueue[j].uPackedID) == OBJECT_Player) | |
368 { | |
369 if (pPlayers[PID_ID(pQueue[j].uPackedID) + 1]->CanAct() && (player_num != PID_ID(pQueue[j].uPackedID)) ) | |
370 break; | |
371 } | |
372 } | |
373 if ( j == uActorQueueSize ) | |
374 { | |
375 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num); | |
376 pQueue[uActorQueueSize].actor_initiative = 100; | |
377 pQueue[uActorQueueSize].uActionLength = 0; | |
378 pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND; | |
379 ++uActorQueueSize; | |
1332 | 380 } |
2242 | 381 } |
382 //add new arrived actors | |
383 for ( actor_num = 0; actor_num < ai_arrays_size; ++actor_num ) | |
384 { | |
385 for ( j = 0; j < uActorQueueSize; ++j ) | |
386 { | |
387 if ((PID_TYPE(pQueue[j].uPackedID)== OBJECT_Actor)&& | |
388 ai_near_actors_ids[actor_num] == PID_ID(pQueue[j].uPackedID)) | |
389 break; | |
390 } | |
391 if ( j == uActorQueueSize ) | |
392 { | |
393 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]); | |
394 pQueue[uActorQueueSize].actor_initiative = 1; | |
395 pQueue[uActorQueueSize].uActionLength = 0; | |
396 pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND; | |
397 ++uActorQueueSize; | |
398 } | |
399 } | |
400 ++turns_count; | |
401 turn_initiative = 100; | |
402 for ( i = 0; i < uActorQueueSize; ++i ) | |
403 { | |
404 if (pQueue[i].actor_initiative == 0 ) | |
405 pQueue[i].actor_initiative = 100; | |
406 } | |
407 StepTurnQueue(); | |
408 for ( i = 0; i < uActorQueueSize; ++i ) | |
409 { | |
410 if ((PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) || (pQueue[i].actor_initiative > 0)) | |
411 break; | |
412 AI_Action_(i); | |
413 } | |
414 } | |
1332 | 415 // 4F75D8: using guessed type int ai_arrays_size; |
416 | |
1341 | 417 //----- (004061CA) -------------------------------------------------------- |
418 void stru262_TurnBased::NextTurn() | |
2242 | 419 { |
420 int v13; // [sp+10h] [bp-4h]@7 | |
421 int monster_id; // eax@5 | |
1341 | 422 |
2242 | 423 SortTurnQueue(); |
424 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) | |
425 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; | |
426 else | |
427 uActiveCharacter = 0; | |
428 viewparams->bRedrawGameUI = true; | |
1341 | 429 |
2242 | 430 if ( pending_actions ) |
431 { | |
432 pTurnEngine->field_18 |= TE_HAVE_PENDING_ACTIONS; | |
433 return; | |
434 } | |
435 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS; | |
436 if ( pQueue[0].actor_initiative <= 0 ) | |
437 return; | |
1332 | 438 |
2242 | 439 v13 = 0; |
440 if (uActorQueueSize > 0 ) | |
441 { | |
442 for ( int i = 0; i < uActorQueueSize; ++i ) | |
443 { | |
444 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) | |
445 { | |
446 monster_id = PID_ID(pQueue[i].uPackedID); | |
2425 | 447 if ( (pActors[monster_id].uAIState == Dying) || (pActors[monster_id].uAIState == Stunned) |
448 || (pActors[monster_id].uAIState == AttackingMelee) || (pActors[monster_id].uAIState == AttackingRanged1) | |
449 || (pActors[monster_id].uAIState == AttackingRanged2) || (pActors[monster_id].uAIState == AttackingRanged3) | |
450 || (pActors[monster_id].uAIState == AttackingRanged4) || (pActors[monster_id].uAIState == Summoned)) | |
2242 | 451 { |
452 pActors[monster_id].uCurrentActionTime += pEventTimer->uTimeElapsed; | |
453 if ( pActors[monster_id].uCurrentActionTime < pActors[monster_id].uCurrentActionLength ) | |
454 v13 = 1; | |
2425 | 455 else if ( pActors[monster_id].uAIState == Dying )// Dying |
2242 | 456 { |
2425 | 457 pActors[monster_id].uAIState = Dead; |
2242 | 458 pActors[monster_id].uCurrentActionTime = 0; |
459 pActors[monster_id].uCurrentActionLength = 0; | |
460 pActors[monster_id].UpdateAnimation(); | |
461 } | |
462 else | |
463 { | |
2425 | 464 if ( pActors[monster_id].uAIState == Stunned ) //Stunned |
2242 | 465 Actor::AI_StandOrBored(monster_id, ai_near_actors_targets_pid[monster_id], 32, 0); |
466 } | |
467 } | |
468 } | |
469 } | |
470 if ( v13 != 0 ) | |
471 { | |
472 field_18 |= TE_FLAG_1; | |
473 return; | |
474 } | |
475 } | |
1332 | 476 |
2242 | 477 field_18 &= ~TE_FLAG_1; |
478 //set all actors to stay | |
479 for ( int i = 0; i < uActorQueueSize; ++i ) | |
480 { | |
481 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) | |
482 { | |
483 monster_id = PID_ID(pQueue[i].uPackedID); | |
2425 | 484 if ((pActors[monster_id].uAIState != Dead) && (pActors[monster_id].uAIState != Dying) && |
485 (pActors[monster_id].uAIState != Removed) && (pActors[monster_id].uAIState != Summoned) && | |
486 (pActors[monster_id].uAIState != Disabled)) | |
2242 | 487 { |
488 pQueue[i].uActionLength = 0; | |
489 Actor::AI_StandOrBored(monster_id, ai_near_actors_targets_pid[monster_id], 32, nullptr); | |
490 } | |
491 } | |
492 } | |
493 // turn tick | |
494 turn_stage = TE_MOVEMENT; | |
495 pParty->uTimePlayed += 213i64; | |
496 _494035_timed_effects__water_walking_damage__etc(); | |
497 uActionPointsLeft = 130; | |
498 } | |
1332 | 499 |
2242 | 500 //----- (004063A1) -------------------------------------------------------- |
501 bool stru262_TurnBased::StepTurnQueue() | |
502 { | |
503 int v9; // dx@12 | |
504 int j; | |
1332 | 505 |
2242 | 506 SortTurnQueue(); |
507 viewparams->bRedrawGameUI = 1; | |
508 if ( pQueue[0].actor_initiative != 0 ) | |
509 { | |
510 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) | |
511 { | |
512 do | |
513 { | |
514 for (j = 0; j < uActorQueueSize; ++j ) | |
515 --pQueue[j].actor_initiative; | |
516 --turn_initiative; | |
517 if (turn_initiative == 0) | |
518 return true; | |
519 } | |
520 while (pQueue[0].actor_initiative != 0); | |
521 } | |
522 else | |
523 { | |
524 if ( pQueue[0].actor_initiative > 0 ) | |
525 { | |
526 v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState; | |
2425 | 527 if (!(v9 == Dying || v9 == Dead || |
528 v9 == Disabled || v9 == Removed)) | |
2242 | 529 { |
530 do | |
531 { | |
532 for ( j = 0; j < uActorQueueSize; ++j ) | |
533 { | |
534 --pQueue[j].actor_initiative; | |
535 if (pQueue[j].actor_initiative == 0) | |
536 pQueue[j].uActionLength = 0; | |
537 } | |
538 --turn_initiative; | |
539 if (turn_initiative == 0) | |
540 return true; | |
541 } | |
542 while (pQueue[0].actor_initiative > 0); | |
543 } | |
544 } | |
545 } | |
546 } | |
547 return false; | |
548 } | |
1332 | 549 |
550 //----- (00406457) -------------------------------------------------------- | |
1340 | 551 void stru262_TurnBased::_406457( int a2 ) |
2242 | 552 { |
553 signed int v4; // ecx@2 | |
554 signed int v6; // eax@2 | |
555 int i; | |
556 v6 = 0; | |
557 if ( PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player) | |
558 { | |
559 v4 = PID_ID(pQueue[a2].uPackedID); | |
560 if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] ) | |
561 pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0; | |
1332 | 562 else |
2242 | 563 v6 = pPlayers[v4 + 1]->GetAttackRecoveryTime(0); |
564 if ( v6 < 30 ) | |
565 v6 = 30; | |
566 } | |
567 else | |
568 v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime; | |
1340 | 569 |
2242 | 570 pQueue[a2].actor_initiative = v6; |
571 SortTurnQueue(); | |
572 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) | |
573 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; | |
574 else | |
575 uActiveCharacter = 0; | |
576 viewparams->bRedrawGameUI = 1; | |
577 while ( (pQueue[0].actor_initiative > 0) && (turn_initiative > 0) ) | |
578 { | |
579 for ( i = 0; i < uActorQueueSize; ++i) | |
580 { | |
581 --pQueue[i].actor_initiative; | |
582 if (pQueue[i].actor_initiative == 0) | |
583 pQueue[i].uActionLength=0; | |
1332 | 584 } |
2242 | 585 --turn_initiative; |
586 } | |
587 } | |
1332 | 588 |
589 //----- (0040652A) -------------------------------------------------------- | |
1448 | 590 void stru262_TurnBased::SetAIRecoveryTimes() |
2242 | 591 { |
592 int i; | |
593 int monster_ai_state; | |
594 Actor *monster; // eax@5 | |
1332 | 595 |
2242 | 596 for ( i = 0; i < uActorQueueSize; ++i ) |
597 { | |
598 if (pQueue[i].actor_initiative == 0) | |
599 { | |
600 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) | |
601 break; | |
602 monster=&pActors[PID_ID(pQueue[i].uPackedID)]; | |
603 monster_ai_state=monster->uAIState; | |
2425 | 604 if (monster_ai_state == Standing || |
605 monster_ai_state == Fleeing || | |
606 monster_ai_state == Fidgeting) | |
2242 | 607 { |
608 pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime; | |
609 if (monster->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0) | |
610 pQueue[i].actor_initiative*=2; | |
611 } | |
1340 | 612 } |
2242 | 613 } |
614 } | |
1332 | 615 |
616 //----- (004065B0) -------------------------------------------------------- | |
617 void stru262_TurnBased::_4065B0() | |
1333 | 618 { |
2242 | 619 int i; |
1332 | 620 |
2242 | 621 SortTurnQueue(); |
622 if (pQueue[0].actor_initiative <= 0) | |
623 { | |
624 for ( i = 0; i < uActorQueueSize; ++i ) | |
625 { | |
626 if ((PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)|| (pQueue[i].actor_initiative > 0) ) | |
627 break; | |
628 if ((pQueue[i].uActionLength <= 0) && (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)) | |
629 AI_Action_(i); | |
630 } | |
631 } | |
632 else | |
633 { | |
634 StepTurnQueue(); | |
635 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) | |
636 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1; | |
1333 | 637 else |
2242 | 638 uActiveCharacter = 0; |
639 viewparams->bRedrawGameUI = 1; | |
640 } | |
641 for ( i = 0; i < uActorQueueSize; ++i ) | |
642 AIAttacks(i); | |
1333 | 643 } |
1332 | 644 |
645 //----- (00406648) -------------------------------------------------------- | |
1448 | 646 void stru262_TurnBased::AIAttacks( unsigned int queue_index ) |
1546 | 647 { |
2242 | 648 //TurnBased_QueueElem *v1; // ecx@1 |
649 //int v3; // eax@1 | |
650 unsigned int actor_id; // ebx@2 | |
651 //Actor *v5; // esi@2 | |
652 char v19; // al@24 | |
653 AIDirection a3; // [sp+Ch] [bp-3Ch]@2 | |
654 AIDirection a4; // [sp+28h] [bp-20h]@2 | |
655 //TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1 | |
656 //unsigned int a2a; // [sp+50h] [bp+8h]@2 | |
1332 | 657 |
2242 | 658 //v1 = &pQueue[queue_index]; |
659 //v28 = v1; | |
660 //v3 = pQueue[queue_index].uPackedID; | |
661 if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor) | |
662 { | |
663 actor_id = PID_ID(pQueue[queue_index].uPackedID); | |
664 //a2a = ai_near_actors_targets_pid[v4]; | |
665 Actor::GetDirectionInfo(pQueue[queue_index].uPackedID, ai_near_actors_targets_pid[actor_id], &a3, 0); | |
666 memcpy(&a4, &a3, sizeof(a4)); | |
667 //v5 = &pActors[v4]; | |
668 //LOWORD(v3) = v5->uAIState; | |
2425 | 669 if (( pActors[actor_id].uAIState != Dead ) && ( pActors[actor_id].uAIState != Disabled ) |
670 &&( pActors[actor_id].uAIState != Removed )) | |
2242 | 671 { |
672 pActors[actor_id].uCurrentActionTime += pEventTimer->uTimeElapsed; | |
673 if ( (signed int)pActors[actor_id].uCurrentActionTime >= pActors[actor_id].uCurrentActionLength ) | |
674 { | |
675 switch (pActors[actor_id].uAIState) | |
1332 | 676 { |
2425 | 677 case AttackingMelee: |
2242 | 678 v19 = pActors[actor_id].special_ability_use_check(actor_id); |
679 AttackerInfo.Add( pQueue[queue_index].uPackedID, 5120, pActors[actor_id].vPosition.x, pActors[actor_id].vPosition.y, | |
680 pActors[actor_id].vPosition.z + ((signed int)pActors[actor_id].uActorHeight >> 1), v19, 1); | |
681 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4); | |
682 break; | |
2425 | 683 case AttackingRanged1: |
2242 | 684 Actor::AI_RangedAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uMissleAttack1Type, 0); |
685 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4); | |
686 break; | |
2425 | 687 case Dying: |
2242 | 688 pActors[actor_id].uCurrentActionTime = 0; |
689 pActors[actor_id].uCurrentActionLength = 0; | |
690 pActors[actor_id].uAIState = Dead; | |
691 pActors[actor_id].UpdateAnimation(); | |
692 break; | |
2425 | 693 case Stunned: |
2242 | 694 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4); |
695 break; | |
2425 | 696 case AttackingRanged2: |
2242 | 697 Actor::AI_RangedAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uMissleAttack2Type, 1); |
698 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4); | |
699 break; | |
2425 | 700 case AttackingRanged3: |
2242 | 701 Actor::AI_SpellAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uSpell1ID, 2, pActors[actor_id].pMonsterInfo.uSpellSkillAndMastery1); |
702 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4); | |
703 break; | |
2425 | 704 case AttackingRanged4: |
2242 | 705 Actor::AI_SpellAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uSpell2ID, 3, pActors[actor_id].pMonsterInfo.uSpellSkillAndMastery2); |
706 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4); | |
707 break; | |
708 default: | |
709 if ( !(rand() % 2) ) | |
710 Actor::AI_Bored(actor_id, ai_near_actors_targets_pid[actor_id], &a4); | |
711 else | |
712 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 64,&a4); | |
1343 | 713 } |
2242 | 714 } |
1332 | 715 } |
2242 | 716 } |
717 } | |
2059 | 718 // 50FE08: using guessed type stru298 AttackerInfo; |
1332 | 719 |
720 //----- (0040680F) -------------------------------------------------------- | |
1450 | 721 void stru262_TurnBased::AI_Action_( int queue_index ) |
2242 | 722 { |
723 unsigned int actor_id; // edi@2 | |
724 AIDirection v7; // esi@10 | |
725 int v9; // ecx@10 | |
726 signed int v10; // eax@13 | |
727 int v14; // eax@29 | |
728 AIDirection a3; // [sp+Ch] [bp-44h]@10 | |
729 AIDirection v18; // [sp+28h] [bp-28h]@10 | |
730 signed int v22; // [sp+58h] [bp+8h]@10 | |
1367 | 731 |
2242 | 732 pQueue[queue_index].uActionLength = 0; |
733 if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor) | |
734 { | |
735 actor_id = PID_ID(pQueue[queue_index].uPackedID); | |
2425 | 736 if (!(pActors[actor_id].uAIState == Dying || pActors[actor_id].uAIState == Dead || pActors[actor_id].uAIState == Summoned || |
737 pActors[actor_id].uAIState == Disabled || pActors[actor_id].uAIState == Removed)) | |
2242 | 738 { |
739 Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true); | |
740 v22 = ai_near_actors_targets_pid[actor_id]; | |
741 if ( pActors[actor_id].pMonsterInfo.uHostilityType && !v22) | |
742 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; | |
743 Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &v7, 0); | |
744 memcpy(&a3, &v7, sizeof(AIDirection)); | |
745 memcpy(&v18, &a3, sizeof(AIDirection)); | |
746 v9 = a3.uDistance - pActors[actor_id].uActorRadius; | |
747 if ( v9 < 0 ) | |
748 v9 = 0; | |
749 if (PID_TYPE(v22) == OBJECT_Actor) | |
750 //v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3); | |
751 v10 = pFactionTable->relations[(pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID) / 3 + 1][(pActors[actor_id].pMonsterInfo.uID - 1) / 3 + 1]; | |
752 else | |
753 v10 = 4; | |
754 switch (v10) | |
755 { | |
756 case 1: | |
757 if ( (double)(signed int)v9 < 307.2 ) | |
758 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
759 break; | |
760 case 2: | |
761 if ( v9 < 1024 ) | |
762 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
763 break; | |
764 case 3: | |
765 if ( v9 < 2560 ) | |
766 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
767 break; | |
768 case 4: | |
769 if ( v9 < 5120 ) | |
770 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
771 break; | |
772 } | |
773 if ( pActors[actor_id].pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 ) | |
774 { | |
775 v14 = pActors[actor_id].special_ability_use_check(actor_id); | |
776 pQueue[queue_index].AI_action_type = TE_AI_STAND; | |
777 switch (v14) | |
778 { | |
779 case 1: | |
780 if ( pActors[actor_id].pMonsterInfo.uMissleAttack2Type ) | |
781 { | |
782 Actor::AI_MissileAttack2(actor_id, v22, &v18); | |
783 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK; | |
1367 | 784 } |
2242 | 785 break; |
786 case 2: | |
787 if ( pActors[actor_id].pMonsterInfo.uSpell1ID ) | |
788 { | |
789 Actor::AI_SpellAttack1(actor_id, v22, &v18); | |
790 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK; | |
791 } | |
792 break; | |
793 case 3: | |
794 if (pActors[actor_id].pMonsterInfo.uSpell2ID) | |
795 { | |
796 Actor::AI_SpellAttack2(actor_id, v22, &v18); | |
797 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK; | |
798 } | |
799 break; | |
800 default: | |
801 if ( pActors[actor_id].pMonsterInfo.uMissleAttack1Type ) | |
802 { | |
803 Actor::AI_MissileAttack1(actor_id, v22, &v18); | |
804 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK; | |
805 } | |
1367 | 806 } |
2244 | 807 //if (!pQueue[queue_index].AI_action_type) |
2242 | 808 if ( (double)v9 < 307.2) |
809 { | |
810 Actor::AI_MeleeAttack(actor_id, v22, &v18); | |
811 pQueue[queue_index].AI_action_type = TE_AI_MELEE_ATTACK; | |
2244 | 812 pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength; |
813 return; | |
2242 | 814 } |
815 else | |
816 { | |
817 Actor::AI_Stand(actor_id, v22, 64, &v18); | |
818 pQueue[queue_index].AI_action_type = TE_AI_STAND; | |
2244 | 819 pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength; |
820 return; | |
2242 | 821 } |
822 } | |
823 else | |
824 { | |
825 Actor::AI_Stand(actor_id, v22, 64, &v18); | |
826 pQueue[queue_index].AI_action_type = TE_AI_STAND; | |
827 } | |
828 pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength; | |
1332 | 829 } |
2242 | 830 } |
831 } | |
1332 | 832 |
833 //----- (00406A63) -------------------------------------------------------- | |
1450 | 834 void stru262_TurnBased::ActorAISetMovementDecision() |
2242 | 835 { |
836 AIDirection a3; // [sp+8h] [bp-44h]@5 | |
837 AIDirection v7; // [sp+24h] [bp-28h]@5 | |
838 unsigned int target_pid; // [sp+40h] [bp-Ch]@5 | |
839 int i; | |
1332 | 840 |
2242 | 841 this->ai_turn_timer = 64; |
842 dword_50C994 = 0; | |
843 uActiveCharacter = 0; | |
844 for ( i = 0; i < uActorQueueSize; ++i ) | |
845 { | |
846 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) | |
847 { | |
848 target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)]; | |
849 Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0); | |
850 if ( !ActorMove(i) ) | |
851 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7); | |
1332 | 852 } |
2242 | 853 } |
854 } | |
1332 | 855 // 50C994: using guessed type int dword_50C994; |
856 | |
857 //----- (00406AFE) -------------------------------------------------------- | |
1450 | 858 void stru262_TurnBased::ActorAIStopMovement() |
2242 | 859 { |
860 AIDirection a3; // [sp+4h] [bp-48h]@5 | |
861 AIDirection v7; // [sp+20h] [bp-2Ch]@5 | |
862 unsigned int target_pid; | |
863 int i; | |
1332 | 864 |
2242 | 865 for ( i = 0; i < uActorQueueSize; ++i ) |
866 { | |
867 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) | |
868 { | |
869 target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)]; | |
870 Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0); | |
871 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7); | |
872 pQueue[i].AI_action_type = TE_AI_STAND; | |
873 pQueue[i].uActionLength = 0; | |
1332 | 874 } |
2242 | 875 } |
876 turn_stage = TE_ATTACK; | |
877 ai_turn_timer = 100; | |
878 } | |
1332 | 879 |
880 //----- (00406B9F) -------------------------------------------------------- | |
1450 | 881 void stru262_TurnBased::ActorAIDoAdditionalMove() |
2242 | 882 { |
883 AIDirection a3; // [sp+0h] [bp-50h]@15 | |
884 AIDirection v9; // [sp+1Ch] [bp-34h]@15 | |
885 unsigned int v13; // [sp+44h] [bp-Ch]@8 | |
886 unsigned int monster_id; | |
887 | |
888 for ( int i = 0; i < uActorQueueSize; ++i ) | |
889 { | |
890 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) | |
1332 | 891 { |
2242 | 892 monster_id = PID_ID(pQueue[i].uPackedID); |
893 if ( !(pActors[monster_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0|| (pActors[monster_id].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0) || | |
2425 | 894 pActors[monster_id].uAIState == Dead || pActors[monster_id].uAIState == Removed || pActors[monster_id].uAIState == Disabled) ) |
2242 | 895 { |
896 v13 = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)]; | |
897 Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &v9, 0); | |
2425 | 898 if ( pActors[monster_id].uAIState == Pursuing || pActors[monster_id].uAIState == Tethered ) |
1332 | 899 { |
2242 | 900 if ( (double)(signed int)v9.uDistance < 307.2 ) |
901 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9); | |
902 } | |
903 else | |
904 { | |
905 pActors[monster_id].uCurrentActionTime += pEventTimer->uTimeElapsed; | |
906 if ( pActors[monster_id].uCurrentActionTime > pActors[monster_id].uCurrentActionLength ) | |
907 { | |
2425 | 908 if ( pActors[monster_id].uAIState == Dying ) |
1332 | 909 { |
2242 | 910 pActors[monster_id].uCurrentActionTime = 0; |
911 pActors[monster_id].uCurrentActionLength = 0; | |
2425 | 912 pActors[monster_id].uAIState = Dead; |
2242 | 913 pActors[monster_id].UpdateAnimation(); |
1332 | 914 } |
2242 | 915 if ( !ActorMove(i) ) |
916 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9); | |
917 } | |
1332 | 918 } |
2242 | 919 } |
1332 | 920 } |
2242 | 921 } |
922 } | |
1332 | 923 |
924 //----- (00406D10) -------------------------------------------------------- | |
1450 | 925 bool stru262_TurnBased::ActorMove(signed int queue_position) |
2242 | 926 { |
927 AIDirection v9; // esi@10 | |
928 int v11; // ecx@10 | |
929 unsigned __int8 pHostileType; // al@12 | |
930 AIDirection a3; // [sp+Ch] [bp-48h]@10 | |
931 AIDirection pDir; // [sp+28h] [bp-2Ch]@10 | |
932 unsigned int uActorID; // [sp+50h] [bp-4h]@2 | |
1448 | 933 |
2242 | 934 if (PID_TYPE(pQueue[queue_position].uPackedID) == OBJECT_Player) |
935 return 0; | |
936 uActorID = PID_ID(pQueue[queue_position].uPackedID); | |
2425 | 937 if ( pActors[uActorID].uAIState == Dead || pActors[uActorID].uAIState == Dying || |
938 pActors[uActorID].uAIState == Removed|| pActors[uActorID].uAIState == Disabled || | |
939 pActors[uActorID].uAIState == Summoned ) | |
2242 | 940 return 1; |
941 Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true); | |
942 if ( pActors[uActorID].pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[uActorID] ) | |
943 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly; | |
944 Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &v9, 0); | |
945 memcpy(&a3, &v9, sizeof(AIDirection)); | |
946 memcpy(&pDir, &a3, sizeof(AIDirection)); | |
947 v11 = a3.uDistance - pActors[uActorID].uActorRadius; | |
948 if ( v11 < 0 ) | |
949 v11 = 0; | |
950 pHostileType = pActors[uActorID].pMonsterInfo.uHostilityType; | |
951 switch (pHostileType) | |
952 { | |
953 case 1: | |
954 if ( (double)v11 < 307.2 ) | |
955 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
956 break; | |
957 case 2: | |
958 if ( v11 < 1024 ) | |
959 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
960 break; | |
961 case 3: | |
962 if ( v11 < 2560 ) | |
963 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long; | |
964 break; | |
965 } | |
966 if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0 ) | |
967 { | |
968 if (v11 < 10240 ) | |
969 { | |
970 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 0, &pDir); | |
971 pTurnEngine->pQueue[queue_position].AI_action_type = 4; | |
972 } | |
973 else | |
974 { | |
975 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 1024, 0); | |
976 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE; | |
977 } | |
978 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength; | |
979 return true; | |
980 } | |
981 if ( pActors[uActorID].pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long ) | |
982 { | |
983 if ( !(pActors[uActorID].uAttributes & 0x020000) || pActors[uActorID].pMonsterInfo.uAIType == 1 ) | |
984 { | |
985 if ( pActors[uActorID].pMonsterInfo.uAIType == 1 ) | |
986 { | |
987 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) | |
988 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
989 else | |
990 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
991 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE; | |
992 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength; | |
993 return true; | |
994 } | |
995 if ( pActors[uActorID].pMonsterInfo.uAIType == 2 ) | |
996 { | |
997 if (((double)pActors[uActorID].pMonsterInfo.uHP * 0.2) > (double)pActors[uActorID].sCurrentHP && (v11 < 10240 ) ) | |
1332 | 998 { |
2242 | 999 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) |
1000 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
1001 else | |
1002 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
1003 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE; | |
1004 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength; | |
1005 return true; | |
1006 } | |
1007 } | |
1008 if ( pActors[uActorID].pMonsterInfo.uAIType == 3 ) | |
1009 { | |
1010 if ( ((double)pActors[uActorID].pMonsterInfo.uHP * 0.1) > (double)pActors[uActorID].sCurrentHP && (v11 < 10240 )) | |
1011 { | |
1012 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY ) | |
1013 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
1014 else | |
1015 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
1016 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE; | |
1017 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength; | |
1018 return true; | |
1332 | 1019 } |
2242 | 1020 } |
1021 } | |
1022 if ( (double)(signed int)v11 < 307.2 ) | |
1023 return 0; | |
1332 | 1024 if ( (signed int)v11 < 5120 ) |
2242 | 1025 { |
1026 if ( pActors[uActorID].pMonsterInfo.uMissleAttack1Type && (signed int)v11 < 1024 ) | |
1027 Actor::AI_Pursue1(uActorID, ai_near_actors_targets_pid[uActorID], uActorID, 32, &pDir); | |
1028 else | |
1029 Actor::AI_Pursue2(uActorID, ai_near_actors_targets_pid[uActorID], 32, &pDir, 307); | |
1030 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE; | |
1031 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength; | |
1032 return true; | |
1332 | 1033 } |
2242 | 1034 } |
1035 switch(pActors[uActorID].pMonsterInfo.uMovementType) | |
1036 { | |
1037 case MONSTER_MOVEMENT_TYPE_SHORT: | |
1038 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 1024, 32); | |
1039 break; | |
1040 case MONSTER_MOVEMENT_TYPE_MEDIUM: | |
1041 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 2560, 32); | |
1042 break; | |
1043 case MONSTER_MOVEMENT_TYPE_LONG: | |
1044 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 5120, 32); | |
1045 break; | |
1046 case MONSTER_MOVEMENT_TYPE_FREE: | |
1047 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 10240, 32); | |
1048 break; | |
1049 case MONSTER_MOVEMENT_TYPE_STAIONARY: | |
1050 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0); | |
1051 break; | |
1052 default: | |
1053 return true; | |
1054 } | |
1055 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE; | |
1056 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength; | |
1057 return true; | |
1058 } | |
1332 | 1059 |
1367 | 1060 //----- (00406FA8) -------------------------------------------------------- |
1450 | 1061 void stru262_TurnBased::ActorAIChooseNewTargets() |
2242 | 1062 { |
1063 Actor *curr_acror; // ebx@4 | |
1064 AIDirection a3; // [sp+Ch] [bp-6Ch]@8 | |
1065 AIDirection v9; // [sp+28h] [bp-50h]@8 | |
1066 AIDirection a4; // [sp+44h] [bp-34h]@8 | |
1067 unsigned int target_pid; // [sp+60h] [bp-18h]@1 | |
1068 int uActorID; // [sp+68h] [bp-10h]@4 | |
1069 int i; | |
1070 | |
1071 for ( i = 0; i < uActorQueueSize; ++i ) | |
1072 { | |
1073 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor) | |
1332 | 1074 { |
2242 | 1075 uActorID=PID_ID(pQueue[i].uPackedID); |
1076 curr_acror = &pActors[uActorID]; | |
2425 | 1077 if ( !( curr_acror->uAIState == Summoned|| curr_acror->uAIState == Dead || |
1078 curr_acror->uAIState == Removed || curr_acror->uAIState == Disabled) ) | |
2242 | 1079 { |
1080 target_pid = ai_near_actors_targets_pid[uActorID]; | |
1081 Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true); | |
1082 Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v9, 0); | |
1083 memcpy(&a4, &v9, sizeof(AIDirection)); | |
1084 curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed; | |
1085 if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength ) | |
1332 | 1086 { |
2425 | 1087 if ( curr_acror->uAIState == Dying ) |
2242 | 1088 { |
1089 curr_acror->uCurrentActionTime = 0; | |
1090 curr_acror->uCurrentActionLength = 0; | |
2425 | 1091 curr_acror->uAIState = Dead; |
2242 | 1092 curr_acror->UpdateAnimation(); |
1093 break; | |
1094 } | |
1095 if ( rand() % 2 ) | |
1096 Actor::AI_Stand(uActorID, target_pid, 64, &a4); | |
1097 else | |
1098 Actor::AI_Bored(uActorID, target_pid, &a4); | |
1332 | 1099 } |
2242 | 1100 } |
1332 | 1101 } |
2242 | 1102 } |
1103 } | |
1332 | 1104 |