annotate src/missile.c @ 16:e246e5730173

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