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