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