Date: Tuesday February 5, 2002 @ 16:52
Author: xyzzy
Update of /home/netrek/cvsroot/Vanilla/ntserv
In directory swashbuckler.real-time.com:/var/tmp/cvs-serv5681
Modified Files:
daemonII.c interface.c phaser.c redraw.c rsa_key.c wander2.c
Log Message:
Fix stupid bug from last change. ?: has lower precedence than *, will
I never learn?
****************************************
Index: Vanilla/ntserv/daemonII.c
diff -u Vanilla/ntserv/daemonII.c:1.37 Vanilla/ntserv/daemonII.c:1.38
--- Vanilla/ntserv/daemonII.c:1.37 Mon Jun 4 17:06:28 2001
+++ Vanilla/ntserv/daemonII.c Tue Feb 5 16:52:58 2002
@@ -281,7 +281,7 @@
#define PLFIGHTFUSE 5
#define SIGHTFUSE 5
#define BEAMFUSE 8 /* scott 8/25/90 -- was 10 */
-#define PMOVEFUSE 300 /* planet movement fuse 07/26/95 JRP */
+#define PMOVEFUSE 50 /* planet movement fuse 07/26/95 JRP */
#define QUEUEFUSE 600 /* cleanup every 60 seconds */
#ifdef INL_POP
#define PLANETFUSE 400/MAXPLANETS /* INL 3.9 POP */
@@ -1519,8 +1519,8 @@
continue;
if (j == owner)
continue;
- if (j->p_team == owner->p_team)
- continue;
+/* if (j->p_team == owner->p_team)
+ continue; */
if (! ((t->t_war & j->p_team) || (t->t_team & j->p_war)))
continue;
@@ -3107,6 +3107,8 @@
l->pl_owner = j->p_team;
l->pl_info = j->p_team;
+
+ pnewhome(l);
#ifdef LTD_STATS
/* LTD is valid only for tourn mode */
@@ -4225,6 +4227,7 @@
for (i = 0; i< 40; i++) {
planets[i].pl_armies = top_armies;
}
+ preset();
for (i = 0; i < 4; i++){
/* one core AGRI */
planets[core_planets[i][random() % 4]].pl_flags |= PLAGRI;
Index: Vanilla/ntserv/interface.c
diff -u Vanilla/ntserv/interface.c:1.10 Vanilla/ntserv/interface.c:1.11
--- Vanilla/ntserv/interface.c:1.10 Thu May 10 05:37:11 2001
+++ Vanilla/ntserv/interface.c Tue Feb 5 16:52:58 2002
@@ -430,33 +430,41 @@
void do_refit(int type)
{
- int i=0;
+ int i=0, fastrefit = 1;
struct ship_cap_spacket ShipFoo;
if (type<0 || type>=ATT) return;
+
+ if (shipsallowed[type]==0) {
+ new_warning(57,"That ship hasn't been designed yet.");
+ return;
+ }
+
+ if(type == STARBASE || me->p_ship.s_type == STARBASE) fastrefit = 0;
+
+ if(!fastrefit) {
+
if (me->p_flags & PFORBIT) {
if (!(planets[me->p_planet].pl_flags & PLHOME)) {
- new_warning(50,"You must orbit your HOME planet to apply for command reassignment!");
+ new_warning(50,"You must orbit your HOME planet to apply for command reassignment!");
return;
} else {
if (!(planets[me->p_planet].pl_flags & me->p_team)) {
- new_warning(51,"You must orbit your home planet to apply for command reassignment!");
+ new_warning(51,"You must orbit your home planet to apply for command reassignment!");
return;
}
} /* if (PLHOME) */
} else if (me->p_flags & PFDOCK) {
- if (type == STARBASE
-
- ) {
- new_warning(52,"Can only refit to starbase on your home planet.");
+ if (type == STARBASE) {
+ new_warning(52,"Can only refit to starbase on your home planet.");
return;
}
if (players[me->p_docked].p_team != me->p_team) {
- new_warning(53,"You must dock YOUR starbase to apply for command reassignment!");
+ new_warning(53,"You must dock YOUR starbase to apply for command reassignment!");
return;
}
} else {
- new_warning(54,"Must orbit home planet or dock your starbase to apply for command reassignment!");
+ new_warning(54,"Must orbit home planet or dock your starbase to apply for command reassignment!");
return;
}
@@ -467,59 +475,50 @@
return;
}
+ } /* end !fastrefit checks */
+
if ((me->p_armies > 0)) {
new_warning(56,"You must beam your armies down before moving to your new ship");
return;
}
- if (shipsallowed[type]==0) {
- new_warning(57,"That ship hasn't been designed yet.");
- return;
- }
-
if (type == STARBASE) {
if (me->p_stats.st_rank < sbrank) {
if(send_short){
swarning(SBRANK_TEXT,sbrank,0);
- }
- else {
-
- new_warning(UNDEF,"You need a rank of %s or higher to command a starbase!", ranks[sbrank].name);
+ } else {
+ new_warning(UNDEF,"You need a rank of %s or higher to command a starbase!", ranks[sbrank].name);
}
return;
}
}
- if (type == STARBASE && chaos) {
+ if (type == STARBASE) {
int num_bases = 0;
+ if(!chaos) max_chaos_bases = 1;
+
for (i=0; i<MAXPLAYER; i++)
if ((me->p_no != i) &&
(players[i].p_status == PALIVE) &&
- (players[i].p_team == me->p_team))
- if (players[i].p_ship.s_type == STARBASE) {
- num_bases++;
- }
+ (players[i].p_team == me->p_team) &&
+ (players[i].p_ship.s_type == STARBASE)) num_bases++;
+
if (num_bases >= max_chaos_bases) {
- new_warning(UNDEF,"Your side already has %d starbase%s",max_chaos_bases,(max_chaos_bases>1) ? "s!":"!");
- return;
+ if(max_chaos_bases==0) {
+ new_warning(UNDEF,"Your side isn't allowed to have starbases");
+ } else if(max_chaos_bases==1) {
+ new_warning(58,"Your side already has a starbase!");
+ } else {
+ new_warning(UNDEF,"Your side already has %d starbase%s",max_chaos_bases,(max_chaos_bases>1) ? "s!":"!");
+ }
+ return;
}
}
- else if (type == STARBASE && !chaos) {
- for (i=0; i<MAXPLAYER; i++)
- if ((me->p_no != i) &&
- (players[i].p_status == PALIVE) &&
- (players[i].p_team == me->p_team))
- if (players[i].p_ship.s_type == STARBASE) {
- new_warning(58,"Your side already has a starbase!");
- return;
- }
- }
if (type == STARBASE && !chaos && !topgun) {
if (realNumShips(me->p_team) < 4) {
if(send_short){
swarning(TEXTE,59,0);
- }
- else
- new_warning(UNDEF,"Your team is not capable of defending such an expensive ship");
+ } else
+ new_warning(UNDEF,"Your team is not capable of defending such an expensive ship");
return;
}
}
@@ -534,9 +533,12 @@
return;
}
+ /* They have finally passed the screening process for potential
+ starship captains. Give them their new ship! */
+
if ((me->p_ship.s_type == STARBASE)/* && (type != STARBASE)*/) {
/* Reset kills to 0.0 */
- me->p_kills=0;
+ me->p_kills = 0;
/* bump all docked ships */
for (i=0; i<NUMPORTS; i++)
if (me->p_port[i] != VACANT) {
@@ -547,10 +549,46 @@
}
}
-
- getship(&(me->p_ship), type);
- /* Notify client of new ship stats, if necessary */
+ if (type != STARBASE && me->p_kills < plkills) {
+ me->p_ship.s_plasmacost = -1;
+ }
+
+ if (fastrefit) {
+ struct ship *newship = &shipvals[type],
+ *oldship = &me->p_ship;
+ me->p_shield *= (float)newship->s_maxshield/oldship->s_maxshield;
+ me->p_damage *= (float)newship->s_maxdamage/oldship->s_maxdamage;
+ me->p_fuel *= (float)newship->s_maxfuel/oldship->s_maxfuel;
+ me->p_wtemp *= (float)newship->s_maxwpntemp/oldship->s_maxwpntemp;
+ me->p_etemp *= (float)newship->s_maxegntemp/oldship->s_maxegntemp;
+ me->p_flags &= ~PFREFIT;
+ me->p_flags |= PFREFITTING;
+ me->p_ship.s_type = type;
+ rdelay = me->p_updates + 1;
+ getship(&(me->p_ship), type);
+ } else {
+ getship(&(me->p_ship), type);
+
+ me->p_shield = me->p_ship.s_maxshield;
+ me->p_damage = 0;
+ me->p_fuel = me->p_ship.s_maxfuel;
+ me->p_wtemp = 0;
+ me->p_wtime = 0;
+ me->p_etemp = 0;
+ me->p_etime = 0;
+ me->p_ship.s_type = type;
+ if (type == STARBASE) {
+ me->p_docked = 0;
+ for (i=0; i<4; i++) me->p_port[i] = VACANT;
+ me->p_flags |= PFDOCKOK;
+ }
+ me->p_flags &= ~(PFREFIT|PFWEP|PFENG);
+ me->p_flags |= PFREFITTING;
+ rdelay = me->p_updates + 50;
+ }
+
#ifndef ROBOT
+ /* Notify client of new ship stats, if necessary */
if ((F_ship_cap)&&(!sent_ship[type])) {
sent_ship[type] = 1;
ShipFoo.type = SP_SHIP_CAP;
@@ -575,26 +613,6 @@
sendClientPacket((CVOID) &ShipFoo);
}
#endif
- if (type != STARBASE && me->p_kills < plkills) {
- me->p_ship.s_plasmacost = -1;
- }
- me->p_shield = me->p_ship.s_maxshield;
- me->p_damage = 0;
- me->p_fuel = me->p_ship.s_maxfuel;
- me->p_wtemp = 0;
- me->p_wtime = 0;
- me->p_etemp = 0;
- me->p_etime = 0;
- me->p_ship.s_type = type;
- if (type == STARBASE) {
- me->p_docked = 0;
- for (i=0; i<4; i++) me->p_port[i] = VACANT;
- me->p_flags |= PFDOCKOK;
- }
-
- me->p_flags &= ~(PFREFIT|PFWEP|PFENG);
- me->p_flags |= PFREFITTING;
- rdelay = me->p_updates + 50;
new_warning(62,"You are being transported to your new vessel .... ");
}
Index: Vanilla/ntserv/phaser.c
diff -u Vanilla/ntserv/phaser.c:1.2 Vanilla/ntserv/phaser.c:1.3
--- Vanilla/ntserv/phaser.c:1.2 Fri Apr 30 15:18:45 1999
+++ Vanilla/ntserv/phaser.c Tue Feb 5 16:52:58 2002
@@ -260,7 +260,7 @@
return;
}
- /* pstatus == PHHIT2 */ {
+ /* pstatus == PHHIT2 */
#ifdef LTD_STATS
@@ -272,58 +272,52 @@
#endif
- if (pingpong_plasma) {
-
- mine->ph_damage = me->p_ship.s_phaserdamage *
- (1.0-((float) range/(float) myphrange));
- if ((target_plasma->t_war & me->p_team)
- || (me->p_hostile & target_plasma->t_team)) {
- int rand_plasmadir;
- int rand_plasmaturns;
- mine->ph_x = target_plasma->t_x;
- mine->ph_y = target_plasma->t_y;
- mine->ph_status = PHHIT2;
- target_plasma->t_damage+=mine->ph_damage/4;
- target_plasma->t_gspeed+=mine->ph_damage/100;
- srandom(getpid() * time((time_t *) 0));
- rand_plasmadir = random() % 9;
- rand_plasmaturns = random() % 9;
- if (rand_plasmadir < 8)
- rand_plasmadir = 128;
- else rand_plasmadir = 80;
- if (rand_plasmaturns < 7) target_plasma->t_turns++;
- target_plasma->t_dir = (target_plasma->t_dir+rand_plasmadir)%256;
- players[target_plasma->t_owner].p_nplasmatorp--;
- target_plasma->t_owner=me->p_no;
- me->p_nplasmatorp++;
- target_plasma->t_team=me->p_team;
- target_plasma->t_war=me->p_hostile;
- target_plasma->t_fuse+=mine->ph_damage * .25 + 5;
- new_warning(UNDEF, "Ping-Pong!");
- }
- else {
- mine->ph_x = target_plasma->t_x;
- mine->ph_y = target_plasma->t_y;
- mine->ph_status = PHHIT2;
- target_plasma->t_damage+=mine->ph_damage;
- target_plasma->t_gspeed+=mine->ph_damage/100;
- target_plasma->t_turns++;
- target_plasma->t_dir = me->p_dir;
- players[target_plasma->t_owner].p_nplasmatorp--;
- target_plasma->t_owner=me->p_no;
- me->p_nplasmatorp++;
- target_plasma->t_team=me->p_team;
- target_plasma->t_war=me->p_hostile;
- target_plasma->t_fuse+=mine->ph_damage * .25 + 5;
- new_warning(UNDEF, "You deflected the plasma!"); }
- }
-
- if (!pingpong_plasma) {
- mine->ph_x = target_plasma->t_x;
- mine->ph_y = target_plasma->t_y;
- target_plasma->t_status = TDET;
- target_plasma->t_whodet = me->p_no;
- new_warning(38, "You destroyed the plasma torpedo!");
- }
+ if (pingpong_plasma) {
+ mine->ph_damage = me->p_ship.s_phaserdamage *
+ (1.0-((float) range/(float) myphrange));
+ mine->ph_x = target_plasma->t_x;
+ mine->ph_y = target_plasma->t_y;
+ if ( (target_plasma->t_war & me->p_team) ||
+ (me->p_hostile & target_plasma->t_team)) {
+ /* Unfriendly plasmas */
+ fprintf(stderr, "phasered unfriendly plasma!\n");
+
+ /* Plasma does a quick 180 */
+ target_plasma->t_dir=(target_plasma->t_dir+128)%256;
+
+ /* Give plasma more fuse, so the fun does't stop */
+ target_plasma->t_fuse+=mine->ph_damage * .25 + 5;
+
+// target_plasma->t_damage+=mine->ph_damage/4;
+// target_plasma->t_gspeed+=mine->ph_damage/100;
+
+ new_warning(UNDEF, "Ping-Pong!");
+ } else {
+ /* Friendly plasma */
+ fprintf(stderr, "phasered friendly plasma!\n");
+
+ /* Plasma points direction ship phasering it is pointed */
+ target_plasma->t_dir = me->p_dir;
+
+ target_plasma->t_fuse+=mine->ph_damage * .25 + 5;
+
+ target_plasma->t_damage+=mine->ph_damage;
+ target_plasma->t_gspeed+=mine->ph_damage/100;
+ target_plasma->t_turns++;
+ new_warning(UNDEF, "You deflected the plasma!");
+ }
+
+ /* Switch owners & teams */
+ players[target_plasma->t_owner].p_nplasmatorp--;
+ target_plasma->t_owner=me->p_no; me->p_nplasmatorp++;
+ target_plasma->t_team=me->p_team;
+ target_plasma->t_war=me->p_war;
+
+ } else {
+ mine->ph_x = target_plasma->t_x;
+ mine->ph_y = target_plasma->t_y;
+ target_plasma->t_status = TDET;
+ target_plasma->t_whodet = me->p_no;
+ new_warning(38, "You destroyed the plasma torpedo!");
}
}
Index: Vanilla/ntserv/redraw.c
diff -u Vanilla/ntserv/redraw.c:1.11 Vanilla/ntserv/redraw.c:1.12
--- Vanilla/ntserv/redraw.c:1.11 Tue Feb 5 06:06:40 2002
+++ Vanilla/ntserv/redraw.c Tue Feb 5 16:52:58 2002
@@ -414,7 +414,7 @@
#endif
pl = me; /* Not observer, just use my kills */
- troop_capacity = pl->p_kills * (myship->s_type == ASSAULT)?3:2;
+ troop_capacity = pl->p_kills * (myship->s_type == ASSAULT?3:2);
if (myship->s_type == STARBASE || troop_capacity > myship->s_maxarmies)
troop_capacity = myship->s_maxarmies;
Index: Vanilla/ntserv/rsa_key.c
diff -u Vanilla/ntserv/rsa_key.c:1.1 Vanilla/ntserv/rsa_key.c:1.2
--- Vanilla/ntserv/rsa_key.c:1.1 Wed Nov 11 20:44:53 1998
+++ Vanilla/ntserv/rsa_key.c Tue Feb 5 16:52:58 2002
@@ -1,4 +1,3 @@
-#ifndef lint
#ifdef RSA
/* rsa_key.c
@@ -140,4 +139,3 @@
return 0;
}
#endif /* RSA */
-#endif /* lint */
Index: Vanilla/ntserv/wander2.c
diff -u Vanilla/ntserv/wander2.c:1.3 Vanilla/ntserv/wander2.c:1.4
--- Vanilla/ntserv/wander2.c:1.3 Tue Aug 15 02:57:58 2000
+++ Vanilla/ntserv/wander2.c Tue Feb 5 16:52:58 2002
@@ -4,33 +4,34 @@
#include "struct.h"
#include "data.h" /* Includes global variable extern defs */
-#define COS(x) ((x) >= 0.0 ? Cosine[(int)(x)] : Cosine[(int)(-(x))])
-#define SIN(x) ((x) >= 0.0 ? Sine[(int)(x)] : -Sine[(int)(-(x))])
+static struct {
+ int x,y;
+} pl_dest[MAXPLANETS];
-static int pl_home[4];
-static int pl_core[4][10];
-static int pl_dist[4][10];
-static const double increment = 0.016;
-static const double incrementrecip = 62.5;
-static float *Cosine, *Sine;
+#define PMOVESPEED 2000.0
-/* call only once */
-void pinit(void)
+void preset(void)
{
- int i, j;
- int pre;
+ int i;
+ for(i=0;i<MAXPLANETS;i++) {
+ pl_dest[i].x = planets[i].pl_x;
+ pl_dest[i].y = planets[i].pl_y;
+ }
- void pmove();
+ return;
+}
- pre = 3.5/increment;
+/* call only once */
+void pinit(void)
+{
+ int i;
- Cosine = (float*) calloc(sizeof(float), pre);
- Sine = (float*) calloc(sizeof(float), pre);
- for (i = 0; i < pre; i++) {
- Cosine[i] = cos((double)i*increment);
- Sine[i] = sin((double)i*increment);
+ for(i=0;i<MAXPLANETS;i++) {
+ pl_dest[i].x = planets[i].pl_x;
+ pl_dest[i].y = planets[i].pl_y;
}
+ /*
pl_home[0] = 0;
pl_core[0][0] = 5;
pl_core[0][1] = 7;
@@ -51,53 +52,77 @@
pl_core[3][1] = 37;
pl_core[3][2] = 38;
pl_core[3][3] = 39;
-
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 4; j++) {
- pl_dist[i][j] = hypot(
- planets[pl_core[i][j]].pl_x - planets[pl_home[i]].pl_x,
- planets[pl_core[i][j]].pl_y - planets[pl_home[i]].pl_y);
+ */
+}
+
+/* find distance of closest planet to x,y */
+static float closestplanet(int x, int y)
+{
+ int i;
+ float d, bestd;
+
+ for(i=0, bestd=HUGE_VAL;i<MAXPLANETS;i++) {
+ d = hypot(planets[i].pl_x - x, planets[i].pl_y - y);
+ if(d<bestd) bestd=d;
+ }
+ for(i=0;i<MAXPLANETS;i++) {
+ d = hypot(pl_dest[i].x - x, pl_dest[i].y - y);
+ if(d<bestd) bestd=d;
+ }
+
+ return bestd;
+}
+
+void pnewhome(struct planet *pl)
+{
+ int t, b, l, r;
+
+ switch(pl->pl_owner) {
+ case FED: t = GWIDTH/2; b = GWIDTH; l = 0; r = GWIDTH/2; break;
+ case ROM: t = 0; b = GWIDTH/2; l = 0; r = GWIDTH/2; break;
+ case KLI: t = 0; b = GWIDTH/2; l = GWIDTH/2; r = GWIDTH; break;
+ case ORI: t = GWIDTH/2; b = GWIDTH; l = GWIDTH/2; r = GWIDTH; break;
+ default: return;
+ }
+
+ if(pl->pl_x < l || pl->pl_x > r || pl->pl_y < t || pl->pl_y > b) {
+ /* planet out of quadrant, needs a new home! */
+ int i, x, y, bestx, besty, bestd = 0, d;
+ for(i=0;i<10;i++) { /* Try 10 times to find a good spot */
+ x = (random()%(GWIDTH/2)) + l; y = (random()%(GWIDTH/2)) + t;
+ d = closestplanet(x, y);
+ if(d > bestd) { bestx=x;besty=y;bestd=d; }
}
+ pl_dest[pl->pl_no].x = bestx;
+ pl_dest[pl->pl_no].y = besty;
+ } else {
+ /* Keep the planet at this spot if it was moving */
+ pl_dest[pl->pl_no].x = pl->pl_x;
+ pl_dest[pl->pl_no].y = pl->pl_y;
}
+
+ return;
}
void pmove(void)
{
- int i, j;
- double dir;
- static int planeti=0, planetj=0;
-
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 4; j++) {
- i = planeti;
- j = planetj;
- planetj = (planetj + 1) % 4;
- if (planetj == 0)
- planeti = (planeti + 1) % 4;
-
- dir = atan2((double) (planets[pl_core[i][j]].pl_y - planets[pl_home[i]].pl_y),
- (double) (planets[pl_core[i][j]].pl_x - planets[pl_home[i]].pl_x));
- if (dir > M_PI) dir = dir - 2.0*M_PI;
- if (dir >= 0.0)
- dir = (dir*incrementrecip+1.5);
- else
- dir = (dir*incrementrecip+0.5);
-
-
- planets[pl_core[i][j]].pl_x =
- planets[pl_home[i]].pl_x +
- (int) (pl_dist[i][j] * COS(dir));
- planets[pl_core[i][j]].pl_y =
- planets[pl_home[i]].pl_y +
- (int) (pl_dist[i][j] * SIN(dir));
-
- dir = atan2((double) (planets[pl_core[i][j]].pl_y
- - planets[pl_home[i]].pl_y),
- (double) (planets[pl_core[i][j]].pl_x
- - planets[pl_home[i]].pl_x));
-
- planets[pl_core[i][j]].pl_flags |= PLREDRAW;
- }
+ int i;
+ int dx,dy;
+ float d;
+
+ for(i=0;i<MAXPLANETS;i++) {
+ if(planets[i].pl_x != pl_dest[i].x || planets[i].pl_y != pl_dest[i].y) {
+ dx = pl_dest[i].x - planets[i].pl_x;
+ dy = pl_dest[i].y - planets[i].pl_y;
+ d = hypot(dx, dy);
+ if( d > PMOVESPEED ) {
+ dx = dx * PMOVESPEED / d; dy = dy * PMOVESPEED / d;
+ }
+
+ planets[i].pl_x += dx;
+ planets[i].pl_y += dy;
+ planets[i].pl_flags |= PLREDRAW;
+ }
}
}