-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAIPTHATT.CPP
247 lines (201 loc) · 6.03 KB
/
AIPTHATT.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* ========================================================================
Copyright (c) 1990,1996 Synergistic Software
All Rights Reserved
========================================================================
Filename: aipthatt.cpp
Author: Greg Hightower & Gary Powell
======================================================================== */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "system.h"
#include "engine.h"
#include "ai_utils.h"
#include "avatar.hxx"
#include "scnmgr.hxx"
/* ========================================================================
Function - mfCreateFollowers
Description - Make some troops
Returns - void
======================================================================== */
#if 0 // UNUSED
void PATH_ATTACK_DATA::mfCreateFollowers(CAvatar *pAvatar)
{
LONG i;
// Note : Don't lock the scene here, its already locked.
PTR_SCENE pCurrentScene = (PTR_SCENE) BLKPTR(SCENE_MGR::hCurrentScene);
const LONG X = pAvatar->mfX();
const LONG Y = pAvatar->mfY();
const LONG Z = pAvatar->mfZ();
LONG IdStart = pAvatar->Id*25+1000; // make groups of 25
SHORT *pList;
PLAYER *pPath;
// init leader data
Leader.sCount = 0;
Leader.sMaxFollowers = 2;
Leader.hdlSlotList = NewBlock(sizeof(SHORT) * Leader.sMaxFollowers);
pList = (SHORT *)BLKPTR(Leader.hdlSlotList);
// Initialize the List to no followers (in case we blow up below.)
for (i = 0; i < Leader.sMaxFollowers; i++)
{
pList[i] = fERROR;
}
Leader.hdlPathDeltas = NewBlock(sizeof(PLAYER) * Leader.sMaxFollowers);
pPath = (PLAYER *)BLKPTR(Leader.hdlPathDeltas);
// create my troops and record their handles in my follower list
for (i=0; i< Leader.sMaxFollowers; i++)
{
LONG index = CAvatar::CreateAvatar( IdStart,
pAvatar->mfType(),
X, Y, 0,
CAvatar::AI_FUNC_FOLLOW_ID ,
pCurrentScene,
pAvatar->Realm.HomeRealm);
if (index != fERROR )
{
CAvatar *pTroop = (CAvatar *) BLKPTR(pCurrentScene->Avatars[index]);
pTroop->attrib.RuntimeCreated = TRUE;
pTroop->fFollowId.Id = pAvatar->Id; // who to follow
// Make them from the same realm as the leader.
pTroop->fFollowId.Rate = 2 * pAvatar->mfGetMarchRate(); // run a little faster then my captain
pList[i] = AvatarIdToHdl(pTroop->Id);
IdStart++;
}
else
{
// No slots left.
printf("WARNING! Unable to create requested troops. %d\n", (8 - i));
return;
}
pPath[i].x = pAvatar->mfX();
pPath[i].y = pAvatar->mfY() + (i*OffSet);
}
}
#endif
/* ========================================================================
Function - PathAttack
Description - AI function to follow a point path from a file on disk
Returns - Current state
======================================================================== */
#if 0 // UNUSED
void CAvatar::PathAttack (CAvatar *pAvatar, CAvatar::AISTATUS Status)
{
switch( Status )
{
case AI_INIT:
if (pAvatar->fPathAttack.FollowPath.PathCount > 0)
{
LONG X;
LONG Y;
LONG Z;
LONG A;
pAvatar->fPathAttack.FollowPath.mfGetCurrentPt(X, Y, Z, A);
pAvatar->Status = AI_MOVING;
//pAvatar->Rate = pAvatar->fPathAttack.TrailRate;
pAvatar->mfMoveToXYZA( X, Y, Z, A );
pAvatar->mfStartAnimationLoop( WALKSEQ);
}
else
{
pAvatar->mfStartAnimationLoop( STANDSEQ);
}
pAvatar->fPathAttack.mfCreateFollowers(pAvatar);
break;
case AI_RELEASE:
pAvatar->Status = AI_INIT;
break;
case AI_MOVING:
{
// only x and y work right now
LONG X;
LONG Y;
LONG Z;
LONG A;
pAvatar->fPathAttack.FollowPath.mfGetCurrentPt(X, Y, Z, A);
if( ( pAvatar->mfX() == X ) &&
( pAvatar->mfY() == Y ) )
{
// if I'm at end of path, attack
if(!pAvatar->fPathAttack.FollowPath.mfGetNextPt(X, Y, Z, A))
pAvatar->Status = AI_ATTACK;
}
else
{
// record where I've been
pAvatar->fPathAttack.Leader.mfRecordTrail(pAvatar);
// if not at destination, start moving in that direction
LONG dx = (X - pAvatar->mfX());
LONG dy = (Y - pAvatar->mfY());
// move toward my target
const LONG h = dist( pAvatar->mfX(), pAvatar->mfY(), X, Y );
if( abs(dx) > pAvatar->fPathAttack.TrailRate )
{
dx = dx * pAvatar->fPathAttack.TrailRate / h;
}
if( abs(dy) > pAvatar->fPathAttack.TrailRate )
{
dy = dy * pAvatar->fPathAttack.TrailRate / h;
}
pAvatar->FaceTo(pAvatar->mfX() + dx,
pAvatar->mfY() + dy );
pAvatar->mfMoveToXYZA( pAvatar->mfX() + dx,
pAvatar->mfY() + dy, Z, pAvatar->mfAngle());
}
// now update anyone following me
pAvatar->fPathAttack.Leader.mfMoveFollowers(pAvatar);
}
break;
case AI_ATTACK:
{
SHORT rndnum;
rndnum = random(6);
if(rndnum == 0)
pAvatar->mfStartAnimationOnce(ATTACK1SEQ);
else
if(rndnum == 1)
pAvatar->mfStartAnimationOnce(ATTACK2SEQ);
else
if(rndnum == 2)
pAvatar->mfStartAnimationOnce(DEFENDSEQ);
else
pAvatar->mfStartAnimationOnce(STANDSEQ);
}
// now update anyone following me
//pAvatar->fPathAttack.Leader.mfMoveFollowers(pAvatar);
break;
case AI_BEGIN_PAUSE:
pAvatar->mfBeginPause();
break;
case AI_PAUSED:
pAvatar->mfStandAndFidget();
break;
case AI_END_PAUSE:
pAvatar->mfEndPause();
break;
case AI_BEGIN_LISTEN:
pAvatar->mfBeginListen();
break;
case AI_LISTEN:
// Follow the camera around.
pAvatar->mfListen();
break;
case AI_END_LISTEN:
pAvatar->mfEndListen();
break;
case AI_BEGIN_LISTEN_BOW:
pAvatar->mfBeginListenBow();
break;
case AI_END_LISTEN_BOW:
pAvatar->mfEndListenBow();
break;
case AI_ROTATE_TO_CAMERA:
pAvatar->mfRotateToCamera();
break;
case AI_RETURN_TO_POSITION:
pAvatar->mfReturnToPosition();
break;
default:
pAvatar->Status = AI_PAUSED;
}
}
#endif