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