annotate src/torp.c @ 19:de685799a432

Made torps wobbly when going through nebulous terrain. Only happens if nebula_effect contains photon.
author darius
date Wed, 24 Dec 1997 12:40:04 +0000
parents 9fda93e18de5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
331055a97a9d Initial revision
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
331055a97a9d Initial revision
darius
parents:
diff changeset
2 NETREK II -- Paradise
331055a97a9d Initial revision
darius
parents:
diff changeset
3
331055a97a9d Initial revision
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
331055a97a9d Initial revision
darius
parents:
diff changeset
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
331055a97a9d Initial revision
darius
parents:
diff changeset
6 purpose and without fee is hereby granted, provided that this copyright
331055a97a9d Initial revision
darius
parents:
diff changeset
7 notice appear in all copies. No representations are made about the
331055a97a9d Initial revision
darius
parents:
diff changeset
8 suitability of this software for any purpose. This software is provided
331055a97a9d Initial revision
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
331055a97a9d Initial revision
darius
parents:
diff changeset
10
331055a97a9d Initial revision
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
331055a97a9d Initial revision
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
331055a97a9d Initial revision
darius
parents:
diff changeset
13 Scott Silvey
331055a97a9d Initial revision
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
331055a97a9d Initial revision
darius
parents:
diff changeset
15 Kurt Olsen
331055a97a9d Initial revision
darius
parents:
diff changeset
16 Brandon Gillespie
331055a97a9d Initial revision
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
18
331055a97a9d Initial revision
darius
parents:
diff changeset
19
331055a97a9d Initial revision
darius
parents:
diff changeset
20 #include "config.h"
331055a97a9d Initial revision
darius
parents:
diff changeset
21
331055a97a9d Initial revision
darius
parents:
diff changeset
22 #include <stdio.h>
331055a97a9d Initial revision
darius
parents:
diff changeset
23 #include <sys/types.h>
331055a97a9d Initial revision
darius
parents:
diff changeset
24 #include <sys/time.h>
331055a97a9d Initial revision
darius
parents:
diff changeset
25
331055a97a9d Initial revision
darius
parents:
diff changeset
26 #include "defs.h"
331055a97a9d Initial revision
darius
parents:
diff changeset
27 #include "struct.h"
331055a97a9d Initial revision
darius
parents:
diff changeset
28 #include "data.h"
331055a97a9d Initial revision
darius
parents:
diff changeset
29 #include "shmem.h"
331055a97a9d Initial revision
darius
parents:
diff changeset
30
331055a97a9d Initial revision
darius
parents:
diff changeset
31
331055a97a9d Initial revision
darius
parents:
diff changeset
32 /*-----------------------------MODULE VARIABLES----------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
33
331055a97a9d Initial revision
darius
parents:
diff changeset
34 static struct timeval lasttp;
331055a97a9d Initial revision
darius
parents:
diff changeset
35
331055a97a9d Initial revision
darius
parents:
diff changeset
36
331055a97a9d Initial revision
darius
parents:
diff changeset
37 #define UGAP 100000 /* microseconds */
331055a97a9d Initial revision
darius
parents:
diff changeset
38
331055a97a9d Initial revision
darius
parents:
diff changeset
39 /*-------------------------------------------------------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
40
331055a97a9d Initial revision
darius
parents:
diff changeset
41
331055a97a9d Initial revision
darius
parents:
diff changeset
42
331055a97a9d Initial revision
darius
parents:
diff changeset
43
331055a97a9d Initial revision
darius
parents:
diff changeset
44
331055a97a9d Initial revision
darius
parents:
diff changeset
45
331055a97a9d Initial revision
darius
parents:
diff changeset
46
331055a97a9d Initial revision
darius
parents:
diff changeset
47
331055a97a9d Initial revision
darius
parents:
diff changeset
48 /*----------------------------VISIBLE FUNCTIONS------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
49
331055a97a9d Initial revision
darius
parents:
diff changeset
50 /*---------------------------------NTORP--------------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
51 /*
19
de685799a432 Made torps wobbly when going through nebulous terrain.
darius
parents: 11
diff changeset
52 * If a set of given conditions are met, fire a single torp in direction
de685799a432 Made torps wobbly when going through nebulous terrain.
darius
parents: 11
diff changeset
53 * course. Type is used because robots are allowed to shoot straight.
de685799a432 Made torps wobbly when going through nebulous terrain.
darius
parents: 11
diff changeset
54 * Torps sent with status TMOVE wobble a bit. TSTRAIGHT torps (fired by
de685799a432 Made torps wobbly when going through nebulous terrain.
darius
parents: 11
diff changeset
55 * robots) move in a straight line.
9
331055a97a9d Initial revision
darius
parents:
diff changeset
56 *
19
de685799a432 Made torps wobbly when going through nebulous terrain.
darius
parents: 11
diff changeset
57 * torp->t_fuse is the life of the torpedo. It is set here based on a
9
331055a97a9d Initial revision
darius
parents:
diff changeset
58 * random function. Torps currently live two to five seconds.
331055a97a9d Initial revision
darius
parents:
diff changeset
59 */
331055a97a9d Initial revision
darius
parents:
diff changeset
60
331055a97a9d Initial revision
darius
parents:
diff changeset
61
331055a97a9d Initial revision
darius
parents:
diff changeset
62 extern void move_torp();
331055a97a9d Initial revision
darius
parents:
diff changeset
63
331055a97a9d Initial revision
darius
parents:
diff changeset
64 void
331055a97a9d Initial revision
darius
parents:
diff changeset
65 ntorp(course, type)
331055a97a9d Initial revision
darius
parents:
diff changeset
66 unsigned char course; /* direction of torp travel */
331055a97a9d Initial revision
darius
parents:
diff changeset
67 int type; /* type of torp flight */
331055a97a9d Initial revision
darius
parents:
diff changeset
68 {
331055a97a9d Initial revision
darius
parents:
diff changeset
69 register int i; /* looping var */
331055a97a9d Initial revision
darius
parents:
diff changeset
70 register struct torp *k; /* to point to a torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
71 register unsigned char buttangle;
331055a97a9d Initial revision
darius
parents:
diff changeset
72
331055a97a9d Initial revision
darius
parents:
diff changeset
73 if (me->p_flags & PFWEP)
331055a97a9d Initial revision
darius
parents:
diff changeset
74 { /* no firing while */
331055a97a9d Initial revision
darius
parents:
diff changeset
75 warning("Torpedo launch tubes have exceeded maximum safe temperature!");
331055a97a9d Initial revision
darius
parents:
diff changeset
76 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
77 }
331055a97a9d Initial revision
darius
parents:
diff changeset
78
331055a97a9d Initial revision
darius
parents:
diff changeset
79 if (!temporally_spaced(&lasttp, UGAP))
331055a97a9d Initial revision
darius
parents:
diff changeset
80 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
81
331055a97a9d Initial revision
darius
parents:
diff changeset
82 if (me->p_ntorp == MAXTORP)
331055a97a9d Initial revision
darius
parents:
diff changeset
83 { /* can't fire more than MAXTORPs */
331055a97a9d Initial revision
darius
parents:
diff changeset
84 warning("Our computers limit us to having 8 live torpedos at a time captain!");
331055a97a9d Initial revision
darius
parents:
diff changeset
85 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
86 }
331055a97a9d Initial revision
darius
parents:
diff changeset
87 if (me->p_fuel < myship->s_torp.cost)
331055a97a9d Initial revision
darius
parents:
diff changeset
88 { /* have to have enough fuel */
331055a97a9d Initial revision
darius
parents:
diff changeset
89 warning("We don't have enough fuel to fire photon torpedos!");
331055a97a9d Initial revision
darius
parents:
diff changeset
90 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
91 }
331055a97a9d Initial revision
darius
parents:
diff changeset
92 if (me->p_flags & PFREPAIR)
331055a97a9d Initial revision
darius
parents:
diff changeset
93 { /* cannot be in reapair mode */
331055a97a9d Initial revision
darius
parents:
diff changeset
94 warning("We cannot fire while our vessel is in repair mode.");
331055a97a9d Initial revision
darius
parents:
diff changeset
95 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
96 }
331055a97a9d Initial revision
darius
parents:
diff changeset
97 if ((me->p_nthingys > 0)
331055a97a9d Initial revision
darius
parents:
diff changeset
98 && (myship->s_nflags & SFNHASFIGHTERS))
331055a97a9d Initial revision
darius
parents:
diff changeset
99 { /* cannot fire if fighters can */
331055a97a9d Initial revision
darius
parents:
diff changeset
100 warning("Fire control systems guiding fighters. No torps available.");
331055a97a9d Initial revision
darius
parents:
diff changeset
101 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
102 }
331055a97a9d Initial revision
darius
parents:
diff changeset
103 if ((me->p_cloakphase) && (me->p_ship.s_type != ATT))
331055a97a9d Initial revision
darius
parents:
diff changeset
104 {
331055a97a9d Initial revision
darius
parents:
diff changeset
105 warning("We are unable to fire while in cloak, captain!");
331055a97a9d Initial revision
darius
parents:
diff changeset
106 return; /* no firing while cloaked unless in an ATT */
331055a97a9d Initial revision
darius
parents:
diff changeset
107 }
331055a97a9d Initial revision
darius
parents:
diff changeset
108 if (!check_fire_warp()
331055a97a9d Initial revision
darius
parents:
diff changeset
109 || !check_fire_warpprep()
331055a97a9d Initial revision
darius
parents:
diff changeset
110 || !check_fire_docked())
331055a97a9d Initial revision
darius
parents:
diff changeset
111 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
112
331055a97a9d Initial revision
darius
parents:
diff changeset
113 me->p_ntorp++; /* inc torps in the air */
331055a97a9d Initial revision
darius
parents:
diff changeset
114 me->p_fuel -= myship->s_torp.cost; /* dec the fuel */
331055a97a9d Initial revision
darius
parents:
diff changeset
115 #ifdef BUTTORP_PENALTY
331055a97a9d Initial revision
darius
parents:
diff changeset
116 /* figure out absolute difference of arc between rear of ship and torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
117 if ((buttangle = course - me->p_dir - 128) > 128)
331055a97a9d Initial revision
darius
parents:
diff changeset
118 buttangle = 256 - buttangle;
331055a97a9d Initial revision
darius
parents:
diff changeset
119
331055a97a9d Initial revision
darius
parents:
diff changeset
120 /* Check if in penalty limit. Ships with no "front" are exempt, of course */
331055a97a9d Initial revision
darius
parents:
diff changeset
121 if (myship->s_type == WARBASE || myship->s_type == STARBASE || myship->s_type ==
331055a97a9d Initial revision
darius
parents:
diff changeset
122 JUMPSHIP || TORP_PENALTY_HALFARC < buttangle)
331055a97a9d Initial revision
darius
parents:
diff changeset
123 {
331055a97a9d Initial revision
darius
parents:
diff changeset
124 me->p_wtemp += myship->s_torp.wtemp;
331055a97a9d Initial revision
darius
parents:
diff changeset
125 }
331055a97a9d Initial revision
darius
parents:
diff changeset
126 else
331055a97a9d Initial revision
darius
parents:
diff changeset
127 {
331055a97a9d Initial revision
darius
parents:
diff changeset
128 /* You call that dogfighting? Bad dog! No biscuit! Bad dog! */
331055a97a9d Initial revision
darius
parents:
diff changeset
129 me->p_wtemp += myship->s_torp.wtemp +
331055a97a9d Initial revision
darius
parents:
diff changeset
130 (myship->s_torp.wtemp *
331055a97a9d Initial revision
darius
parents:
diff changeset
131 (TORP_PENALTY_HALFARC - buttangle) *
331055a97a9d Initial revision
darius
parents:
diff changeset
132 TORP_PENALTY_FACTOR *
331055a97a9d Initial revision
darius
parents:
diff changeset
133 me->p_speed
331055a97a9d Initial revision
darius
parents:
diff changeset
134 ) / (TORP_PENALTY_HALFARC * myship->s_imp.maxspeed);
331055a97a9d Initial revision
darius
parents:
diff changeset
135 }
331055a97a9d Initial revision
darius
parents:
diff changeset
136 #else
331055a97a9d Initial revision
darius
parents:
diff changeset
137 me->p_wtemp += myship->s_torp.wtemp;
331055a97a9d Initial revision
darius
parents:
diff changeset
138 #endif
331055a97a9d Initial revision
darius
parents:
diff changeset
139 for (i = me->p_no * MAXTORP, k = &torps[i]; /* Find a free torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
140 i < me->p_no * MAXTORP + MAXTORP; i++, k++)
331055a97a9d Initial revision
darius
parents:
diff changeset
141 {
331055a97a9d Initial revision
darius
parents:
diff changeset
142 if (k->t_status == TFREE)
331055a97a9d Initial revision
darius
parents:
diff changeset
143 break;
331055a97a9d Initial revision
darius
parents:
diff changeset
144 }
331055a97a9d Initial revision
darius
parents:
diff changeset
145 if ((type > TSTRAIGHT) || (type < TFREE)) /* straight torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
146 type = TMOVE;
331055a97a9d Initial revision
darius
parents:
diff changeset
147 k->t_no = i; /* set torp's number */
331055a97a9d Initial revision
darius
parents:
diff changeset
148 k->t_status = type; /* set torp's type */
331055a97a9d Initial revision
darius
parents:
diff changeset
149 k->t_owner = me->p_no; /* set torp's owner */
331055a97a9d Initial revision
darius
parents:
diff changeset
150 k->t_team = me->p_team; /* set team of owner */
331055a97a9d Initial revision
darius
parents:
diff changeset
151
331055a97a9d Initial revision
darius
parents:
diff changeset
152 move_torp(i, me->p_x, me->p_y, 0);
331055a97a9d Initial revision
darius
parents:
diff changeset
153
331055a97a9d Initial revision
darius
parents:
diff changeset
154 k->t_dir = course; /* set course of torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
155 k->t_damage = myship->s_torp.damage; /* set its damage */
331055a97a9d Initial revision
darius
parents:
diff changeset
156 k->t_speed = myship->s_torp.speed; /* set its speed */
331055a97a9d Initial revision
darius
parents:
diff changeset
157 k->t_war = me->p_hostile | me->p_swar; /* get its war mask */
331055a97a9d Initial revision
darius
parents:
diff changeset
158 k->t_fuse = myship->s_torp.fuse + (lrand48() % 20); /* set fuse */
331055a97a9d Initial revision
darius
parents:
diff changeset
159 k->t_turns = myship->s_torp.aux; /* set how torp tracks */
331055a97a9d Initial revision
darius
parents:
diff changeset
160 }
331055a97a9d Initial revision
darius
parents:
diff changeset
161
331055a97a9d Initial revision
darius
parents:
diff changeset
162 /*-------------------------------------------------------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
163
331055a97a9d Initial revision
darius
parents:
diff changeset
164
331055a97a9d Initial revision
darius
parents:
diff changeset
165
331055a97a9d Initial revision
darius
parents:
diff changeset
166
331055a97a9d Initial revision
darius
parents:
diff changeset
167
331055a97a9d Initial revision
darius
parents:
diff changeset
168
331055a97a9d Initial revision
darius
parents:
diff changeset
169 /*-------END OF FILE--------*/