annotate src/torp.c @ 11:9fda93e18de5

Testing CVS in xEmacs
author darius
date Sat, 06 Dec 1997 04:46:49 +0000
parents 331055a97a9d
children de685799a432
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
11
9fda93e18de5 Testing CVS in xEmacs
darius
parents: 9
diff changeset
31 /* Foo */
9
331055a97a9d Initial revision
darius
parents:
diff changeset
32
331055a97a9d Initial revision
darius
parents:
diff changeset
33
331055a97a9d Initial revision
darius
parents:
diff changeset
34 /*-----------------------------MODULE VARIABLES----------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
35
331055a97a9d Initial revision
darius
parents:
diff changeset
36 static struct timeval lasttp;
331055a97a9d Initial revision
darius
parents:
diff changeset
37
331055a97a9d Initial revision
darius
parents:
diff changeset
38
331055a97a9d Initial revision
darius
parents:
diff changeset
39 #define UGAP 100000 /* microseconds */
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
331055a97a9d Initial revision
darius
parents:
diff changeset
49
331055a97a9d Initial revision
darius
parents:
diff changeset
50 /*----------------------------VISIBLE FUNCTIONS------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
51
331055a97a9d Initial revision
darius
parents:
diff changeset
52 /*---------------------------------NTORP--------------------------------*/
331055a97a9d Initial revision
darius
parents:
diff changeset
53 /*
331055a97a9d Initial revision
darius
parents:
diff changeset
54 * If a set of given conditions are met, fire a single torp in direction *
331055a97a9d Initial revision
darius
parents:
diff changeset
55 * course. Type is used because robots are allowed to shoot straight. *
331055a97a9d Initial revision
darius
parents:
diff changeset
56 * Torps sent with status TMOVE wobble a bit. TSTRAIGHT torps (fired * by
331055a97a9d Initial revision
darius
parents:
diff changeset
57 * robots) move in a straight line. *
331055a97a9d Initial revision
darius
parents:
diff changeset
58 *
331055a97a9d Initial revision
darius
parents:
diff changeset
59 * torp->t_fuse is the life of the torpedo. It is set here based on * a
331055a97a9d Initial revision
darius
parents:
diff changeset
60 * random function. Torps currently live two to five seconds.
331055a97a9d Initial revision
darius
parents:
diff changeset
61 */
331055a97a9d Initial revision
darius
parents:
diff changeset
62
331055a97a9d Initial revision
darius
parents:
diff changeset
63
331055a97a9d Initial revision
darius
parents:
diff changeset
64 extern void move_torp();
331055a97a9d Initial revision
darius
parents:
diff changeset
65
331055a97a9d Initial revision
darius
parents:
diff changeset
66 void
331055a97a9d Initial revision
darius
parents:
diff changeset
67 ntorp(course, type)
331055a97a9d Initial revision
darius
parents:
diff changeset
68 unsigned char course; /* direction of torp travel */
331055a97a9d Initial revision
darius
parents:
diff changeset
69 int type; /* type of torp flight */
331055a97a9d Initial revision
darius
parents:
diff changeset
70 {
331055a97a9d Initial revision
darius
parents:
diff changeset
71 register int i; /* looping var */
331055a97a9d Initial revision
darius
parents:
diff changeset
72 register struct torp *k; /* to point to a torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
73 register unsigned char buttangle;
331055a97a9d Initial revision
darius
parents:
diff changeset
74
331055a97a9d Initial revision
darius
parents:
diff changeset
75 if (me->p_flags & PFWEP)
331055a97a9d Initial revision
darius
parents:
diff changeset
76 { /* no firing while */
331055a97a9d Initial revision
darius
parents:
diff changeset
77 warning("Torpedo launch tubes have exceeded maximum safe temperature!");
331055a97a9d Initial revision
darius
parents:
diff changeset
78 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
79 }
331055a97a9d Initial revision
darius
parents:
diff changeset
80
331055a97a9d Initial revision
darius
parents:
diff changeset
81 if (!temporally_spaced(&lasttp, UGAP))
331055a97a9d Initial revision
darius
parents:
diff changeset
82 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
83
331055a97a9d Initial revision
darius
parents:
diff changeset
84 if (me->p_ntorp == MAXTORP)
331055a97a9d Initial revision
darius
parents:
diff changeset
85 { /* can't fire more than MAXTORPs */
331055a97a9d Initial revision
darius
parents:
diff changeset
86 warning("Our computers limit us to having 8 live torpedos at a time captain!");
331055a97a9d Initial revision
darius
parents:
diff changeset
87 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
88 }
331055a97a9d Initial revision
darius
parents:
diff changeset
89 if (me->p_fuel < myship->s_torp.cost)
331055a97a9d Initial revision
darius
parents:
diff changeset
90 { /* have to have enough fuel */
331055a97a9d Initial revision
darius
parents:
diff changeset
91 warning("We don't have enough fuel to fire photon torpedos!");
331055a97a9d Initial revision
darius
parents:
diff changeset
92 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
93 }
331055a97a9d Initial revision
darius
parents:
diff changeset
94 if (me->p_flags & PFREPAIR)
331055a97a9d Initial revision
darius
parents:
diff changeset
95 { /* cannot be in reapair mode */
331055a97a9d Initial revision
darius
parents:
diff changeset
96 warning("We cannot fire while our vessel is in repair mode.");
331055a97a9d Initial revision
darius
parents:
diff changeset
97 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
98 }
331055a97a9d Initial revision
darius
parents:
diff changeset
99 if ((me->p_nthingys > 0)
331055a97a9d Initial revision
darius
parents:
diff changeset
100 && (myship->s_nflags & SFNHASFIGHTERS))
331055a97a9d Initial revision
darius
parents:
diff changeset
101 { /* cannot fire if fighters can */
331055a97a9d Initial revision
darius
parents:
diff changeset
102 warning("Fire control systems guiding fighters. No torps available.");
331055a97a9d Initial revision
darius
parents:
diff changeset
103 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
104 }
331055a97a9d Initial revision
darius
parents:
diff changeset
105 if ((me->p_cloakphase) && (me->p_ship.s_type != ATT))
331055a97a9d Initial revision
darius
parents:
diff changeset
106 {
331055a97a9d Initial revision
darius
parents:
diff changeset
107 warning("We are unable to fire while in cloak, captain!");
331055a97a9d Initial revision
darius
parents:
diff changeset
108 return; /* no firing while cloaked unless in an ATT */
331055a97a9d Initial revision
darius
parents:
diff changeset
109 }
331055a97a9d Initial revision
darius
parents:
diff changeset
110 if (!check_fire_warp()
331055a97a9d Initial revision
darius
parents:
diff changeset
111 || !check_fire_warpprep()
331055a97a9d Initial revision
darius
parents:
diff changeset
112 || !check_fire_docked())
331055a97a9d Initial revision
darius
parents:
diff changeset
113 return;
331055a97a9d Initial revision
darius
parents:
diff changeset
114
331055a97a9d Initial revision
darius
parents:
diff changeset
115 me->p_ntorp++; /* inc torps in the air */
331055a97a9d Initial revision
darius
parents:
diff changeset
116 me->p_fuel -= myship->s_torp.cost; /* dec the fuel */
331055a97a9d Initial revision
darius
parents:
diff changeset
117 #ifdef BUTTORP_PENALTY
331055a97a9d Initial revision
darius
parents:
diff changeset
118 /* figure out absolute difference of arc between rear of ship and torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
119 if ((buttangle = course - me->p_dir - 128) > 128)
331055a97a9d Initial revision
darius
parents:
diff changeset
120 buttangle = 256 - buttangle;
331055a97a9d Initial revision
darius
parents:
diff changeset
121
331055a97a9d Initial revision
darius
parents:
diff changeset
122 /* Check if in penalty limit. Ships with no "front" are exempt, of course */
331055a97a9d Initial revision
darius
parents:
diff changeset
123 if (myship->s_type == WARBASE || myship->s_type == STARBASE || myship->s_type ==
331055a97a9d Initial revision
darius
parents:
diff changeset
124 JUMPSHIP || TORP_PENALTY_HALFARC < buttangle)
331055a97a9d Initial revision
darius
parents:
diff changeset
125 {
331055a97a9d Initial revision
darius
parents:
diff changeset
126 me->p_wtemp += myship->s_torp.wtemp;
331055a97a9d Initial revision
darius
parents:
diff changeset
127 }
331055a97a9d Initial revision
darius
parents:
diff changeset
128 else
331055a97a9d Initial revision
darius
parents:
diff changeset
129 {
331055a97a9d Initial revision
darius
parents:
diff changeset
130 /* You call that dogfighting? Bad dog! No biscuit! Bad dog! */
331055a97a9d Initial revision
darius
parents:
diff changeset
131 me->p_wtemp += myship->s_torp.wtemp +
331055a97a9d Initial revision
darius
parents:
diff changeset
132 (myship->s_torp.wtemp *
331055a97a9d Initial revision
darius
parents:
diff changeset
133 (TORP_PENALTY_HALFARC - buttangle) *
331055a97a9d Initial revision
darius
parents:
diff changeset
134 TORP_PENALTY_FACTOR *
331055a97a9d Initial revision
darius
parents:
diff changeset
135 me->p_speed
331055a97a9d Initial revision
darius
parents:
diff changeset
136 ) / (TORP_PENALTY_HALFARC * myship->s_imp.maxspeed);
331055a97a9d Initial revision
darius
parents:
diff changeset
137 }
331055a97a9d Initial revision
darius
parents:
diff changeset
138 #else
331055a97a9d Initial revision
darius
parents:
diff changeset
139 me->p_wtemp += myship->s_torp.wtemp;
331055a97a9d Initial revision
darius
parents:
diff changeset
140 #endif
331055a97a9d Initial revision
darius
parents:
diff changeset
141 for (i = me->p_no * MAXTORP, k = &torps[i]; /* Find a free torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
142 i < me->p_no * MAXTORP + MAXTORP; i++, k++)
331055a97a9d Initial revision
darius
parents:
diff changeset
143 {
331055a97a9d Initial revision
darius
parents:
diff changeset
144 if (k->t_status == TFREE)
331055a97a9d Initial revision
darius
parents:
diff changeset
145 break;
331055a97a9d Initial revision
darius
parents:
diff changeset
146 }
331055a97a9d Initial revision
darius
parents:
diff changeset
147 if ((type > TSTRAIGHT) || (type < TFREE)) /* straight torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
148 type = TMOVE;
331055a97a9d Initial revision
darius
parents:
diff changeset
149 k->t_no = i; /* set torp's number */
331055a97a9d Initial revision
darius
parents:
diff changeset
150 k->t_status = type; /* set torp's type */
331055a97a9d Initial revision
darius
parents:
diff changeset
151 k->t_owner = me->p_no; /* set torp's owner */
331055a97a9d Initial revision
darius
parents:
diff changeset
152 k->t_team = me->p_team; /* set team of owner */
331055a97a9d Initial revision
darius
parents:
diff changeset
153
331055a97a9d Initial revision
darius
parents:
diff changeset
154 move_torp(i, me->p_x, me->p_y, 0);
331055a97a9d Initial revision
darius
parents:
diff changeset
155
331055a97a9d Initial revision
darius
parents:
diff changeset
156 k->t_dir = course; /* set course of torp */
331055a97a9d Initial revision
darius
parents:
diff changeset
157 k->t_damage = myship->s_torp.damage; /* set its damage */
331055a97a9d Initial revision
darius
parents:
diff changeset
158 k->t_speed = myship->s_torp.speed; /* set its speed */
331055a97a9d Initial revision
darius
parents:
diff changeset
159 k->t_war = me->p_hostile | me->p_swar; /* get its war mask */
331055a97a9d Initial revision
darius
parents:
diff changeset
160 k->t_fuse = myship->s_torp.fuse + (lrand48() % 20); /* set fuse */
331055a97a9d Initial revision
darius
parents:
diff changeset
161 k->t_turns = myship->s_torp.aux; /* set how torp tracks */
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
331055a97a9d Initial revision
darius
parents:
diff changeset
170
331055a97a9d Initial revision
darius
parents:
diff changeset
171 /*-------END OF FILE--------*/