Update of /cvsroot/netrek/server/Vanilla/ntserv In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5335/ntserv Modified Files: commands.c Log Message: remove unused code Index: commands.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/ntserv/commands.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- commands.c 26 Apr 2006 09:52:43 -0000 1.5 +++ commands.c 6 May 2006 12:05:57 -0000 1.6 @@ -1,5 +1,6 @@ /* * Commands.c + * Not part of ntserv or daemon */ /* @@ -53,31 +54,6 @@ int do_generic_vote(char *comm, int who); int do_start_robot(); -#if !defined(INL) -int do_player_eject(); -#endif - -#if defined (AUTO_INL) && !defined(INL) -int do_start_inl(); -#endif - -#if defined (AUTO_PRACTICE) && !defined(BASEP) -int do_start_basep(); -#endif - -#if defined(AUTO_HOCKEY) && !defined(PUCK) -int do_start_puck(); -#endif - -#if defined(AUTO_DOGFIGHT) && !defined(DOG) -int do_start_mars(); -#endif - -#if defined (TRIPLE_PLANET_MAYHEM) -int do_balance(); -int do_triple_planet_mayhem(); -#endif - #if defined (DOG) || defined (PUCK) /* DOG-FIGHTING & PUCK stuff */ extern int do_score_msg(); @@ -394,31 +370,6 @@ struct vote_handler votes[] = { { NULL, 0, 0, 0, NULL, 0, NULL}, /* record 0 */ -#if !defined(INL) - { "EJECT", - VC_TEAM | VC_GLOG | VC_PLAYER, - 2, - 0, - "To eject a player. Ex: 'EJECT 0'", - 120, - do_player_eject }, /* EJECT */ -#endif -#if defined(TRIPLE_PLANET_MAYHEM) && !defined(ROBOT) - { "TRIPLE", - VC_ALL | VC_GLOG, - 2, - 22, - "Start triple planet mayhem by vote", - 0, - do_triple_planet_mayhem }, - { "BALANCE", - VC_ALL | VC_GLOG, - 4, - 23, - "Request team randomise & balance", - 0, - do_balance }, -#endif #if defined (DOG) || defined (PUCK) { "NEWGAME", VC_ALL, @@ -437,15 +388,6 @@ 0, do_change_timekeep }, /* Short game */ #endif -#if defined(AUTO_INL) && !defined(ROBOT) - { "INL", - VC_ALL|VC_GLOG, - 1, - 20, - "Start game under INL rules.", - 0, - do_start_inl}, -#endif #if (defined(AUTO_INL) && defined(INL)) || (defined(BASEP) && defined(AUTO_PRACTICE)) || (defined(AUTO_HOCKEY) && defined(PUCK)) || (defined(AUTO_DOGFIGHT) && defined (DOG)) { "EXIT", VC_ALL, @@ -455,33 +397,6 @@ 0, cleanup}, #endif -#if defined(AUTO_PRACTICE) && !defined(ROBOT) - { "PRACTICE", - VC_ALL, - 1, - 20, - "Start basepractice by majority vote.", - 0, - do_start_basep}, -#endif -#if defined(AUTO_HOCKEY) && !defined(ROBOT) - { "HOCKEY", - VC_ALL|VC_GLOG, - 1, - 20, - "Start hockey by majority vote.", - 0, - do_start_puck}, -#endif -#if defined(AUTO_DOGFIGHT) && !defined(ROBOT) - { "DOGFIGHT", - VC_ALL|VC_GLOG, - 1, - 20, - "Start dogfight tournament by majority vote.", - 0, - do_start_mars}, -#endif }; @@ -592,460 +507,6 @@ return what; } - - - - -#if defined(TRIPLE_PLANET_MAYHEM) -/* -** 16-Jul-1994 James Cameron -** -** Balances teams according to player statistics. -** Intended for use with Triple Planet Mayhem -*/ - -/* -** Tell all that player will be moved -*/ -static void moveallmsg ( int p_no, int ours, int theirs ) -{ - struct player *k = &players[p_no]; - pmessage(0, MALL, "GOD->ALL", - "Balance: %16s (%c%c) is to join the %s", - k->p_name, teamlet[k->p_team], shipnos[p_no], team_name(ours)); -} - -/* -** Move a player to the specified team, if they are not yet there. -** Make them peaceful with the new team, and hostile/at war with the -** other team. -*/ -static void -move(int p_no, int ours, int theirs) -{ - struct player *k = &players[p_no]; - int queue; - - if ( k->p_team != ours ) { - pmessage(k->p_no, MINDIV, addr_mess(k->p_no,MINDIV), - "%s: please SWAP SIDES to the %s", k->p_name, team_name(ours)); - } - else { - pmessage(k->p_no, MINDIV, addr_mess(k->p_no,MINDIV), - "%s: please remain with the %s", k->p_name, team_name(ours)); - } - - printf("Balance: %16s (%s) is to join the %s\n", - k->p_name, k->p_mapchars, team_name(ours)); - - /* cope with a balance during INL pre-game, if we don't shift players who - are on the QU_HOME or QU_AWAY queues then the queue masks will force - them to join the team they were on anyway. */ - queue = ( ours == FED ) ? QU_HOME : QU_AWAY; - if (k->w_queue != QU_PICKUP && k->w_queue != queue) { - queues[k->w_queue].free_slots++; - k->w_queue = queue; - queues[k->w_queue].free_slots--; - } - - k->p_hostile |= theirs; - k->p_swar |= theirs; - k->p_hostile &= ~ours; - k->p_swar &= ~ours; - k->p_war = (k->p_hostile | k->p_swar); - k->p_team = ours; - sprintf(k->p_mapchars, "%c%c", teamlet[k->p_team], shipnos[p_no]); - sprintf(k->p_longname, "%s (%s)", k->p_name, k->p_mapchars); - - k->p_status = PEXPLODE; - k->p_whydead = KPROVIDENCE; /* should be KTOURNSTART? */ - if (k->p_ship.s_type == STARBASE) - k->p_explode = 2 * SBEXPVIEWS; - else - k->p_explode = 10; - k->p_ntorp = 0; - k->p_nplasmatorp = 0; - k->p_hostile = (FED | ROM | ORI | KLI); - k->p_war = (k->p_hostile | k->p_swar); -} - -/* -** Return two team masks corresponding to the teams of the first two -** teams found in the player list. -*/ -static void sides ( int *one, int *two ) -{ - struct player *k; - int i; - int unseen; - - unseen = (FED | ROM | ORI | KLI); - *one = 0; - *two = 0; - k = &players[0]; - for(i=0;i<MAXPLAYER;i++) - { - if ( (k->p_status != PFREE) && (!(k->p_flags & PFROBOT))) - { - if ( ( unseen & k->p_team ) != 0 ) - { - if ( *one == 0 ) - { - *one = k->p_team; - unseen &= ~k->p_team; - k++; - continue; - } - *two = k->p_team; - return; - } - } - k++; - } -} - -/* -** Calculate a player value -*/ -static int value ( struct player *k ) -{ - return - (int) - ( - (float) - ( -#ifdef LTD_STATS - ltd_bombing_rating(k) + - ltd_planet_rating(k) + - ltd_offense_rating(k) -#else - bombingRating(k) + - planetRating(k) + - offenseRating(k) -#endif - ) * 100.0 - ); -} - -/* -** Balance the teams -** -** Uses an exhaustive algorithm (I'm exhausted!) to find the best combination -** of the current players that balances the teams in terms of statistics. -** The algorithm will support only the number of players that fits into the -** number of bits in an int. -** -** If there are multiple "best" combinations, then the combination -** involving the least number of team swaps will be chosen. -*/ -int do_balance(void) -{ - int i, j; /* miscellaneous counters */ - int records; /* number of players in game */ - int one; /* team number one mask */ - int two; /* team number two mask */ - - struct player *k; /* pointer to current player */ - - struct item - { - int p_no; /* player number */ - int p_value; /* calculated player value */ - int p_team; /* team player on previously */ - } list[MAXPLAYER]; /* working array */ - - struct - { - int combination; /* combination number */ - int value; /* team balance difference */ - int one; /* team one total value */ - int two; /* team two total value */ - int swaps; /* number of swaps involved */ - } best; /* best team combination */ - - /* which teams are playing? give up if only one found */ - sides ( &one, &two ); - if ( two == 0 ) - { - pmessage ( 0, MALL, "GOD->ALL", - "Can't balance only one team!" ); - pmessage ( 0, MALL, "GOD->ALL", - "Please could somebody move to another team, then all vote again?" ); - return 0; - } - - /* initialise best to worst case */ - best.combination = -1; - best.value = 1<<30; - best.one = 0; - best.two = 0; - best.swaps = 1<<30; - - /* reset working array */ - for(i=0;i<MAXPLAYER;i++) - { - list[i].p_no = 0; - list[i].p_value = 0; - } - - /* insert players in working array */ - records = 0; - k = &players[0]; - for(i=0;i<MAXPLAYER;i++) - { - if ( (k->p_status != PFREE) && (!(k->p_flags & PFROBOT))) - { - list[records].p_no = k->p_no; - list[records].p_value = value ( k ); - list[records].p_team = k->p_team; - records++; - } - k++; - } - - /* randomise the working array; may cause different team mixes */ - for(i=0;i<records;i++) - { - int a, b; - struct item swapper; - - a = random() % records; - b = random() % records; - - swapper = list[a]; - list[a] = list[b]; - list[b] = swapper; - } - - /* loop for every _possible_ combination to find the best */ - for(i=0;i<(1<<records);i++) - { - int difference; /* difference in team total */ - int value_a, value_b; /* total stats per team */ - int count_a, count_b; /* total count of players on team */ - int swaps; /* number of swaps involved */ - - /* if this a shadow combination already considered, ignore it */ - /* if ( ( i ^ ( ( 1<<records ) - 1 ) ) < i ) continue; */ - /* disabled - it will interfere with swap minimisation goal */ - - /* is this combination an equal number of players each side? */ - count_a = 0; - count_b = 0; - - for(j=0;j<records;j++) - if((1<<j)&i) - count_a++; - else - count_b++; - - /* skip this combination if teams are significantly unequal */ - if ( abs ( count_a - count_b ) > 1 ) continue; - - /* reset team total for attempt */ - value_a = 0; - value_b = 0; - - /* calculate team total stats */ - for(j=0;j<records;j++) - if((1<<j)&i) - value_a += list[j].p_value; - else - value_b += list[j].p_value; - - /* calculate number of swaps this combination produces */ - swaps = 0; - for(j=0;j<records;j++) - if((1<<j)&i) - { - if ( list[j].p_team != one ) swaps++; - } - else - { - if ( list[j].p_team != two ) swaps++; - } - - /* calculate difference in team total stats */ - difference = abs ( value_a - value_b ); - - /* if this combo is better than the previous one we had, - or the combo is the same and the number of swaps is lower... */ - if ( ( difference < best.value ) - || ( ( difference == best.value ) - && ( swaps < best.swaps ) ) ) - { - /* remember it */ - best.value = difference; - best.combination = i; - best.one = value_a; - best.two = value_b; - best.swaps = swaps; - } - } - - /* announce movements intended */ - for(j=0;j<records;j++) - if ( (1<<j)&best.combination ) - moveallmsg ( list[j].p_no, one, two ); - - for(j=0;j<records;j++) - if ( !((1<<j)&best.combination) ) - moveallmsg ( list[j].p_no, two, one ); - - /* move players to their teams */ - for(j=0;j<records;j++) - if ( (1<<j)&best.combination ) - move ( list[j].p_no, one, two ); - else - move ( list[j].p_no, two, one ); - - /* advise all of resultant team mix difference */ - pmessage ( 0, MALL, "GOD->ALL", - "The %s total rating will be %.2f", - team_name(one), - (float) ( best.one / 100.0 ) ); - - pmessage ( 0, MALL, "GOD->ALL", - "The %s total rating will be %.2f", - team_name(two), - (float) ( best.two / 100.0 ) ); - - return 0; -} - -int do_triple_planet_mayhem(void) -{ - int i; - - struct player* j; - - /* balance the teams */ - do_balance(); - - /* move all planets off the galaxy */ - for (i=0; i<MAXPLANETS; i++) - { - planets[i].pl_flags = 0; - planets[i].pl_owner = 0; - planets[i].pl_x = -10000; - planets[i].pl_y = -10000; - planets[i].pl_info = 0; - planets[i].pl_armies = 0; - strcpy ( planets[i].pl_name, "" ); - } - - /* disable Klingon and Orion teams; stop people from joining them */ - planets[20].pl_couptime = 999999; /* no Klingons */ - planets[30].pl_couptime = 999999; /* no Orions */ - - /* initialise earth */ - i = 0; - planets[i].pl_flags |= FED | PLHOME | PLCORE | PLAGRI | PLFUEL | PLREPAIR; - planets[i].pl_x = 40000; - planets[i].pl_y = 65000; - planets[i].pl_armies = 40; - planets[i].pl_info = FED; - planets[i].pl_owner = FED; - strcpy ( planets[i].pl_name, "Earth" ); - - /* initialise romulus */ - i = 10; - planets[i].pl_flags |= ROM | PLHOME | PLCORE | PLAGRI | PLFUEL | PLREPAIR; - planets[i].pl_x = 40000; - planets[i].pl_y = 35000; - planets[i].pl_armies = 40; - planets[i].pl_info = ROM; - planets[i].pl_owner = ROM; - strcpy ( planets[i].pl_name, "Romulus" ); - - /* initialise indi */ - i = 18; - planets[i].pl_flags |= PLFUEL | PLREPAIR; - planets[i].pl_flags &= ~PLAGRI; - planets[i].pl_x = 15980; - planets[i].pl_y = 50000; - planets[i].pl_armies = 4; - planets[i].pl_info &= ~ALLTEAM; - strcpy ( planets[i].pl_name, "Indi" ); - - /* fix all planet name lengths */ - for (i=0; i<MAXPLANETS; i++) - { - planets[i].pl_namelen = strlen(planets[i].pl_name); - } - - /* advise players */ - { - char *list[] = - { - "Galaxy reset for triple planet mayhem!", - "Rule 1: they take Indi, they win,", - "Rule 2: they take your home planet, they win,", - "Rule 3: you can't bomb Indi,", - "Rule 4: you may bomb their home planet, and;", - "Rule 5: all planets are FUEL & REPAIR, home planets are AGRI.", - "" - }; - - for ( i=0; strlen(list[i])!=0; i++ ) - pmessage ( 0, MALL, "GOD->ALL", list[i] ); - } - return 0; -} -#endif /* TRIPLE_PLANET_MAYHEM */ - - -#if !defined(INL) -int do_player_eject(int who, int player, int mflags, int sendto) -{ - register struct player *j; - - j = &players[player]; - - if (j->p_status == PFREE){ - pmessage(sendto, mflags, addr_mess(who,MTEAM), - "That player is not in the game"); - return; - } - if (j->p_flags & PFROBOT) { - pmessage(sendto, mflags, addr_mess(players[who].p_team,MTEAM), - "You cannot eject a robot, twinks!"); - return; - } - if (j->p_team != players[who].p_team){ - pmessage(players[who].p_team, MTEAM, - addr_mess(players[who].p_team,MTEAM), - "You can only eject your own teammates, twinks!"); - return; - } - - pmessage(0, MALL, addr_mess(who,MALL), - " %2s has been ejected by the players", j->p_mapchars); - -#if defined (DOG) - reset_player(j->p_no); - dont_score(j->p_no); -#endif - - eject_player(j->p_no); - if (freeslot(j) < 0) { - ERROR(1,("do_player_eject: freeslot failed\n")); - } -} - -eject_player(int who) -{ - struct player* j; - - j = &players[who]; - j->p_ship.s_type = STARBASE; - j->p_whydead=KQUIT; - j->p_explode=10; - j->p_status=PEXPLODE; - j->p_whodead=me->p_no; -} -#endif - check_listing(comm) char *comm; { @@ -1197,54 +658,6 @@ return 1; } -#if defined(AUTO_PRACTICE) && !defined(BASEP) -int do_start_basep(who, mflags, sendto) -int who, mflags,sendto; -{ - if (vfork() == 0) { - (void) SIGNAL(SIGALRM,SIG_DFL); - execl(Basep, "basep", 0); - perror(Basep); - } -} -#endif - -#if defined(AUTO_INL) && !defined(INL) -int do_start_inl(who, mflags, sendto) -int who, mflags, sendto; -{ - if (vfork() == 0) { - (void) SIGNAL(SIGALRM,SIG_DFL); - execl(Inl, "inl", 0); - perror(Inl); - } -} -#endif - -#if defined(AUTO_HOCKEY) && !defined(PUCK) -int do_start_puck(who, mflags, sendto) -int who, mflags, sendto; -{ - if (vfork() == 0) { - (void) SIGNAL(SIGALRM,SIG_DFL); - execl(Puck, "puck", 0); - perror(Puck); - } -} -#endif - -#if defined(AUTO_DOGFIGHT) && !defined(DOG) -int do_start_mars(who, mflags, sendto) -int who, mflags, sendto; -{ - if (vfork() == 0) { - (void) SIGNAL(SIGALRM,SIG_DFL); - execl(Mars, "mars", 0); - perror(Mars); - } -} -#endif - char *addr_mess(who,type) int who,type; { @@ -1335,6 +748,7 @@ votes[i].type, ch, votes[i].desc); } } + return; } #ifndef INL