annotate Engine/TurnEngine/TurnEngine.cpp @ 2567:d569340b05ff

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