Update of /cvsroot/netrek/client/netrekxp/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv25229/src Modified Files: data.c enter.c map.c newwin.c ranklist.c short.c socket.c Log Message: Main change: 1) The way memory was set up for all the weapons/planets/player structs was changed. Instead of a static struct memory universe, it was changed to malloc calls during entry. A bunch of new functions (for paradise) were called to dealloc this memory and realloc if it a game parameter packet was received which indicated new array sizes. Currently there is only partial support for increasing torp/plasma array sizes, and no support for increasing number of phasers per ship. Maxplayer, while dynamic in paradise client, was too much a PITA to realloc on the fly without changing all the MAXPLAYER checks, so I'm keeping it constant at 257 for paradise, rather than trying to save some memory by downsizing it if the actual number of players is less. Paradise does something weird in that it has a max player value for what the server says, and a second max player value for what the client can actually handle. I'm not going to go that route, just keeping 1 maxplayer value thank you very much. Paradise only changes: 1) Add support for adjustable gwidth, it starts at 100000, but if a planet loc packet is sent beyond this range, it increases to 200000. Very stupid, but that's how paradise does it. Wouldn't seem to support galaxies with sizes other than these 2 values. 2) Increased paradise planet window size so it wasn't getting cut off. Bronco changes: 1) Support new server change from rank defense to rank offense. 2) Renamed view to viewboxview for drawing viewbox. 3) Removed unnecessary bounds check on drawing lockline. Index: map.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/map.c,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- map.c 18 May 2007 19:54:38 -0000 1.57 +++ map.c 7 Jun 2007 04:43:39 -0000 1.58 @@ -40,7 +40,7 @@ #ifdef PARADISE int drawgrid = 1; /* goes to netrekrc eventually */ -int blk_zoom = 0; /* goes to netrekrc eventually */ +int blk_zoom = 0; /* goes to netrekrc eventually, doesn't work */ int sectorNums = 1; /* goes to netrekrc eventually */ #define DRAWGRID 4 #endif @@ -925,7 +925,8 @@ static char clearviewbox = 0; static char viewboxcleared = 0; int viewdist; - int view = TWINSIDE * scaleFactor / 2; + int view = TWINSIDE * mapscaleFactor / 2; /* view range for scaled galactic */ + int viewboxview = (TWINSIDE * scaleFactor / 2); /* view range for view box */ int mvx, mvy; #ifdef PARADISE static int osx = 0, osy = 0; /* old square */ @@ -941,7 +942,7 @@ if (GWINSIDE == 0) return; - viewdist = (TWINSIDE / 2 * scaleFactor) / (GWIDTH / GWINSIDE); + viewdist = (viewboxview) / (GWIDTH / GWINSIDE); dx = (me->p_x) / (GWIDTH / GWINSIDE); dy = (me->p_y) / (GWIDTH / GWINSIDE); @@ -1010,10 +1011,10 @@ /* redraw any planets they overwrote */ mvx = viewx * (GWIDTH / GWINSIDE); /* correct from view scale */ mvy = viewy * (GWIDTH / GWINSIDE); - checkRedraw(mvx + view, mvy + view); - checkRedraw(mvx + view, mvy - view); - checkRedraw(mvx - view, mvy + view); - checkRedraw(mvx - view, mvy - view); + checkRedraw(mvx + viewboxview, mvy + viewboxview); + checkRedraw(mvx + viewboxview, mvy - viewboxview); + checkRedraw(mvx - viewboxview, mvy + viewboxview); + checkRedraw(mvx - viewboxview, mvy - viewboxview); viewboxcleared = 1; } @@ -1609,7 +1610,7 @@ clearlmark[3] = 1; clearlock = 1; } - if (lockLine && (dx <= view && dx >= 0 && dy <= view && dy >= 0)) + if (lockLine) { int mydx, mydy; Index: newwin.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/newwin.c,v retrieving revision 1.66 retrieving revision 1.67 diff -u -d -r1.66 -r1.67 --- newwin.c 25 May 2007 03:36:47 -0000 1.66 +++ newwin.c 7 Jun 2007 04:43:39 -0000 1.67 @@ -969,7 +969,7 @@ W_SetWindowKeyDownHandler (warnw, handleMessageWindowKeyDown); #ifdef PARADISE - planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 70, MAXPLANETS + 8, baseWin, 2); + planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 75, MAXPLANETS + 8, baseWin, 2); #else planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 57, MAXPLANETS + 3, baseWin, 2); #endif Index: enter.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/enter.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- enter.c 25 May 2007 03:36:46 -0000 1.12 +++ enter.c 7 Jun 2007 04:43:38 -0000 1.13 @@ -48,27 +48,37 @@ { int i; - players = universe.players; - torps = universe.torps; - plasmatorps = universe.plasmatorps; + /* Used to be struct memory universe, but leaving room for flexible struct + sizes is better, and necessary for paradise - BB */ + players = (struct player *) malloc(sizeof(*players) * MAXPLAYER); + torps = (struct torp *) malloc(sizeof(*torps) * MAXPLAYER * MAXTORP); + plasmatorps = (struct plasmatorp *) malloc(sizeof(*plasmatorps) * MAXPLAYER * MAXPLASMA); #ifdef PARADISE - thingies = universe.thingies; - ranks2 = universe.ranks2; - teaminfo = universe.teaminfo; - royal = universe.royal; - status2 = universe.status2; + thingies = (struct thingy *) malloc(sizeof(*thingies) * (MAXPLAYER * npthingies + ngthingies)); + ranks2 = (struct rank2 *) malloc(sizeof(*ranks2) * nranks2); + for (i = 0; i < nranks2; i++) + ranks2[i].name = strdup("blank"); + /* independent is teaminfo[-1] */ + teaminfo = 1 + (struct teaminfo_s *) malloc(sizeof(*teaminfo) * (number_of_teams + 2)); + royal = (struct royalty *) malloc(sizeof(*royal) * nroyals); + for (i = 0; i < nroyals; i++) + royal[i].name = strdup("blank"); + status2 = (struct status2 *) malloc(sizeof(*status2)); #endif - status = universe.status; - planets = universe.planets; - phasers = universe.phasers; - mctl = universe.mctl; - messages = universe.messages; + status = (struct status *) malloc(sizeof(*status)); + planets = (struct planet *) malloc(sizeof(*planets) * MAXPLANETS); + phasers = (struct phaser *) malloc(sizeof(*phasers) * MAXPLAYER); + mctl = (struct mctl *) malloc(sizeof(*mctl)); + messages = (struct message *) malloc(sizeof(*messages) * MAXMESSAGE); for (i = 0; i < MAXPLAYER; i++) { players[i].p_status = PFREE; players[i].p_cloakphase = 0; players[i].p_no = i; players[i].p_ntorp = 0; +#ifdef PARADISE + players[i].p_ndrone = 0; +#endif players[i].p_explode = 1; players[i].p_stats.st_tticks = 1; } Index: short.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/short.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- short.c 12 Apr 2007 00:56:28 -0000 1.23 +++ short.c 7 Jun 2007 04:43:39 -0000 1.24 @@ -225,7 +225,11 @@ int spwinside = 500; /* WINSIDE from Server */ #define SPWINSIDE 500 /* To make it safe */ +#ifdef PARADISE +LONG spgwidth = 100000; +#else LONG spgwidth = GWIDTH; +#endif void sendThreshold (short unsigned int v) Index: ranklist.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/ranklist.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ranklist.c 25 May 2007 03:36:47 -0000 1.4 +++ ranklist.c 7 Jun 2007 04:43:39 -0000 1.5 @@ -118,14 +118,14 @@ char buf[100]; /* W_ClearWindow(rankw); */ - (void) strcpy (buf, " Rank Hours Defense Ratings DI"); + (void) strcpy (buf, " Rank Hours Offense Ratings DI"); W_WriteText (rankw, 1, 1, textColor, buf, strlen (buf), W_BoldFont); for (i = 0; i < NUMRANKS; i++) { sprintf (buf, "%-11.11s %5.0f %8.2f %8.2f %7.2f", ranks[i].name, ranks[i].hours, - ranks[i].defense, + ranks[i].offense, ranks[i].ratings, ranks[i].ratings * ranks[i].hours); if (mystats->st_rank == i) { Index: data.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- data.c 25 May 2007 03:36:46 -0000 1.95 +++ data.c 7 Jun 2007 04:43:38 -0000 1.96 @@ -35,7 +35,6 @@ struct phaser *phasers; struct message *messages; struct mctl *mctl; -struct memory universe; struct _star stars[MAXSECTORS][MAXSECTORS][MAXSTARS]; int TWINSIDE = 500; /* Size of tactical window */ @@ -279,7 +278,8 @@ int received_terrain_info = 0; int terrain_x; int terrain_y; -int gwidth = GWIDTH; /* galaxy width, adjusted for zoom [BDyess] */ +int gwidth = 100000; /* Paradise version of GWIDTH */ +int gwidth_zoom = 100000; /* galaxy width, adjusted for zoom, unused */ int offsetx = 0; int offsety = 0; /* offsets when zooming [BDyess] */ int nplayers = 256; @@ -899,5 +899,6 @@ int sortPlanets = 1; /* sort planet list by team and army count */ int packetLights = 1; /* show packet send/receive via dashboard */ int infoRange = 1; /* show limit on info with large tactical windows */ -int scaleFactor = 40; /* allows for scaling of graphics */ +int scaleFactor = 40; /* allows for scaling of tactical window */ +int mapscaleFactor = 40; /* allows for scaling of galactic window, unused */ int fullBitmapRotation = 1; /* draw old bitmap sets to all angles */ Index: socket.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/socket.c,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- socket.c 25 May 2007 03:36:47 -0000 1.35 +++ socket.c 7 Jun 2007 04:43:39 -0000 1.36 @@ -2547,6 +2547,12 @@ pl->pl_flags |= PLREDRAW; reinitPlanets = 1; +#ifdef PARADISE + /* What a terrible hack, just copying paradise client code - BB */ + if (pl->pl_x > gwidth) + gwidth = 200000; +#endif + #ifdef ROTATERACE if (rotate) { @@ -3014,7 +3020,7 @@ struct thingy *thetorp; #ifdef CORRUPTED_PACKETS - if (packet->tnum >= npthingies*nplayers + ngthingies) + if (ntohs(packet->tnum) >= npthingies*nplayers + ngthingies) { LineToConsole ("handleThingy: bad index %d\n", packet->tnum); return; @@ -3044,7 +3050,7 @@ struct thingy *thetorp; #ifdef CORRUPTED_PACKETS - if (packet->tnum >= npthingies*nplayers + ngthingies) + if (ntohs(packet->tnum) >= npthingies*nplayers + ngthingies) { LineToConsole ("handleThingyInfo: bad index %d\n", packet->tnum); return; @@ -3115,9 +3121,217 @@ } } -void handleGPsizes (struct gp_sizes_spacket *pkt) +void +initialize_thingies(void) +{ + int i; + int n = (npthingies * MAXPLAYER + ngthingies); + thingies = (struct thingy *) malloc(sizeof(*thingies) * n); + for (i = 0; i < n; i++) { + thingies[i].t_shape = SHP_BLANK; + thingies[i].t_no = i; + thingies[i].t_owner = (i >= npthingies * MAXPLAYER) ? -1 : (i / npthingies); + } +} + +void +initialize_torps(void) +{ + int i; + + torps = (struct torp *) malloc(sizeof(*torps) * MAXPLAYER * ntorps); + + for (i = 0; i < nplayers * ntorps; i++) { + torps[i].t_status = TFREE; + torps[i].t_owner = (i / ntorps); + } +} + +void +initialize_plasmas(void) +{ + int i; + + plasmatorps = (struct plasmatorp *) malloc(sizeof(*plasmatorps) * MAXPLAYER * nplasmas); + for (i = 0; i < MAXPLAYER * nplasmas; i++) { + plasmatorps[i].pt_status = PTFREE; + plasmatorps[i].pt_owner = (i / nplasmas); + } +} + +static void +initialize_phasers(void) +{ + int i; + + phasers = (struct phaser *) malloc(sizeof(*phasers) * MAXPLAYER * nphasers); + + for (i = 0; i < MAXPLAYER * nphasers; i++) { + phasers[i].ph_status = PHFREE; + phasers[i].ph_fuse = 0; + } +} + +void +initialize_planets(void) +{ + int i; + + planets = (struct planet *)malloc(sizeof(*planets) * MAXPLANETS); + + for(i = 0; i < MAXPLANETS; i++) { + struct planet *curr = &planets[i]; + curr->pl_no = i; + curr->pl_flags = 0; + curr->pl_owner = 0; + curr->pl_x = curr->pl_y = -10000; + sprintf(curr->pl_name, "planet%d", i); + curr->pl_namelen = strlen(curr->pl_name); + curr->pl_armies = 0; + curr->pl_info = 0; + curr->pl_deadtime = 0; + curr->pl_couptime = 0; + curr->pl_timestamp = 0; + + /* initialize planet redraw for moving planets */ + pl_update[i].plu_update = -1; + } +} + +void +initialize_ranks(void) { + int i; + ranks2 = (struct rank2 *) malloc(sizeof(*ranks2) * nranks2); + + for (i = 0; i < nranks2; i++) { + ranks2[i].name = strdup("blank"); + } +} + +void +initialize_royal(void) +{ + int i; + royal = (struct royalty *) malloc(sizeof(*royal) * nroyals); + + for (i = 0; i < nroyals; i++) { + royal[i].name = strdup("blank"); + } +} + + +void +resize_players(void) +{ +/* For sake of simplicity, I'm leaving size of player struct constant at MAXPLAYER, + resizing just leads to too many problems. - BB */ /* + int me_no = 0; + + if (me) + me_no = me->p_no; + players = (struct player *) realloc(players, sizeof(*players) * nplayers); + if (me) { + me = &players[me_no]; + myship = &(me->p_ship); + } +*/ +} + +load_generic_teams(void) +{ +/* needs to be converted to xpm */ + /* + reserved letters: A G T + */ + int i; + + /* independent is teaminfo[-1] */ + teaminfo = 1 + (struct teaminfo_s *) malloc(sizeof(*teaminfo) * (number_of_teams + 2)); + + strcpy(teaminfo[-1].name, "Independant"); + teaminfo[-1].letter = 'I'; + strcpy(teaminfo[-1].shortname, "IND"); + +// load_default_teamlogos(); /* loads the first 4 team logos */ + + for (i = 0; i < number_of_teams; i++) { + sprintf(teaminfo[i].name, "Team #%d", i); + teaminfo[i].letter = 'J' + i; /* I, J through P */ + sprintf(teaminfo[i].shortname, "T%02d", i); + + /* we should draw something nifty here */ + if (i >= 4) /* the first 4 have been loaded already. */ + teaminfo[i].shield_logo = W_StoreBitmap(1, 1, (char*)&i, w); + /* XXX uh-oh if more than 4 teams */ + } +} + +void +free_teams(void) +{ + int i; + for (i = 0; i < number_of_teams; i++) { + free (teaminfo[i].shield_logo); + } + /* we offsetted by 1 to make room for IND */ + free(teaminfo - 1); + teaminfo = 0; +} + +void +free_torps(void) +{ + free(torps); + torps = 0; +} + +void +free_phasers(void) +{ + free(phasers); + phasers = 0; +} + +void +free_plasmas(void) +{ + free(plasmatorps); + plasmatorps = 0; +} + +void +free_thingies(void) +{ + free(thingies); + thingies = 0; +} + +void +free_ranks(void) +{ + int i; + for (i = 0; i < nranks2; i++) + if (ranks2[i].name) + free(ranks2[i].name); + free(ranks2); + ranks2 = 0; +} + +void +free_royal(void) +{ + int i; + for (i = 0; i < nroyals; i++) + if (royal[i].name) + free(royal[i].name); + + free(royal); + royal = 0; +} +void handleGPsizes (struct gp_sizes_spacket *pkt) +{ free_ranks(); free_royal(); @@ -3126,32 +3340,33 @@ free_phasers(); free_plasmas(); free_thingies(); -*/ + nplayers = pkt->nplayers; number_of_teams = pkt->nteams; // shiptypes nranks2 = pkt->nranks; nroyals = pkt->nroyal; + // Code doesn't support nphasers ntorps or plasmas changing - BB nphasers = pkt->nphasers; ntorps = pkt->ntorps; nplasmas = pkt->nplasmas; npthingies = pkt->nthingies; ngthingies = pkt->gthingies; -/* + // gwidth // flags load_generic_teams(); - reinit_ranks(); - reinit_royal(); + initialize_ranks(); + initialize_royal(); resize_players(); initialize_torps(); initialize_phasers(); initialize_plasmas(); initialize_thingies(); -*/ + } void handleGPteam (struct gp_team_spacket *pkt)