comparison src/orbit.c @ 4:aa38447a4b21

First entry of Paradise Server 2.9 patch 10 Beta
author darius
date Sat, 06 Dec 1997 04:37:03 +0000
parents
children
comparison
equal deleted inserted replaced
3:cafa94d86546 4:aa38447a4b21
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 #include "config.h"
20 #include <stdio.h>
21 #include <math.h>
22 #include <sys/types.h>
23 #include <sys/ipc.h>
24 #include <sys/shm.h>
25
26 #include "defs.h"
27 #include "struct.h"
28 #include "data.h"
29 #include "shmem.h"
30
31
32 void newdock();
33 extern void move_player();
34
35 static void
36 deactivate_friendly_tractors()
37 {
38 int i;
39 struct player *j;
40 for (i = 0; i < MAXPLAYER; i++)
41 {
42 j = &players[i];
43 if (i == me->p_no ||
44 j->p_team != me->p_team ||
45 j->p_tractor != me->p_no)
46 continue;
47 /* j is a teammate with a tractor on me */
48 j->p_flags &= ~(PFTRACT | PFPRESS);
49 }
50 }
51
52 /*------------------------------VISIBLE PROCEDURES-------------------------*/
53
54 /*-----------------------------------ORBIT---------------------------------*/
55 /*
56 * This function is called when the player presses the orbit key. It check
57 * to make sure the player can orbit or dock. The function first checks
58 * through the list of players to see whether there is a dockable ship
59 * nearby. If that fails, then the planets are checked. The orbit key acts
60 * as a toggle for docking and undocking at ships.
61 */
62
63 void
64 orbit()
65 {
66 register int i; /* looping var */
67 register struct planet *l; /* to point to planet being orbited */
68 unsigned char dir; /* to hold course direction */
69 int dx, dy; /* used to get distances */
70
71 if (me->p_flags & PFORBIT) /* if not orbiting then we do not */
72 return; /* need to do this section of code */
73 if (me->p_speed > ORBSPEED)
74 { /* going to fast to orbit/dock? */
75 warning("Helmsman: Captain, the maximum safe speed for docking or orbiting is warp 2!");
76 return;
77 } /* turn off flags */
78 me->p_flags &= ~(PFORBIT | PFTRACT | PFPRESS |
79 PFWARP | PFAFTER | PFWARPPREP | PFWPSUSPENDED);
80 me->p_warptime = 0;
81 if ((me->p_flags & PFDOCK) && (players[me->p_docked].p_speed > 4))
82 {
83 warning("It's unsafe to disengage from your base when it's moving faster then warp 4."); /* cannot disengage from
84 * travelling */
85 return; /* ships if they are going too fast */
86 }
87 else
88 undock_player(me); /* make sure I'm not docked */
89
90 if (!(me->p_flags & PFPLLOCK) && /* if we aren't locked onto a planet */
91 can_dock(me->p_ship))
92 { /* and player can dock then */
93 for (i = 0; i < MAXPLAYER; i++)
94 { /* go through all players */
95 if (me->p_no == i) /* and look for ships that */
96 continue; /* allow docking */
97 if (!allows_docking(players[i].p_ship))
98 continue;
99 if (!isAlive(&players[i]))/* disregard players not */
100 continue; /* alive */
101 if (!friendlyPlayer(&players[i])) /* cannot dock on enemy */
102 continue; /* players */
103 dx = ABS(players[i].p_x - me->p_x); /* get distance */
104 dy = ABS(players[i].p_y - me->p_y);
105 if (dx > DOCKDIST || dy > DOCKDIST) /* if too far away thenwe */
106 continue; /* cannot dock here */
107 newdock(i); /* find a port and dock */
108
109 deactivate_friendly_tractors();
110
111 me->p_flags &= ~(PFPLOCK | PFPLLOCK);
112 return;
113 }
114 } /* not docking with a player try a planet */
115 if (!(me->p_flags & PFPLOCK))
116 { /* aren't locked onto a player */
117 for (i = 0, l = &planets[i]; i < NUMPLANETS; i++, l++)
118 {
119 switch (PL_TYPE(*l))
120 {
121 case PLSTAR:
122 case PLNEB:
123 case PLBHOLE:
124 case PLPULSAR:
125 continue;
126 }
127
128 dx = ABS(l->pl_x - me->p_x); /* go through all planets and */
129 dy = ABS(l->pl_y - me->p_y); /* check their distance */
130 if (dx > ENTORBDIST || dy > ENTORBDIST)
131 continue; /* too far away? */
132 if (dx * dx + dy * dy > ENTORBDIST * ENTORBDIST)
133 continue;
134
135 if (!(me->p_team & planets[i].pl_owner) && /* can player orbit? */
136 !(me->p_ship.s_nflags & SFNCANORBIT))
137 {
138 warning("Central Command regulations prohibits you from orbiting foreign planets");
139 return;
140 }
141 if (!(me->p_team & planets[i].pl_owner) &&
142 !status->tourn)
143 {
144 warning("No one is allowed to orbit alien planets outside of T-mode");
145 return;
146 }
147 dir = (unsigned char) (int) (atan2((double) (me->p_x - l->pl_x),
148 (double) (l->pl_y - me->p_y)) / 3.14159 * 128.);
149 scout_planet(me->p_no, l->pl_no);
150 #if 0
151 l->pl_torbit |= me->p_team; /* place team in orbit */
152 #endif
153 me->p_orbitdir = drand48() < configvals->orbitdirprob;
154 me->p_dir = dir + (me->p_orbitdir ? 64 : -64); /* get direction for
155 * player */
156 me->p_flags |= PFORBIT; /* set his orbiting flag */
157
158 deactivate_friendly_tractors();
159
160 move_player(me->p_no, (int) (l->pl_x + ORBDIST * Cos[dir]),
161 (int) (l->pl_y + ORBDIST * Sin[dir]), 1);
162
163 me->p_speed = me->p_desspeed = 0;
164 me->p_planet = l->pl_no; /* set the planet number */
165 me->p_flags &= ~(PFPLOCK | PFPLLOCK);
166 return;
167 }
168 }
169 warning("Helmsman: Sensors read no valid targets in range to dock or orbit sir!");
170 }
171
172
173
174 /*--------------------------------NEWDOCK--------------------------------*/
175
176
177 void
178 newdock(base_num)
179 int base_num;
180 {
181 char buf[80]; /* to sprintf into */
182 struct player *base = &players[base_num];
183 int port_id, i;
184 int numports;
185 long distsq = 0; /* will be set by the first matching port */
186 int angle;
187
188 if (!(base->p_flags & PFDOCKOK))
189 { /* docking allowed? */
190 sprintf(buf, "Starbase %s refusing us docking permission captain.",
191 base->p_name);
192 warning(buf); /* if not say so then */
193 return; /* get out of here */
194 }
195 port_id = -1;
196 numports = base->p_ship.s_numports;
197
198 for (i = 0; i < numports; i++)
199 {
200 long ds;
201 int x, y;
202 angle = (2 * i + 1) * 128 / numports;
203
204 if (base->p_port[i] != VACANT)
205 continue;
206
207 x = base->p_x + DOCKDIST * Cos[angle];
208 y = base->p_y + DOCKDIST * Sin[angle];
209 ds = (me->p_x - x) * (me->p_x - x) + (me->p_y - y) * (me->p_y - y);
210 if (port_id == -1 || ds < distsq)
211 {
212 port_id = i;
213 distsq = ds;
214 }
215 }
216
217 if (port_id < 0)
218 {
219 sprintf(buf, "Base %s: Permission to dock denied, all ports currently occupied.", base->p_name);
220 warning(buf); /* print message to tell */
221 return;
222 } /* player */
223 dock_to(me, base_num, port_id);
224
225 sprintf(buf, "Helmsman: Docking manuever completed Captain. All moorings secured at port %d.", port_id);
226 warning(buf); /* tell user he's docked */
227 }
228
229 #ifdef HAVE_RAND48
230
231 double drand48();
232
233 #endif
234
235 /*------------END OF FILE--------*/