Update of /cvsroot/netrek/client/netrekxp/src In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv32689/src Modified Files: dashboard.c warning.c Log Message: Fix to bug where client sometimes has wrong value for what planet you are orbitting. Addition of phaser stats to long packets. Index: warning.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/warning.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- warning.c 18 May 2006 07:15:35 -0000 1.6 +++ warning.c 20 May 2006 03:55:23 -0000 1.7 @@ -48,7 +48,50 @@ rdelay = time (0) + REFITTIME; if (doDeclare) delay = time (0) + DECLARETIME; + #ifdef PHASER_STATS + if (!recv_short) /* Gotta parse phaser info for long packets here */ + { + if (strncmp(text, "You destroyed the plasma", 24) == 0) /* Plasma hit */ + { + phaserStatTry++; + phaserStatHit++; + /* Record as an average damage hit so as not to skew overall average */ + phaserStatDamage += phaserStatDamage / phaserStatTry; + } + if (strncmp(text, "Phaser missed", 13) == 0) /* Miss */ + { + phaserStatTry++; + if (phaserStats) + { + /* Mung the message */ + char phstatmsg[30]; + + sprintf (phstatmsg, "%s [%d%%]", text, + phaserStatTry ? (phaserStatHit * 100) / + phaserStatTry : 0); + strcpy (text, phstatmsg); + /* Update string length */ + warncount = strlen (text); + } + } + if (doPhaser) /* Parse out damage and record to average */ + { + char *d; + register int damage; + d = &text[warncount]; + /* find the last number in the string, should be damage */ + while (!isdigit(*d) && d > text) + d--; + while (d > text && isdigit(*d)) + d--; + if (d > text) + damage = atoi(d); + phaserStatTry++; + phaserStatHit++; + phaserStatDamage += damage; + } + } if (doPhaser && phaserStats) { sprintf (newtext, "%s [%3d%%] [%2u]", text, Index: dashboard.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/dashboard.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- dashboard.c 19 May 2006 18:08:07 -0000 1.5 +++ dashboard.c 20 May 2006 03:55:23 -0000 1.6 @@ -18,6 +18,7 @@ /******************************************************************************/ #include <stdio.h> +#include <math.h> #include "config.h" #include "copyright.h" @@ -287,12 +288,12 @@ static int oldmsgtype; W_Color color; int left, right, pos; - + if ((me->p_flags & (PFPLOCK | PFOBSERV)) == (PFPLOCK | PFOBSERV)) plr = players + me->p_playerl; else plr = me; - + /* Check if any delays expired */ if (delay && time (0) > delay) delay = 0; @@ -300,10 +301,10 @@ rdelay = 0; if (tdelay && time (0) > tdelay) tdelay = 0; - + /* Start with highest priority message, then go down in descending order of importance */ - + /* Declare War text */ if (delay) { @@ -852,23 +853,29 @@ int hulltime = 0; int shieldneeded, hullneeded; float shieldrate = 0.0, hullrate = 0.0; - + struct player *plr; + + if ((me->p_flags & (PFPLOCK | PFOBSERV)) == (PFPLOCK | PFOBSERV)) + plr = players + me->p_playerl; + else + plr = me; + /* 100 subshield or subdamage = 1 shield or hull repaired This routine is used by server every update (and 10 updates/sec) */ /* calculate shield repair rate */ if ((shieldneeded = (me->p_ship.s_maxshield - me->p_shield)) > 0) { me->p_subshield = me->p_ship.s_repair * 4; - if ((me->p_flags & PFORBIT) - && (planets[me->p_planet].pl_flags & PLREPAIR) - &&(!(planets[me->p_planet].pl_owner & (me->p_swar | me->p_hostile)))) - { - me->p_subshield += me->p_ship.s_repair * 4; - } - if (me->p_flags & PFDOCK) + if (me->p_flags & PFORBIT) { - me->p_subshield += me->p_ship.s_repair * 6; - } + /* Damn server doesn't send us p_planet info, have to calculate it ourselves! */ + me->p_planet = get_closest_planet(me->p_x, me->p_y); + if ((planets[me->p_planet].pl_flags & PLREPAIR) + &&(!(planets[me->p_planet].pl_owner & (plr->p_swar | plr->p_hostile)))) + me->p_subshield += me->p_ship.s_repair * 4; + if (me->p_flags & PFDOCK) + me->p_subshield += me->p_ship.s_repair * 6; + } /* Calculate time needed to repair shields */ shieldrate = (float)(me->p_subshield)/(float)100.0; shieldtime = (int)(shieldneeded/shieldrate); @@ -878,20 +885,44 @@ if (((hullneeded = me->p_damage) > 0) && !(me->p_flags & PFSHIELD)) { me->p_subdamage = me->p_ship.s_repair * 2; - if ((me->p_flags & PFORBIT) - && (planets[me->p_planet].pl_flags & PLREPAIR) - && (!(planets[me->p_planet].pl_owner & (me->p_swar | me->p_hostile)))) - { - me->p_subdamage += me->p_ship.s_repair * 2; - } - if (me->p_flags & PFDOCK) + if (me->p_flags & PFORBIT) { - me->p_subdamage += me->p_ship.s_repair * 3; + /* Damn server doesn't send us p_planet info, have to calculate it ourselves! */ + me->p_planet = get_closest_planet(me->p_x, me->p_y); + if ((planets[me->p_planet].pl_flags & PLREPAIR) + && (!(planets[me->p_planet].pl_owner & (plr->p_swar | plr->p_hostile)))) + me->p_subdamage += me->p_ship.s_repair * 2; + if (me->p_flags & PFDOCK) + me->p_subdamage += me->p_ship.s_repair * 3; } - /* Calculate time needed to repair hull */ + /* Calculate time needed to repair hull */ hullrate = (float)(me->p_subdamage)/(float)100.0; hulltime = (int)(hullneeded/hullrate); } return MAX(shieldtime, hulltime); -}; \ No newline at end of file +} + +/******************************************************************************/ +/*** get_closest_planet() - find closest planet to given location + Useful for determining which planet you are orbitting ***/ +/******************************************************************************/ +int get_closest_planet(int x, int y) +{ + register int i; + register struct planet *k; + double dist, closedist; + int target; + + closedist = GWIDTH; + for (i = 0, k = &planets[i]; i < MAXPLANETS; i++, k++) + { + dist = hypot ((double) (x - k->pl_x), (double) (y - k->pl_y)); + if (dist < closedist) + { + target = i; + closedist = dist; + } + } + return (short)(target); +}