Avionics
Dropship Simulator
TCAS.cpp
Go to the documentation of this file.
1 #include "Module.h"
2 
3 Tcas::Tcas(Bus* prmBus): Module(prmBus)
4 {
5 }
6 
7 void Tcas::FrameMove(float fElapsed)
8 {
9  for (UINT i = 0; i < bus->commandStream.size(); i++)
10  {
11  Command command = bus->commandStream.at(i);
12  if (command.delay != 0.0f) continue;
13 
14  if (command.name == "TcasSystemTest" && testProgress == 0)
15  {
16  testProgress = 1;
17  bus->commandStream.erase(bus->commandStream.begin() + i);
18  }
19  }
20 
21  if (testProgress > 0)
22  {
23  secsincelast += fElapsed;
24  if (secsincelast >= 2.0f)
25  {
26  secsincelast = 0.0f;
27  Command command;
28  switch (testProgress)
29  {
30  case 1: command.name = "TrafficTraffic";
31  break;
32  case 2: command.name = "ClimbClimb";
33  break;
34  case 3: command.name = "DescendDescend";
35  break;
36  case 4: command.name = "IncreaseClimb";
37  break;
38  case 5: command.name = "IncreaseDescent";
39  break;
40  case 6: command.name = "ReduceClimb";
41  break;
42  case 7: command.name = "ReduceDescent";
43  break;
44  case 8: command.name = "ClimbClimbNow";
45  break;
46  case 9: command.name = "DescendDescendNow";
47  break;
48  case 10: command.name = "MaintainVerticalSpeedMaintain";
49  secsincelast = -1.0f;
50  break;
51  case 11: command.name = "AdjustVerticalSpeedAdjust";
52  secsincelast = -1.0f;
53  break;
54  case 12: command.name = "MonitorVerticalSpeed";
55  break;
56  case 13: command.name = "Crossing";
57  secsincelast = 0.5f;
58  break;
59  case 14: command.name = "ClearOfConflict";
60  break;
61  case 15: command.name = "TcasSystemTestOk";
62  break;
63  }
64  bus->commandStream.push_back(command);
65  testProgress++;
66  if (testProgress == 16)
67  testProgress = 0;
68  }
69  }
70 
71  /*
72 inhibited below 1000 feet
73 inhibited by gpws
74 
75 
76 static char tcasmode=0;
77 if (!epgwc && game->tcastime<99.0f)
78 {
79 swprintf_s(gpwsmsg, 32, L"TCAS TTI %.0f", game->tcastime);
80 if ((flasher>0.0f && oldflasher<=0.0f) || (flasher>0.2f && oldflasher<=0.2f))
81 tempcolor=0xFFFFFF00;
82 else
83 tempcolor=0xFFC4C400;
84 }
85 if (secsincelast>=2.0f) // last spoke
86 {
87 char oldtcasmode=tcasmode;
88 if (game->tcastime<25.0f && tcasmode>0) // must issue traffic traffic first
89 {
90 if (oldtcasmode==2 || oldtcasmode==3) // already issued RA
91 tcasmode=4;
92 else if (game->tcastgtC!=-1)
93 {
94 D3DXVECTOR3 result1;
95 D3DXVec3Subtract( &result1, &playerships[ourcockpit.ourshipC].position, &playerships[game->tcastgtC].position );
96 D3DXVec3TransformCoord( &result1, &result1, &game->matrixView );
97 
98 if (result1.z!=0.0f)
99 {
100 float bear=D3DXToDegree( atanf( result1.x/result1.z ) );
101 float mark=D3DXToDegree( atanf( result1.y/result1.z ) );
102 float f_temp=sqrtf(mark*mark+bear*bear);
103 if (f_temp>180.0f)
104 {
105 f_temp=180.0f/f_temp;
106 mark*=f_temp; bear*=f_temp;
107 }
108 if (result1.z>0.0f) // Behind us
109 {
110 if (bear>0.0f)
111 bear-=180.0f;
112 else
113 bear+=180.0f;
114 mark=-mark;
115 }
116 if (mark<0.0f)
117 tcasmode=2; // climb
118 else
119 tcasmode=3; // descend
120 }
121 }
122 }
123 else if (game->tcastime<40.0f) // must be online, not a gv, closure time
124 {
125 tcasmode=1; // traffic traffic
126 if (oldtcasmode!=1)
127 {
128 // flash traffic
129 char msg[999];
130 sprintf_s(msg, 999, "TCAS* flash traffic %i (%i) now %.1f away (%f km) debug %i\n",
131 game->tcastgtC, playerships[game->tcastgtC].vehicle, game->tcastime, playerships[game->tcastgtC].distance, playerships[game->tcastgtC].reference);
132 _write(logfile, msg, strlen(msg));
133 }
134 }
135 else // greater than 40
136 {
137 static float coctime=0.0f;
138 coctime+=fElapsedTime;
139 if (coctime>10.0f || tcasmode==0)
140 {
141 tcasmode=0; // clear of conflict
142 coctime=0.0f;
143 }
144 else
145 tcasmode=5; // waiting to clear?
146 }
147 
148 
149 if ((tcasmode!=oldtcasmode && (tcasmode>oldtcasmode || tcasmode==0)) ||
150 tcasmode==4)
151 {
152 if (tcasmode!=5 && ourcockpit.power>0.5f)
153 {
154 SClientPacket outpacket;
155 outpacket.type=10; // sound effect
156 outpacket.f_x=19.0f; // TCAS
157 outpacket.f_y=(float)tcasmode; //
158 outpacket.f_z=0.0f;
159 outpacket.f_w=0.0f;
160 game->SendPacket( &outpacket, sizeof(SClientPacket), true, 0 );
161 secsincelast=0.0f;
162 }
163 }
164 }
165 // END OF TCAS
166 */
167 }
std::vector< Command > commandStream
Definition: Bus.h:20
float secsincelast
Definition: Module.h:52
Definition: Bus.h:12
std::string name
command name
Definition: Command.h:11
Abstract base class for modules By definition, instruments don&#39;t do any of the work (they don&#39;t modif...
Definition: Module.h:11
Tcas(Bus *prmBus)
Definition: TCAS.cpp:3
Definition: Command.h:5
Bus * bus
Definition: Module.h:17
int testProgress
Definition: Module.h:53
float delay
wait number of seconds before executing command
Definition: Command.h:8
void FrameMove(float fElapsedTime) override
Definition: TCAS.cpp:7