5
|
1 /*--------------------------------------------------------------------------
|
|
2 NETREK II -- Paradise
|
|
3
|
|
4 Permission to use, copy, modify, and distribute this software and its
|
|
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
|
|
6 purpose and without fee is hereby granted, provided that this copyright
|
|
7 notice appear in all copies. No representations are made about the
|
|
8 suitability of this software for any purpose. This software is provided
|
|
9 "as is" without express or implied warranty.
|
|
10
|
|
11 Xtrek Copyright 1986 Chris Guthrie
|
|
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
|
|
13 Scott Silvey
|
|
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
|
|
15 Kurt Olsen
|
|
16 Brandon Gillespie
|
|
17 --------------------------------------------------------------------------*/
|
|
18
|
|
19 #include "config.h"
|
|
20 #include <stdio.h>
|
|
21 #include <sys/types.h>
|
|
22 #include <sys/time.h>
|
|
23
|
|
24 #include "defs.h"
|
|
25 #include "struct.h"
|
|
26 #include "data.h"
|
|
27 #include "shmem.h"
|
|
28
|
|
29 #include "grid.h"
|
|
30
|
|
31
|
|
32
|
|
33
|
|
34
|
|
35 /*-----------------------------MODULE VARIABLES----------------------------*/
|
|
36 static struct timeval lasttime; /* used to prevent players from */
|
|
37 /* firing too quickly */
|
|
38
|
|
39 #define UGAP 100000 /* gap between missile firings, microseconds */
|
|
40 /*-------------------------------------------------------------------------*/
|
|
41
|
|
42
|
|
43
|
|
44
|
|
45
|
|
46
|
|
47
|
|
48
|
|
49 /*----------------------------VISIBLE FUNCTIONS------------------------*/
|
|
50
|
|
51 /*------------------------------FIRE_MISSILE-----------------------------*/
|
|
52 /*
|
|
53 * If a set of given conditions are met, fire a single missile in direction *
|
|
54 * course. *
|
|
55 *
|
|
56 * torp->t_fuse is the life of the missile.
|
|
57 */
|
|
58
|
|
59 void
|
|
60 fire_missile_dir(course)
|
|
61 unsigned char course; /* direction of torp travel */
|
|
62 {
|
|
63 register int i; /* looping var */
|
|
64 register struct missile *drn; /* to point to a torp */
|
|
65 int max;
|
|
66
|
|
67 if (weaponsallowed[WP_MISSILE] == 0)
|
|
68 {
|
|
69 warning("Missiles haven't been invented yet.");
|
|
70 return;
|
|
71 }
|
|
72 if ((weaponsallowed[WP_FIGHTER] == 0) && (me->p_ship.s_nflags & SFNHASFIGHTERS))
|
|
73 {
|
|
74 warning("Fighters haven't been invented yet.");
|
|
75 return;
|
|
76 }
|
|
77 if (0 == shipvals[me->p_ship.s_type].s_missile.count)
|
|
78 {
|
|
79 warning("This ship can't mount a missile rack");
|
|
80 return;
|
|
81 }
|
|
82 if (!(me->p_specweap & SFNHASMISSILE))
|
|
83 {
|
|
84 warning("Our ship is not equipped with a missile rack");
|
|
85 return;
|
|
86 }
|
|
87 if (me->p_ship.s_missilestored == 0)
|
|
88 {
|
|
89 warning("Our missile rack is empty!");
|
|
90 return;
|
|
91 }
|
|
92 if (me->p_flags & PFWEP)
|
|
93 { /* no firing while */
|
|
94 warning("Torpedo launch tubes have exceeded maximum safe temperature!");
|
|
95 return;
|
|
96 }
|
|
97 if (me->p_flags & PFREPAIR)
|
|
98 { /* cannot be in repair mode */
|
|
99 warning("We cannot fire while our vessel is in repair mode.");
|
|
100 return;
|
|
101 }
|
|
102 if ((me->p_cloakphase) && (me->p_ship.s_type != ATT))
|
|
103 {
|
|
104 warning("We are unable to fire while in cloak, captain!");
|
|
105 return; /* no firing while cloaked unless in an ATT */
|
|
106 }
|
|
107 if ((me->p_ship.s_nflags & SFNHASFIGHTERS) &&
|
|
108 (me->p_ntorp > 0))
|
|
109 {
|
|
110 warning("Flight crews rearming fighters, be patient (wait for torps to die)");
|
|
111 return; /* can't do both fighters and torps */
|
|
112 }
|
|
113
|
|
114 if (!check_fire_warp()
|
|
115 || !check_fire_warpprep()
|
|
116 || !check_fire_docked())
|
|
117 return;
|
|
118
|
|
119 if (!temporally_spaced(&lasttime, UGAP))
|
|
120 return;
|
|
121
|
|
122 max = NPTHINGIES;
|
|
123 if (me->p_ship.s_missile.count < max)
|
|
124 max = me->p_ship.s_missile.count;
|
|
125
|
|
126 for (i = 0, drn = &missiles[me->p_no * NPTHINGIES]; i < max; i++, drn++)
|
|
127 {
|
|
128 if (drn->ms_status == TFREE || drn->ms_status == TLAND)
|
|
129 break;
|
|
130 }
|
|
131
|
|
132 if (i >= max)
|
|
133 {
|
|
134 char buf[120];
|
|
135
|
|
136 if (myship->s_nflags & SFNHASFIGHTERS)
|
|
137 sprintf(buf, "Maximum of %d fighters in a squadron.", max);
|
|
138 else
|
|
139 sprintf(buf, "Our computers limit us to %d missiles at a time", max);
|
|
140 warning(buf);
|
|
141 return;
|
|
142 }
|
|
143 if (me->p_fuel < myship->s_missile.cost)
|
|
144 { /* have to have enough fuel */
|
|
145 if (myship->s_nflags & SFNHASFIGHTERS)
|
|
146 warning("No fuel can be spared to send out fighters!");
|
|
147 else
|
|
148 warning("We don't have enough fuel to launch a missile!");
|
|
149 return;
|
|
150 }
|
|
151 if (me->p_ship.s_missilestored > 0)
|
|
152 {
|
|
153 char buf[80];
|
|
154 me->p_ship.s_missilestored--; /* use up a missile in the rack */
|
|
155 if (myship->s_nflags & SFNHASFIGHTERS)
|
|
156 {
|
|
157 me->p_armies = (int) (me->p_ship.s_missilestored / FAE_RATE);
|
|
158 sprintf(buf, "Fighter launched. %d left", me->p_ship.s_missilestored);
|
|
159 }
|
|
160 else
|
|
161 sprintf(buf, "Missile away. %d left", me->p_ship.s_missilestored);
|
|
162 warning(buf);
|
|
163 }
|
|
164 me->p_fuel -= myship->s_missile.cost; /* dec the fuel */
|
|
165 me->p_wtemp += myship->s_missile.wtemp; /* Heat weapons */
|
|
166
|
|
167
|
|
168 drn->ms_no = drn - missiles; /* set torp's number */
|
|
169 drn->ms_status = TMOVE; /* set torp's type */
|
|
170 drn->ms_owner = me->p_no; /* set torp's owner */
|
|
171
|
|
172 move_missile(drn->ms_no, me->p_x, me->p_y, 0);
|
|
173
|
|
174 /* Fighters get launched in "groups" of four --> +/- 30',60' */
|
|
175 /* It might be a good idea to make this launch pattern thing a #define */
|
|
176 /* Maybe even a macro with a pattern, so they can go in groups of 2,3,etc */
|
|
177
|
|
178 if (myship->s_nflags & SFNHASFIGHTERS)
|
|
179 {
|
|
180 if (((drn->ms_no) % NPTHINGIES) % 4 == 1)
|
|
181 drn->ms_dir = me->p_dir + 16;
|
|
182 else if (((drn->ms_no) % NPTHINGIES) % 4 == 2)
|
|
183 drn->ms_dir = me->p_dir - 48;
|
|
184 else if (((drn->ms_no) % NPTHINGIES) % 4 == 3)
|
|
185 drn->ms_dir = me->p_dir + 48;
|
|
186 else
|
|
187 drn->ms_dir = me->p_dir - 16; /* set course of torp */
|
|
188 }
|
|
189 else if (myship->s_nflags & SFNMASSPRODUCED)
|
|
190 drn->ms_dir = me->p_dir; /* PTs only fire forward */
|
|
191 else
|
|
192 drn->ms_dir = course;
|
|
193
|
|
194 drn->ms_damage = myship->s_missile.damage; /* set its damage */
|
|
195 drn->ms_speed = myship->s_missile.speed; /* set its speed */
|
|
196 drn->ms_fuse = myship->s_missile.fuse + (lrand48() % 20); /* set fuse */
|
|
197 drn->ms_war = me->p_hostile | me->p_swar; /* get its war mask */
|
|
198 drn->ms_team = me->p_team; /* set team of owner */
|
|
199 drn->fi_hasfired = 0;
|
|
200 if (myship->s_nflags & SFNHASFIGHTERS)
|
|
201 { /* If sfnhasfighters is set */
|
|
202 drn->ms_type = FIGHTERTHINGY; /* the missile is a fighter. */
|
|
203 }
|
|
204 else
|
|
205 {
|
|
206 drn->ms_type = MISSILETHINGY;
|
|
207 }
|
|
208
|
|
209 drn->ms_turns = myship->s_missile.aux; /* set how torp tracks */
|
|
210 drn->ms_locked = -1;
|
|
211 me->p_nthingys++; /* we own another thingy */
|
|
212 }
|
|
213
|
|
214 /*-------------------------------------------------------------------------*/
|
|
215
|
|
216
|
|
217
|
|
218
|
|
219
|
|
220
|
|
221 /*-------END OF FILE--------*/
|