This is Tracker.h in view mode; [Download] [Up]
// This class tracks the one ship relative to another
// It not only returns information about the "target" ship,
// it will order the 'owning' ship to track it,
// either in position, orientation, or velocity.
#import <appkit/appkit.h>
#import "Actor.h"
#import "Ship.h"
typedef enum {X_AXIS, Y_AXIS, N_AXIS} AXIS;
@interface Tracker:Object
{
Ship* ship;
Actor* to;
float x[N_AXIS];
float v[N_AXIS];
float resolution;
}
// Initialization
- initFor:aShip;
// set ship to track
- track:target;
- ship;
- target;
// set angular resolution on turning
- setResolution:(float) res;
// YES if target is within resolution of my forward facing
- (BOOL) isFacing:(float)angle;
// update values for the targets position and velocity
- update;
// extrapolate where the target will be thus far in the future
- projectForward:(float)time;
- (float) distance;
- (float) angle;
- (float) velocity;
- (float) Vangle; //velocity angle
/*
* Control sequences
* If angle not given, move directly towards target
*/
// Change orientation
- (BOOL) turnTowards;
- (BOOL) turnTowards:(float)angle;
// Change velocity
- (BOOL) thrustTowards;
- (BOOL) thrustTowards:(float)angle;
- (BOOL) matchVelocity;
// Fire if in range
// Minimum range - due to the fact that firing removes shields!
- (BOOL) fireBetween:(float)far :(float)near;
// Turn on shields if within range;
// Don't have on all the time, since they lose energy
- (BOOL) shieldsWithin:(float)distance;
// Move the target to the point where it could be hit
// If a bullet were to leave now in the correction orientation
// Experimental; do not trust
- (BOOL) projectToHit;
@end
// Accessor methods so we don't have to dereference the pointer
@interface Ship (Tracker)
- (float) velocity:(Actor*)to axis:(AXIS)xy;
- (float) distance:(Actor*)to axis:(AXIS)xy;
- (float) angle;
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.