2499
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6
|
2541
|
7 #include "Engine/Engine.h"
|
2499
|
8
|
|
9 #include "Engine/Objects/Actor.h"
|
|
10 #include "../Party.h"
|
2502
|
11 #include "Media/Audio/AudioPlayer.h"
|
2499
|
12 #include "Engine/Objects/SpriteObject.h"
|
|
13 #include "../Timer.h"
|
|
14 #include "../stru298.h"
|
|
15 #include "Engine/Tables/IconFrameTable.h"
|
|
16 #include "Engine/Graphics/Viewport.h"
|
|
17 #include "Engine/Tables/FactionTable.h"
|
|
18
|
|
19 #include "TurnEngine.h"
|
|
20
|
|
21 struct stru262_TurnBased *pTurnEngine = new stru262_TurnBased;
|
|
22
|
|
23
|
|
24 //----- (00404544) --------------------------------------------------------
|
|
25 void stru262_TurnBased::SortTurnQueue()
|
|
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;
|
|
34
|
|
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 |= ACTOR_STAND_IN_QUEUE;//0x80
|
|
45 if ( !pActors[p_id].CanAct() )
|
|
46 {
|
|
47 --active_actors;
|
|
48 pQueue[i].actor_initiative = 1001;
|
|
49 pActors[p_id].ResetQueue();
|
|
50 }
|
|
51 }
|
|
52 else if ( p_type == OBJECT_Player)
|
|
53 {
|
|
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));
|
|
78 }
|
|
79 }
|
|
80 }
|
|
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 }
|
|
99 //----- (0040471C) --------------------------------------------------------
|
|
100 void stru262_TurnBased::ApplyPlayerAction()
|
|
101 {
|
|
102 if ( pParty->bTurnBasedModeOn == 1 )
|
|
103 {
|
|
104 if ( pTurnEngine->turn_stage == TE_ATTACK )
|
|
105 _406457(0);
|
|
106 }
|
|
107 }
|
|
108
|
|
109 //----- (004059DB) --------------------------------------------------------
|
|
110 void stru262_TurnBased::Start()
|
|
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;
|
|
121
|
|
122 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
|
|
123 pEventTimer->TrackGameTime();
|
|
124 pAudioPlayer->StopChannels(-1, -1);
|
2534
|
125 pAudioPlayer->PlaySound(SOUND_batllest, 0, 0, -1, 0, 0, 0, 0);
|
2499
|
126 //pPlayer = pParty->pPlayers.data();
|
|
127 dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength;
|
|
128 dword_50C994 = 0;
|
|
129
|
|
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;
|
|
135
|
|
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 }
|
|
147
|
|
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]].ActorNearby() )
|
|
155 {
|
|
156 pActors[ai_near_actors_ids[i]].uAttributes |= ACTOR_STAND_IN_QUEUE;//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 }
|
|
167
|
|
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;
|
|
212 }
|
|
213 }
|
|
214 }
|
|
215 for ( i = 0; i < a_players_count; ++i)
|
|
216 this->pQueue[activ_players[i]].actor_initiative = i + 2;
|
|
217 }
|
|
218 this->SortTurnQueue();
|
|
219 }
|
|
220
|
|
221 //----- (00405CFF) --------------------------------------------------------
|
|
222 void stru262_TurnBased::End(bool bPlaySound)
|
|
223 {
|
|
224 ObjectType objType; // eax@13
|
|
225 int objID; // esi@13
|
|
226 int i;
|
|
227
|
|
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)].ResetQueue();
|
|
233 }
|
|
234
|
|
235 for( uint i = 0; i < uNumSpriteObjects; ++i)
|
|
236 {
|
|
237 if (pSpriteObjects[i].uAttributes & 4)
|
|
238 pSpriteObjects[i].uAttributes &= ~0x04;
|
|
239 }
|
|
240
|
|
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 )
|
2534
|
252 pAudioPlayer->PlaySound(SOUND_batlleen, 0, 0, -1, 0, 0, 0, 0);
|
2499
|
253 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
|
|
254 pEventTimer->StopGameTime();
|
|
255 dword_50C994 = 0;
|
|
256 dword_50C998_turnbased_icon_1A = 0;
|
|
257 }
|
|
258 // 50C994: using guessed type int dword_50C994;
|
|
259 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
|
|
260
|
|
261 //----- (00405E14) --------------------------------------------------------
|
|
262 void stru262_TurnBased::AITurnBasedAction()
|
|
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 j;
|
|
272
|
|
273 for (uint 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
|
|
278 {
|
|
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 )
|
|
295 {
|
|
296 curr_actor->uCurrentActionTime = 0;
|
|
297 curr_actor->uCurrentActionLength = 0;
|
|
298 curr_actor->uAIState = Dead;
|
|
299 curr_actor->UpdateAnimation();
|
|
300 }
|
|
301 else if ( (curr_actor->uAIState > Removed) && (curr_actor->uAIState < 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;
|
|
316 }
|
|
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 }
|
|
350
|
|
351
|
|
352 //----- (00406051) --------------------------------------------------------
|
|
353 void stru262_TurnBased::StartTurn()
|
|
354 {
|
|
355 int player_num, actor_num, i, j;
|
|
356
|
|
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;
|
|
376 }
|
|
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 }
|
|
411 // 4F75D8: using guessed type int ai_arrays_size;
|
|
412
|
|
413 //----- (004061CA) --------------------------------------------------------
|
|
414 void stru262_TurnBased::NextTurn()
|
|
415 {
|
|
416 int v13; // [sp+10h] [bp-4h]@7
|
|
417 int monster_id; // eax@5
|
|
418
|
|
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;
|
|
425
|
|
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;
|
|
434
|
|
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 == Dying) || (pActors[monster_id].uAIState == Stunned)
|
|
444 || (pActors[monster_id].uAIState == AttackingMelee) || (pActors[monster_id].uAIState == AttackingRanged1)
|
|
445 || (pActors[monster_id].uAIState == AttackingRanged2) || (pActors[monster_id].uAIState == AttackingRanged3)
|
|
446 || (pActors[monster_id].uAIState == AttackingRanged4) || (pActors[monster_id].uAIState == 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 == Dying )// Dying
|
|
452 {
|
|
453 pActors[monster_id].uAIState = 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 == 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 }
|
|
472
|
|
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 != Dead) && (pActors[monster_id].uAIState != Dying) &&
|
|
481 (pActors[monster_id].uAIState != Removed) && (pActors[monster_id].uAIState != Summoned) &&
|
|
482 (pActors[monster_id].uAIState != 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 }
|
|
495
|
|
496 //----- (004063A1) --------------------------------------------------------
|
|
497 bool stru262_TurnBased::StepTurnQueue()
|
|
498 {
|
|
499 int v9; // dx@12
|
|
500 int j;
|
|
501
|
|
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 == Dying || v9 == Dead ||
|
|
524 v9 == Disabled || v9 == 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 }
|
|
545
|
|
546 //----- (00406457) --------------------------------------------------------
|
|
547 void stru262_TurnBased::_406457( int a2 )
|
|
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;
|
|
558 else
|
|
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;
|
|
565
|
|
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;
|
|
580 }
|
|
581 --turn_initiative;
|
|
582 }
|
|
583 }
|
|
584
|
|
585 //----- (0040652A) --------------------------------------------------------
|
|
586 void stru262_TurnBased::SetAIRecoveryTimes()
|
|
587 {
|
|
588 int i;
|
|
589 int monster_ai_state;
|
|
590 Actor *monster; // eax@5
|
|
591
|
|
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 == Standing ||
|
|
601 monster_ai_state == Fleeing ||
|
|
602 monster_ai_state == 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 }
|
|
608 }
|
|
609 }
|
|
610 }
|
|
611
|
|
612 //----- (004065B0) --------------------------------------------------------
|
|
613 void stru262_TurnBased::_4065B0()
|
|
614 {
|
|
615 int i;
|
|
616
|
|
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;
|
|
633 else
|
|
634 uActiveCharacter = 0;
|
|
635 viewparams->bRedrawGameUI = 1;
|
|
636 }
|
|
637 for ( i = 0; i < uActorQueueSize; ++i )
|
|
638 AIAttacks(i);
|
|
639 }
|
|
640
|
|
641 //----- (00406648) --------------------------------------------------------
|
|
642 void stru262_TurnBased::AIAttacks( unsigned int queue_index )
|
|
643 {
|
|
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
|
|
653
|
|
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 != Dead ) && ( pActors[actor_id].uAIState != Disabled )
|
|
666 &&( pActors[actor_id].uAIState != 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)
|
|
672 {
|
|
673 case 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 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 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 Stunned:
|
|
690 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
|
|
691 break;
|
|
692 case 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 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 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);
|
|
709 }
|
|
710 }
|
|
711 }
|
|
712 }
|
|
713 }
|
|
714 // 50FE08: using guessed type stru298 AttackerInfo;
|
|
715
|
|
716 //----- (0040680F) --------------------------------------------------------
|
|
717 void stru262_TurnBased::AI_Action_( int queue_index )
|
|
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
|
|
727
|
|
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 == Dying || pActors[actor_id].uAIState == Dead || pActors[actor_id].uAIState == Summoned ||
|
|
733 pActors[actor_id].uAIState == Disabled || pActors[actor_id].uAIState == 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;
|
|
780 }
|
|
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 }
|
|
802 }
|
|
803 //if (!pQueue[queue_index].AI_action_type)
|
|
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;
|
|
808 pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength;
|
|
809 return;
|
|
810 }
|
|
811 else
|
|
812 {
|
|
813 Actor::AI_Stand(actor_id, v22, 64, &v18);
|
|
814 pQueue[queue_index].AI_action_type = TE_AI_STAND;
|
|
815 pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength;
|
|
816 return;
|
|
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;
|
|
825 }
|
|
826 }
|
|
827 }
|
|
828
|
|
829 //----- (00406A63) --------------------------------------------------------
|
|
830 void stru262_TurnBased::ActorAISetMovementDecision()
|
|
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;
|
|
836
|
|
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);
|
|
848 }
|
|
849 }
|
|
850 }
|
|
851 // 50C994: using guessed type int dword_50C994;
|
|
852
|
|
853 //----- (00406AFE) --------------------------------------------------------
|
|
854 void stru262_TurnBased::ActorAIStopMovement()
|
|
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;
|
|
860
|
|
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;
|
|
870 }
|
|
871 }
|
|
872 turn_stage = TE_ATTACK;
|
|
873 ai_turn_timer = 100;
|
|
874 }
|
|
875
|
|
876 //----- (00406B9F) --------------------------------------------------------
|
|
877 void stru262_TurnBased::ActorAIDoAdditionalMove()
|
|
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)
|
|
887 {
|
|
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 == Dead || pActors[monster_id].uAIState == Removed || pActors[monster_id].uAIState == 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 == Pursuing || pActors[monster_id].uAIState == Tethered )
|
|
895 {
|
|
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 == Dying )
|
|
905 {
|
|
906 pActors[monster_id].uCurrentActionTime = 0;
|
|
907 pActors[monster_id].uCurrentActionLength = 0;
|
|
908 pActors[monster_id].uAIState = Dead;
|
|
909 pActors[monster_id].UpdateAnimation();
|
|
910 }
|
|
911 if ( !ActorMove(i) )
|
|
912 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
|
|
913 }
|
|
914 }
|
|
915 }
|
|
916 }
|
|
917 }
|
|
918 }
|
|
919
|
|
920 //----- (00406D10) --------------------------------------------------------
|
|
921 bool stru262_TurnBased::ActorMove(signed int queue_position)
|
|
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
|
|
929
|
|
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 == Dead || pActors[uActorID].uAIState == Dying ||
|
|
934 pActors[uActorID].uAIState == Removed|| pActors[uActorID].uAIState == Disabled ||
|
|
935 pActors[uActorID].uAIState == 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 & ACTOR_FLEEING) || 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 ) )
|
|
994 {
|
|
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;
|
|
1015 }
|
|
1016 }
|
|
1017 }
|
|
1018 if ( (double)(signed int)v11 < 307.2 )
|
|
1019 return 0;
|
|
1020 if ( (signed int)v11 < 5120 )
|
|
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;
|
|
1029 }
|
|
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 }
|
|
1055
|
|
1056 //----- (00406FA8) --------------------------------------------------------
|
|
1057 void stru262_TurnBased::ActorAIChooseNewTargets()
|
|
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)
|
|
1070 {
|
|
1071 uActorID=PID_ID(pQueue[i].uPackedID);
|
|
1072 curr_acror = &pActors[uActorID];
|
|
1073 if ( !( curr_acror->uAIState == Summoned|| curr_acror->uAIState == Dead ||
|
|
1074 curr_acror->uAIState == Removed || curr_acror->uAIState == 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 )
|
|
1082 {
|
|
1083 if ( curr_acror->uAIState == Dying )
|
|
1084 {
|
|
1085 curr_acror->uCurrentActionTime = 0;
|
|
1086 curr_acror->uCurrentActionLength = 0;
|
|
1087 curr_acror->uAIState = 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);
|
|
1095 }
|
|
1096 }
|
|
1097 }
|
|
1098 }
|
|
1099 }
|
|
1100
|