4b825dc642cb6eb9a060e54bf8d69288fbee4904ebd360ec63ec976c05699f3180e866b3f69e5472
 
 
1
#include "system.h"
 
 
2
#include "stratdef.h"
 
 
3
#include "bh_types.h"
 
 
4
#include "npc_marine.h"
 
 
5
#include "weapons.h"
 
 
6
#include "los.h"
 
 
7
#include "paintball.h"
 
 
8
#include <math.h>
 
 
9
#include <stdio.h>
 
 
10
#include <stdlib.h>
 
 
11
#include <assert.h>
 
 
12
#include "pldghost.h"
 
 
13
 
 
 
14
extern int ObjectShouldAppearOnMotionTracker(STRATEGYBLOCK *sbPtr);
 
 
15
/*
 
 
16
 
 
 
17
 Foley and Van Dam 2d distance function
 
 
18
 
 
 
19
 WARNING! Returns distance x 3
 
 
20
 
 
 
21
 Here is the F & VD distance function:
 
 
22
 
 
 
23
 x + z + (max(x,z) * 2)
 
 
24
 ----------------------
 
 
25
          3
 
 
26
*/
 
 
27
 
 
 
28
static int FandVD_Distance_2d(const VECTOR2D *v0, const VECTOR2D *v1)
 
 
29
{
 
 
30
    int dx = abs(v1->vx - v0->vx);
 
 
31
    int dy = abs(v1->vy - v0->vy);
 
 
32
 
 
 
33
    if(dx > dy)
 
 
34
        return (dx + dy + (dx* 2));
 
 
35
    else
 
 
36
        return (dx + dy + (dy* 2));
 
 
37
}
 
 
38
 
 
 
39
 
 
 
40
/*
 
 
41
 Foley and Van Dam 3d distance function
 
 
42
 
 
 
43
 WARNING! Returns distance x 9
 
 
44
 
 
 
45
 For a 3d version, calculate (f(f(x,y), y*3))/9
 
 
46
 
 
 
47
*/
 
 
48
 
 
 
49
static int FandVD_Distance_3d(const VECTORCH *v0, const VECTORCH *v1)
 
 
50
{
 
 
51
    int dz = abs((v1->vz - v0->vz) * 3);
 
 
52
 
 
 
53
    int dxy = FandVD_Distance_2d((VECTOR2D *) v0, (VECTOR2D *) v1);
 
 
54
 
 
 
55
    if(dxy > dz)
 
 
56
        return (dxy + dz + (dxy * 2));
 
 
57
    else
 
 
58
        return (dxy + dz + (dz * 2));
 
 
59
}
 
 
60
 
 
 
61
 
 
 
62
extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
 
 
63
 
 
 
64
int CalculateFiringSolution(VECTORCH* firing_pos, VECTORCH* target_pos, VECTORCH* target_vel, int projectile_speed, VECTORCH* solution)
 
 
65
{
 
 
66
    VECTORCH rotated_solution;
 
 
67
    MATRIXCH mat;
 
 
68
 
 
 
69
    assert(target_vel);
 
 
70
 
 
 
71
    //get a normalised vector from start to destination
 
 
72
    VECTORCH normal = *target_pos; //normal from firer to target
 
 
73
 
 
 
74
    normal.vx -= firing_pos->vx;
 
 
75
    normal.vy -= firing_pos->vy;
 
 
76
    normal.vz -= firing_pos->vz;
 
 
77
 
 
 
78
    if(!normal.vx && !normal.vy && !normal.vz)
 
 
79
        return 0;
 
 
80
 
 
 
81
    Approximate3dMagnitude(&normal);
 
 
82
    Normalise(&normal);
 
 
83
 
 
 
84
    //calculate a matrix that will rotate the normal to the zaxis
 
 
85
    {
 
 
86
        //normal will be the third row
 
 
87
        VECTORCH row1,row2;
 
 
88
 
 
 
89
        if(normal.vx > 30000 || normal.vx < -30000 || normal.vy > 30000 || normal.vy < -30000)
 
 
90
        {
 
 
91
            row1.vx = -normal.vy;
 
 
92
            row1.vy = normal.vx;
 
 
93
            row1.vz = 0;
 
 
94
        }
 
 
95
        else 
 
 
96
        {
 
 
97
            row1.vx = -normal.vz;
 
 
98
            row1.vy = 0;
 
 
99
            row1.vz = normal.vx;
 
 
100
        }
 
 
101
 
 
 
102
        Normalise(&row1);
 
 
103
 
 
 
104
        CrossProduct(&normal,&row1,&row2);
 
 
105
 
 
 
106
        mat.mat11 = row1.vx;
 
 
107
        mat.mat21 = row1.vy;
 
 
108
        mat.mat31 = row1.vz;
 
 
109
 
 
 
110
        mat.mat12 = row2.vx;
 
 
111
        mat.mat22 = row2.vy;
 
 
112
        mat.mat32 = row2.vz;
 
 
113
 
 
 
114
        mat.mat13 = normal.vx;
 
 
115
        mat.mat23 = normal.vy;
 
 
116
        mat.mat33 = normal.vz;
 
 
117
    }
 
 
118
 
 
 
119
    //apply the rotation to the velocity
 
 
120
    VECTORCH rotated_vel = *target_vel;
 
 
121
    RotateVector(&rotated_vel,&mat);
 
 
122
 
 
 
123
    //is the target moving too fast?
 
 
124
    if(rotated_vel.vz >= projectile_speed || -rotated_vel.vz >= projectile_speed)
 
 
125
            return 0;
 
 
126
 
 
 
127
    //the x and y components of the rotated solution should match the rotated velocity
 
 
128
    //(scale down by projectile speed , because we want a normalised direction)
 
 
129
 
 
 
130
    rotated_solution.vx = DIV_FIXED(rotated_vel.vx, projectile_speed);
 
 
131
    rotated_solution.vy = DIV_FIXED(rotated_vel.vy, projectile_speed);
 
 
132
 
 
 
133
    //z=1-(x*x+y*y)
 
 
134
    {
 
 
135
        //not sure we have a fixed point square root
 
 
136
        float x = (float)rotated_solution.vx;
 
 
137
        float y = (float)rotated_solution.vy;
 
 
138
        float z_squared = 65536.0*65536.0-(x*x+y*y);
 
 
139
 
 
 
140
        if(z_squared < 0)
 
 
141
        {
 
 
142
            //target moving too fast to hit
 
 
143
            return 0;
 
 
144
        }
 
 
145
 
 
 
146
        rotated_solution.vz = (int)sqrt(z_squared);
 
 
147
    }
 
 
148
 
 
 
149
    //finally need to rotated solution back
 
 
150
    *solution = rotated_solution;
 
 
151
    TransposeMatrixCH(&mat);
 
 
152
    RotateVector(solution, &mat);
 
 
153
 
 
 
154
    //normalise solution to be on the safe side
 
 
155
    Normalise(solution);
 
 
156
 
 
 
157
return 1;
 
 
158
}
 
 
159
 
 
 
160
void SmartTarget_GetCofM(DISPLAYBLOCK *target, VECTORCH *viewSpaceOutput) 
 
 
161
{
 
 
162
    AVP_BEHAVIOUR_TYPE targetType;
 
 
163
 
 
 
164
    /* Get smartgun aiming point. */
 
 
165
 
 
 
166
    if (target->HModelControlBlock == NULL || target->HModelControlBlock->section_data == NULL)
 
 
167
    {
 
 
168
        *viewSpaceOutput = target->ObView;
 
 
169
        return;
 
 
170
    }
 
 
171
 
 
 
172
    /* Must be a hierarchy. */
 
 
173
 
 
 
174
    switch(target->ObStrategyBlock->type)
 
 
175
    {
 
 
176
        case I_BehaviourNetGhost:
 
 
177
        {
 
 
178
            NETGHOSTDATABLOCK *dataptr = target->ObStrategyBlock->dataptr;
 
 
179
            targetType = dataptr->type;
 
 
180
        }
 
 
181
        break;
 
 
182
        default:
 
 
183
            targetType = target->ObStrategyBlock->type;
 
 
184
    }
 
 
185
 
 
 
186
    /* Now, switch case on targetType. */
 
 
187
 
 
 
188
    switch (targetType)
 
 
189
    {
 
 
190
        case I_BehaviourMarine:
 
 
191
        case I_BehaviourMarinePlayer:
 
 
192
        case I_BehaviourPredator:
 
 
193
        case I_BehaviourPredatorPlayer:
 
 
194
        case I_BehaviourAlien:
 
 
195
        case I_BehaviourAlienPlayer:
 
 
196
        {
 
 
197
            SECTION_DATA *targetsection = GetThisSectionData(target->HModelControlBlock->section_data, "chest");
 
 
198
 
 
 
199
            if (targetsection == NULL)
 
 
200
                targetsection = target->HModelControlBlock->section_data;
 
 
201
 
 
 
202
            if (targetsection->flags & section_data_view_init)
 
 
203
                *viewSpaceOutput = targetsection->View_Offset;
 
 
204
            else
 
 
205
                *viewSpaceOutput = target->ObView; /* Whoops. */
 
 
206
        return;
 
 
207
        }
 
 
208
        default:
 
 
209
        {
 
 
210
            /* General case. */
 
 
211
            if (target->HModelControlBlock->section_data->flags & section_data_view_init)
 
 
212
                *viewSpaceOutput = target->HModelControlBlock->section_data->View_Offset;
 
 
213
            else
 
 
214
                *viewSpaceOutput = target->ObView; /* Whoops. */
 
 
215
        }
 
 
216
    }
 
 
217
}
 
 
218
 
 
 
219
static int SmartTarget_TargetFilter(STRATEGYBLOCK *candidate)
 
 
220
{
 
 
221
    /* KJL 11:56:33 14/10/98 - the Predator's Shoulder cannon can only track objects when used in the correct
 
 
222
    vision mode, e.g. you can only target marines when in infrared mode */
 
 
223
 
 
 
224
    switch(PlayerStatus.SelectedWeapon->WeaponIDNumber)
 
 
225
    {
 
 
226
        case WEAPON_PRED_SHOULDERCANNON:
 
 
227
        case WEAPON_PRED_DISC:
 
 
228
        {
 
 
229
            switch (PlayerStatus.VisionMode)
 
 
230
            {
 
 
231
                case VISION_MODE_PRED_SEEALIENS:
 
 
232
                {
 
 
233
                    switch(candidate->type)
 
 
234
                    {
 
 
235
                        case I_BehaviourAlien:
 
 
236
                        case I_BehaviourXenoborg:
 
 
237
                        case I_BehaviourFaceHugger:
 
 
238
                        case I_BehaviourQueenAlien:
 
 
239
                            return !NPC_IsDead(candidate);
 
 
240
                        case I_BehaviourNetGhost:
 
 
241
                        {
 
 
242
                            NETGHOSTDATABLOCK *ghostDataPtr = (NETGHOSTDATABLOCK *)candidate->dataptr;
 
 
243
                            return (ghostDataPtr->type == I_BehaviourAlienPlayer || ghostDataPtr->type == I_BehaviourAlien);
 
 
244
                        }
 
 
245
                        default:
 
 
246
                        return 0;
 
 
247
                    }
 
 
248
                }
 
 
249
                case VISION_MODE_PRED_THERMAL:
 
 
250
                {
 
 
251
                    switch(candidate->type)
 
 
252
                    {
 
 
253
                        case I_BehaviourMarine:
 
 
254
                        {
 
 
255
                            MARINE_STATUS_BLOCK *marineStatusPointer = (MARINE_STATUS_BLOCK *)(candidate->dataptr);
 
 
256
                            return marineStatusPointer->My_Weapon->Android ? 0 : !NPC_IsDead(candidate);
 
 
257
                        }
 
 
258
                        case I_BehaviourNetGhost:
 
 
259
                        {
 
 
260
                            NETGHOSTDATABLOCK *ghostDataPtr = (NETGHOSTDATABLOCK *)candidate->dataptr;
 
 
261
                            return (ghostDataPtr->type == I_BehaviourMarinePlayer || ghostDataPtr->type == I_BehaviourMarine);
 
 
262
                        }
 
 
263
                        default:
 
 
264
                        return 0;
 
 
265
                    }
 
 
266
                }
 
 
267
                case VISION_MODE_PRED_SEEPREDTECH:
 
 
268
                {
 
 
269
                    switch(candidate->type)
 
 
270
                    {
 
 
271
                        case I_BehaviourPredator:
 
 
272
                            return !NPC_IsDead(candidate);
 
 
273
                        case I_BehaviourNetGhost:
 
 
274
                        {
 
 
275
                            NETGHOSTDATABLOCK *ghostDataPtr = (NETGHOSTDATABLOCK *)candidate->dataptr;
 
 
276
 
 
 
277
                            switch(ghostDataPtr->type)
 
 
278
                            {
 
 
279
                                case I_BehaviourPredator:
 
 
280
                                case I_BehaviourPredatorPlayer:
 
 
281
                                {
 
 
282
                                    /* Check for game type? */
 
 
283
                                    switch (netGameData.gameType)
 
 
284
                                    {
 
 
285
                                        case NGT_Coop:
 
 
286
                                        case NGT_CoopDeathmatch:
 
 
287
                                        case NGT_LastManStanding:
 
 
288
                                            return 0;
 
 
289
                                        //case NGT_Individual:
 
 
290
                                        //case NGT_PredatorTag:
 
 
291
                                        //    return 1;
 
 
292
                                        default:
 
 
293
                                            return 1;
 
 
294
                                    }
 
 
295
                                }
 
 
296
                                default:
 
 
297
                                return 0;
 
 
298
                            }
 
 
299
                        }
 
 
300
                        case I_BehaviourFrisbee:
 
 
301
                        case I_BehaviourGrenade:
 
 
302
                        case I_BehaviourFragmentationGrenade:
 
 
303
                        return 1;
 
 
304
                        case I_BehaviourProximityGrenade:
 
 
305
                            return DynamicObjectIsMoving(candidate->DynPtr);
 
 
306
                        default:
 
 
307
                        return 0;
 
 
308
                    }
 
 
309
                }
 
 
310
                default:
 
 
311
                return 0;
 
 
312
            }
 
 
313
        }
 
 
314
        case WEAPON_SMARTGUN:
 
 
315
        {
 
 
316
            switch (candidate->type)
 
 
317
            {
 
 
318
                //case I_BehaviourMarine:
 
 
319
                case I_BehaviourMarinePlayer:
 
 
320
                    return 0;
 
 
321
                default:
 
 
322
                    return ObjectShouldAppearOnMotionTracker(candidate);
 
 
323
        /*
 
 
324
                case I_BehaviourAlien:
 
 
325
                case I_BehaviourPredator:
 
 
326
                case I_BehaviourQueenAlien:
 
 
327
                case I_BehaviourFaceHugger:
 
 
328
                case I_BehaviourXenoborg:
 
 
329
                    return !NPC_IsDead(candidate);
 
 
330
                case I_BehaviourNetGhost:
 
 
331
                {
 
 
332
                    NETGHOSTDATABLOCK *ghostDataPtr = (NETGHOSTDATABLOCK *)candidate->dataptr;
 
 
333
 
 
 
334
                    // Don't target marines if Friendly Fire is disabled.
 
 
335
                    //if (netGameData.disableFriendlyFire && (netGameData.gameType == NGT_CoopDeathmatch || netGameData.gameType == NGT_Coop))
 
 
336
 
 
 
337
                    switch (ghostDataPtr->type)
 
 
338
                    {
 
 
339
                        case I_BehaviourPredatorPlayer:
 
 
340
                        case I_BehaviourAlienPlayer:
 
 
341
                        case I_BehaviourAlien:
 
 
342
                            return 1;
 
 
343
                        default:
 
 
344
                            return 0;
 
 
345
                    }
 
 
346
                }
 
 
347
                default:
 
 
348
                    return 0;
 
 
349
        */
 
 
350
            }
 
 
351
        }
 
 
352
        break;
 
 
353
        default:
 
 
354
        return 0;
 
 
355
    }
 
 
356
}
 
 
357
 
 
 
358
#define SMART_TRACKABLE_TARGETS 100
 
 
359
#define SMART_TARGETING_RANGE 1000000
 
 
360
 
 
 
361
extern struct KObject VisibleObjects[maxobjects];
 
 
362
extern int numVisObjs;
 
 
363
 
 
 
364
DISPLAYBLOCK *SmartTarget_GetNewTarget()
 
 
365
{
 
 
366
    int a=0,b,c;
 
 
367
    int numberOfObjects = numVisObjs;
 
 
368
 
 
 
369
    DISPLAYBLOCK *track_array[SMART_TRACKABLE_TARGETS] = { NULL };
 
 
370
 
 
 
371
    while (numberOfObjects--)
 
 
372
    {
 
 
373
        DISPLAYBLOCK* objectPtr = VisibleObjects[numberOfObjects].DispPtr;
 
 
374
        STRATEGYBLOCK* sbPtr = objectPtr->ObStrategyBlock;
 
 
375
 
 
 
376
        if (sbPtr && sbPtr->DynPtr)
 
 
377
        {
 
 
378
            VECTORCH viewPos;
 
 
379
            /* Arc reject. */
 
 
380
            SmartTarget_GetCofM(objectPtr, &viewPos);
 
 
381
 
 
 
382
            if (viewPos.vz > 0)
 
 
383
            {
 
 
384
                if (SmartTarget_TargetFilter(sbPtr))
 
 
385
                {
 
 
386
                    if (a < SMART_TRACKABLE_TARGETS)
 
 
387
                    {
 
 
388
                        track_array[a] = objectPtr;
 
 
389
                        a++;
 
 
390
                    }
 
 
391
                }
 
 
392
            }
 
 
393
        }
 
 
394
    }
 
 
395
 
 
 
396
    /* Now, filter the track array. */
 
 
397
    b = a;
 
 
398
    c = a;
 
 
399
 
 
 
400
    while (b--)
 
 
401
    {
 
 
402
        int notFar = -1;
 
 
403
 
 
 
404
        int nearestObjectDist = SMART_TARGETING_RANGE;
 
 
405
        DISPLAYBLOCK *nearestObjectPtr = NULL;
 
 
406
 
 
 
407
        a = c;
 
 
408
 
 
 
409
        while (a)
 
 
410
        {
 
 
411
            DISPLAYBLOCK* objectPtr = track_array[--a];
 
 
412
 
 
 
413
            if (objectPtr)
 
 
414
            {
 
 
415
                /* calc distance to player - no parallel strat support yet */
 
 
416
                /* 2d vector from player to object */
 
 
417
                int dist = FandVD_Distance_3d(&objectPtr->ObWorld, &PlayerStatus.DisplayBlock->ObWorld);
 
 
418
 
 
 
419
                if (dist < nearestObjectDist)
 
 
420
                {
 
 
421
                    nearestObjectDist = dist;
 
 
422
                    nearestObjectPtr = objectPtr;
 
 
423
                    notFar = a;
 
 
424
                }
 
 
425
            }
 
 
426
        }
 
 
427
 
 
 
428
        if (nearestObjectPtr)
 
 
429
        {
 
 
430
            assert(notFar != -1);
 
 
431
 
 
 
432
            if (IsThisObjectVisibleFromThisPosition_WithIgnore(track_array[notFar], PlayerStatus.DisplayBlock, &(Global_VDB.VDB_World)))
 
 
433
                return track_array[notFar]; /* Valid. */
 
 
434
            else
 
 
435
                track_array[notFar] = NULL; /* Remove from list. */
 
 
436
        }
 
 
437
    }
 
 
438
 
 
 
439
return NULL;
 
 
440
}
 
 
441
 
 
 
442
int SmartTargetSightX, SmartTargetSightY;
 
 
443
DISPLAYBLOCK *SmartTarget_Object;
 
 
444
 
 
 
445
int SmartTarget(int speed, int projectile_speed)
 
 
446
{
 
 
447
    DISPLAYBLOCK *trackedObject = SmartTarget_GetNewTarget();    
 
 
448
    int targetX = ScreenDescriptorBlock.SDB_Width >> 1;
 
 
449
    int targetY = ScreenDescriptorBlock.SDB_Height >> 1;
 
 
450
    SmartTarget_Object = NULL;
 
 
451
 
 
 
452
    /* If there is a valid near object which isn't so close as to cause a division by zero */
 
 
453
    if (trackedObject && (trackedObject->ObView.vz != 0))
 
 
454
    {
 
 
455
        VECTORCH targetView;
 
 
456
 
 
 
457
        /* Set targetView. */
 
 
458
        SmartTarget_GetCofM(trackedObject, &targetView);
 
 
459
 
 
 
460
        if(projectile_speed)
 
 
461
        {
 
 
462
            //get a firing solution so that projectile should hit if target maintains curremt velocity
 
 
463
            if(trackedObject->ObStrategyBlock)
 
 
464
            {
 
 
465
                if(trackedObject->ObStrategyBlock->DynPtr)
 
 
466
                {
 
 
467
                    DYNAMICSBLOCK *dynPtr = trackedObject->ObStrategyBlock->DynPtr;
 
 
468
 
 
 
469
                    if(dynPtr->LinVelocity.vx || dynPtr->LinVelocity.vy || dynPtr->LinVelocity.vz)
 
 
470
                    {
 
 
471
                        VECTORCH velocity = dynPtr->LinVelocity;
 
 
472
                        VECTORCH zero = {0,0,0};
 
 
473
                        VECTORCH solution;
 
 
474
                        //rotate velocity into view space
 
 
475
                        RotateVector(&velocity, &Global_VDB.VDB_Mat);
 
 
476
 
 
 
477
                        if(CalculateFiringSolution(&zero, &targetView, &velocity, projectile_speed, &solution))
 
 
478
                            targetView = solution;
 
 
479
                    }
 
 
480
                }
 
 
481
            }
 
 
482
        }
 
 
483
 
 
 
484
        if (targetView.vz > 0)
 
 
485
        {
 
 
486
            int screenX = WideMulNarrowDiv(targetView.vx, Global_VDB.VDB_ProjX, targetView.vz);
 
 
487
            int screenY = WideMulNarrowDiv(targetView.vy*4, Global_VDB.VDB_ProjY, targetView.vz*3);
 
 
488
            int maxRangeX = (ScreenDescriptorBlock.SDB_Width * 14) / 32;  /* gives nearly 90% of screen */
 
 
489
 
 
 
490
            if ((screenX > -maxRangeX) && (screenX < maxRangeX))
 
 
491
            {
 
 
492
                int maxRangeY = (ScreenDescriptorBlock.SDB_Height * 14) / 32; /* gives nearly 90% of screen */
 
 
493
 
 
 
494
                if ((screenY > -maxRangeY) && (screenY < maxRangeY))
 
 
495
                {
 
 
496
                    targetX += screenX;
 
 
497
                    targetY += screenY;
 
 
498
                    SmartTarget_Object = trackedObject;
 
 
499
                    //printf("Tracking object %p \n", trackedObject);
 
 
500
                }
 
 
501
            }
 
 
502
        }
 
 
503
    }
 
 
504
 
 
 
505
    if (speed)
 
 
506
    {
 
 
507
        int targetingSpeed = NormalFrameTime * speed;
 
 
508
 
 
 
509
        /* KJL 14:08:50 09/20/96 - the targeting is FRI, but care has to be taken
 
 
510
           at very low frame rates to ensure that the sight doesn't jump about
 
 
511
           all over the place. */
 
 
512
        if (targetingSpeed > 65536)
 
 
513
            targetingSpeed = 65536;
 
 
514
 
 
 
515
        int dx = MUL_FIXED( ((targetX << 16) - SmartTargetSightX), targetingSpeed );
 
 
516
        int dy = MUL_FIXED( ((targetY << 16) - SmartTargetSightY), targetingSpeed );
 
 
517
 
 
 
518
        /* If the x-coord difference between the sight and the target is small,
 
 
519
           just move the sight so that it has the same x-coord as the target.
 
 
520
           This stops the sight from hovering a pixel away from where it should be */
 
 
521
        if (dx > 16384 || dx < -16384)
 
 
522
            SmartTargetSightX += dx;
 
 
523
        else
 
 
524
            SmartTargetSightX = targetX << 16;
 
 
525
 
 
 
526
        /* Similarly for the y-coord */
 
 
527
        if (dy > 16384 || dy < -16384)
 
 
528
            SmartTargetSightY += dy;
 
 
529
        else
 
 
530
            SmartTargetSightY = targetY << 16;
 
 
531
    }
 
 
532
    else
 
 
533
    {
 
 
534
        SmartTargetSightX = targetX << 16;
 
 
535
        SmartTargetSightY = targetY << 16;
 
 
536
    }
 
 
537
 
 
 
538
return SmartTarget_Object != NULL;
 
 
539
}
 
 
540
 
 
 
541
void GetTargetingPointOfObject(DISPLAYBLOCK *objectPtr, VECTORCH *targetPtr)
 
 
542
{
 
 
543
    /* try to look at the centre of the object */
 
 
544
    if (objectPtr->HModelControlBlock)
 
 
545
    {
 
 
546
          ProveHModel(objectPtr->HModelControlBlock, objectPtr);
 
 
547
        SECTION_DATA *firstSectionPtr = objectPtr->HModelControlBlock->section_data;
 
 
548
          assert(firstSectionPtr);
 
 
549
        assert(firstSectionPtr->flags&section_data_initialised);
 
 
550
 
 
 
551
        /* look for the object's torso in preference */
 
 
552
        SECTION_DATA *targetSectionPtr = GetThisSectionData(objectPtr->HModelControlBlock->section_data, "chest");
 
 
553
 
 
 
554
        if (targetSectionPtr)
 
 
555
        {
 
 
556
            assert(targetSectionPtr->flags & section_data_initialised);
 
 
557
            *targetPtr = targetSectionPtr->World_Offset;
 
 
558
        }
 
 
559
        else /* just use the top of the hierarchy then */
 
 
560
        {
 
 
561
            *targetPtr = firstSectionPtr->World_Offset;
 
 
562
        }
 
 
563
    }
 
 
564
    else
 
 
565
    {
 
 
566
        *targetPtr = objectPtr->ObWorld;
 
 
567
    }
 
 
568
}
 
 
569
 
 
 
570
void GetTargetingPointOfObject_Far(STRATEGYBLOCK *sbPtr, VECTORCH *targetPtr)
 
 
571
{
 
 
572
    /* Can we use the near one?  This is a more general shell. */
 
 
573
    if (sbPtr->DisplayBlock)
 
 
574
    {
 
 
575
        GetTargetingPointOfObject(sbPtr->DisplayBlock,targetPtr);
 
 
576
    }
 
 
577
    else if(sbPtr->DynPtr)
 
 
578
    {
 
 
579
        *targetPtr = sbPtr->DynPtr->Position;
 
 
580
        targetPtr->vy -= 500; /* Just to be on the safe side. */
 
 
581
    }
 
 
582
    #if DEBUG
 
 
583
    else
 
 
584
    {
 
 
585
        /* Aw, gawd! I don't know! There's NO position for this! */
 
 
586
        assert(0);
 
 
587
    }
 
 
588
    #endif
 
 
589
}