forked from electronicarts/CnC_Tiberian_Dawn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFUSE.CPP
196 lines (179 loc) · 12 KB
/
FUSE.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
/*
** Command & Conquer(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Header: F:\projects\c&c\vcs\code\fuse.cpv 2.18 16 Oct 1995 16:50:46 JOE_BOSTIC $ */
/***********************************************************************************************
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
***********************************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : FUSE.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : April 24, 1994 *
* *
* Last Update : October 17, 1994 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* FuseClass::Arm_Fuse -- Sets up fuse for detonation check. *
* FuseClass::Fuse_Checkup -- Determines if the fuse triggers. *
* FuseClass::Fuse_Write -- Writes the fuse data to the save game file. *
* FuseClass::Fuse_Read -- Reads the fuse class data from the save game file. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/***********************************************************************************************
* FuseClass::FuseClass -- Constructor. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/27/1995 BRR : Created. Gosh, what a lotta work. *
*=============================================================================================*/
FuseClass::FuseClass(void)
{
Timer = 0;
Arming = 0;
HeadTo = 0;
Proximity = 0;
}
/***********************************************************************************************
* FuseClass::Arm_Fuse -- Sets up fuse for detonation check. *
* *
* This starts a fuse. Fuses are proximity detonation variety but *
* can be modified to have a minimum time to elapse before detonation *
* and a maximum time to exist before detonation. Typically, the *
* timing values are used for missiles that have a minimum arming *
* distance and a limited amount of fuel. *
* *
* INPUT: location -- The coordinate where the projectile start. This *
* is needed for proper proximity tracking. *
* *
* target -- The actual impact point. Fuses are based on real *
* word coordinates. *
* *
* time -- The maximum time that the fuse may work before *
* explosion is forced. *
* *
* arming -- The minimum time that must elapse before the *
* fuse may explode. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 04/24/1994 JLB : Created. *
*=============================================================================================*/
void FuseClass::Arm_Fuse(COORDINATE location, COORDINATE target, int timeto, int arming)
{
timeto = MAX(timeto, arming);
Timer = MIN(timeto, 0xFF);
Arming = MIN(arming, 0xFF);
HeadTo = target;
Proximity = Distance(location, target);
}
/***********************************************************************************************
* FuseClass::Fuse_Checkup -- Determines if the fuse triggers. *
* *
* This will process the fuse and update the internal clocks as well *
* as check to see if the fuse should trigger (explode) or not. *
* *
* INPUT: newlocation -- The new location of the fuse. This is needed *
* to determine proximity explosions. *
* *
* OUTPUT: bool; Was the fuse triggered to explode now? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 04/24/1994 JLB : Created. *
*=============================================================================================*/
bool FuseClass::Fuse_Checkup(COORDINATE newlocation)
{
int proximity;
/*
** Always decrement the fuse timer.
*/
if (Timer) Timer--;
/*
** If the arming countdown has not expired, then do nothing.
*/
if (Arming) {
Arming--;
} else {
/*
** If the timer has run out, then the warhead explodes.
*/
if (!Timer) return(true);
proximity = Distance(newlocation, HeadTo);
if (proximity < 0x0010) return(true);
if (proximity < ICON_LEPTON_W && proximity > Proximity) {
return(true);
}
Proximity = proximity;
}
return(false);
}
/***********************************************************************************************
* FuseClass::Fuse_Write -- Writes the fuse data to the save game file. *
* *
* Use this routine to output the fuse class data to the save game file specified. *
* *
* INPUT: file -- The file to output the data to. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
*=============================================================================================*/
void FuseClass::Fuse_Write(FileClass & file)
{
file.Write(&Timer, sizeof(Timer));
file.Write(&Arming, sizeof(Arming));
file.Write(&HeadTo, sizeof(HeadTo));
file.Write(&Proximity, sizeof(Proximity));
}
/***********************************************************************************************
* FuseClass::Fuse_Read -- Reads the fuse class data from the save game file. *
* *
* Use this routine to input the fuse class data from the save game file specified. *
* *
* INPUT: file -- The file to input the data from. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
*=============================================================================================*/
void FuseClass::Fuse_Read(FileClass & file)
{
file.Read(&Timer, sizeof(Timer));
file.Read(&Arming, sizeof(Arming));
file.Read(&HeadTo, sizeof(HeadTo));
file.Read(&Proximity, sizeof(Proximity));
}