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