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