Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
DropShipAI.cpp
Go to the documentation of this file.
1
/* Project Starshatter 4.5
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: DropShipAI.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Drop Ship (orbit/surface and surface/orbit) AI class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
DropShipAI.h
"
17
#include "
TacticalAI.h
"
18
#include "
Ship.h
"
19
#include "
ShipCtrl.h
"
20
#include "
Drive.h
"
21
#include "
Sim.h
"
22
#include "
StarSystem.h
"
23
#include "
KeyMap.h
"
24
25
#include "
Game.h
"
26
27
// +----------------------------------------------------------------------+
28
29
DropShipAI::DropShipAI
(
Ship
* s)
30
:
ShipAI
(s)
31
{
32
seek_gain
= 20;
33
seek_damp
= 0.5;
34
35
delete
tactical
;
36
tactical
= 0;
37
}
38
39
DropShipAI::~DropShipAI
()
40
{
41
}
42
43
// +--------------------------------------------------------------------+
44
45
void
46
DropShipAI::FindObjective
()
47
{
48
distance
= 0;
49
50
if
(!
ship
)
return
;
51
52
Sim
* sim =
Sim::GetSim
();
53
SimRegion
* self_rgn =
ship
->
GetRegion
();
54
55
// if making orbit, go up:
56
if
(self_rgn->
Type
() ==
Sim::AIR_SPACE
) {
57
obj_w
=
self
->Location() +
Point
(0, 1e3, 0);
58
}
59
60
// if breaking orbit, head for terrain region:
61
else
{
62
SimRegion
* dst_rgn = sim->
FindNearestTerrainRegion
(
ship
);
63
Point
dst = dst_rgn->
GetOrbitalRegion
()->
Location
() -
64
self_rgn->
GetOrbitalRegion
()->
Location
() +
65
Point
(0, 0, -1e6);
66
67
obj_w
= dst.
OtherHand
();
68
}
69
70
// distance from self to navpt:
71
distance
=
Point
(
obj_w
-
self
->
Location
()).length();
72
73
// transform into camera coords:
74
objective
=
Transform
(
obj_w
);
75
objective
.
Normalize
();
76
}
77
78
// +--------------------------------------------------------------------+
79
80
void
81
DropShipAI::Navigator
()
82
{
83
accumulator
.
Clear
();
84
magnitude
= 0;
85
86
if
(
other
)
87
ship
->
SetFLCSMode
(
Ship::FLCS_AUTO
);
88
else
89
ship
->
SetFLCSMode
(
Ship::FLCS_MANUAL
);
90
91
Accumulate
(
AvoidCollision
());
92
Accumulate
(
Seek
(
objective
));
93
94
// are we being asked to flee?
95
if
(fabs(
accumulator
.
yaw
) == 1.0 &&
accumulator
.
pitch
== 0.0) {
96
accumulator
.
pitch
= -0.7f;
97
accumulator
.
yaw
*= 0.25f;
98
}
99
100
self
->ApplyRoll((
float
) (
accumulator
.
yaw
* -0.4));
101
self
->ApplyYaw((
float
) (
accumulator
.
yaw
* 0.2));
102
103
if
(fabs(
accumulator
.
yaw
) > 0.5 && fabs(
accumulator
.
pitch
) < 0.1)
104
accumulator
.
pitch
-= 0.1f;
105
106
if
(
accumulator
.
pitch
!= 0)
107
self
->ApplyPitch((
float
)
accumulator
.
pitch
);
108
109
// if not turning, roll to orient with world coords:
110
if
(fabs(
accumulator
.
yaw
) < 0.1) {
111
Point
vrt = ((
Camera
*) &(
self
->
Cam
()))->vrt();
112
double
deflection = vrt.
y
;
113
if
(deflection != 0) {
114
double
theta = asin(deflection/vrt.
length
());
115
self
->ApplyRoll(-theta);
116
}
117
}
118
119
ship
->
SetThrottle
(100);
120
ship
->
ExecFLCSFrame
();
121
}
122
Stars45
DropShipAI.cpp
Generated on Tue Jun 5 2012 20:46:52 for Starshatter_Open by
1.8.1