Update of /cvsroot/netrek/server/Vanilla/robotd In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv28256/robotd Modified Files: assault.c data.c data.h decide.c dmessage.c dodge.c escort.c getarmies.c input.c main.c robot.c robot.h socket.c struct.h update_players.c util.c Log Message: merge 2.11.1 from darcs Index: dmessage.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/dmessage.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- dmessage.c 22 Apr 2006 02:16:46 -0000 1.3 +++ dmessage.c 1 Jun 2006 03:17:25 -0000 1.4 @@ -84,6 +84,8 @@ "wrap - toggle wrap-around galaxy", "woff - toggle no weapon", "coff - toggle no cloak", + "hcr - toggle logic that assumes humans carry", + "ogh (ogg happy) - switch logic to ogg carriers while bombing", "", "QUERY", @@ -229,12 +231,11 @@ return; } - /* Don't accept commands for newbie server. Allow showstate for - debugging. */ -/* if(strncmp(m, "showstate", 5)==0) - show_state(); - else */ - if (inl) return; + /* don't allow players to message bots. + But allow local admin to send directives through terminal + also allow bots to read commands file. + */ + if (inl && !std) return; if((flags & MINDIV) || std){ if(!strcmp(me->p_login, PRE_T_ROBOT_LOGIN) @@ -1150,6 +1151,16 @@ sprintf(buf, "random torps %s", randtorp?"on":"off"); response(buf); } + else if(strncmp(m, "hcr", 3)==0){ + hm_cr = !hm_cr; + sprintf(buf, "humans carry %s", hm_cr?"on":"off"); + response(buf); + } + else if(strncmp(m, "ogh", 3)==0){ + ogg_happy = !ogg_happy; + sprintf(buf, "ogg while bombing %s", ogg_happy?"on":"off"); + response(buf); + } else if(strncmp(m, "detall", 6)==0){ detall = !detall; sprintf(buf, "detall %s", detall?"on":"off"); @@ -1863,10 +1874,16 @@ dist.distype = i; dist.close_pl = me_p->closest_pl->pl_no; - dist.close_en = _state.closest_e->p->p_no; - dist.close_fr = _state.closest_f->p->p_no; - dist.close_j = (_state.closest_e->dist < _state.closest_f->dist) ? - dist.close_en : dist.close_fr; + dist.close_en = _state.closest_e ? _state.closest_e->p->p_no : me->p_no; + dist.close_fr = _state.closest_f ? _state.closest_f->p->p_no : me->p_no; + if(!_state.closest_f) { + dist.close_j = dist.close_en; + } else if(!_state.closest_e) { + dist.close_j = dist.close_fr; + } else { + dist.close_j = (_state.closest_e->dist < _state.closest_f->dist) ? + dist.close_en : dist.close_fr; + } /* These are just guesses.... */ dist.tclose_pl = 0; Index: robot.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/robot.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- robot.c 12 May 2006 03:44:48 -0000 1.4 +++ robot.c 1 Jun 2006 03:17:25 -0000 1.5 @@ -719,7 +719,7 @@ } if((me->p_flags & PFCLOAK) && me->p_ship.s_type != ASSAULT && (!pl || !(pl->pl_flags & PLFUEL))){ - req_cloak_off(); + req_cloak_off("recharge: no fuel planet"); } if(_state.pl_danger){ @@ -1121,7 +1121,7 @@ for (i = 0, pt = &plasmatorps[0]; i < MAXPLASMA * MAXPLAYER; i++, pt++) { if (pt->pt_status != PTMOVE) continue; - if(_server == SERVER_GRIT){ + if(_server == SERVER_GRIT || _state.torp_bounce){ if(!(pt->pt_war & me->p_team)) continue; } Index: dodge.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/dodge.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- dodge.c 22 Apr 2006 02:16:46 -0000 1.2 +++ dodge.c 1 Jun 2006 03:17:25 -0000 1.3 @@ -110,6 +110,10 @@ if(!WAR(j)){ /* friendly torps */ init_ftorps(i, j); + /* With ping-pong plasma, a friendly player's plasma can become + hostile, if an enemy has bounced it. */ + if(_state.torp_bounce) + goto check_plasma; continue; } @@ -220,6 +224,10 @@ /* plasma */ pt = &plasmatorps[i]; if(pt->pt_status == PTMOVE){ + /* Skip non-hostile plasmas */ + if( !(pt->pt_war & me->p_team) && + !((me->p_hostile|me->p_swar) & pt->pt_team)) + continue; ts = SH_PLASMASPEED(j); tx = pt->pt_x; ty = pt->pt_y; dx = tx - me->p_x; dy = ty - me->p_y; Index: update_players.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/update_players.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- update_players.c 22 Apr 2006 02:16:46 -0000 1.2 +++ update_players.c 1 Jun 2006 03:17:25 -0000 1.3 @@ -141,12 +141,16 @@ orbit_check(p, j); army_check1(p, j); army_check2(p, j); + if (hm_cr) + army_check3(p, j); + } + + if(p->invisible) { + p->closest_pl = NULL; + } else { + p->closest_pl = closest_planet(j, &pldist, p->closest_pl); + p->closest_pl_dist = pldist; } - if(p->invisible) - p->closest_pl = NULL; - else - p->closest_pl = closest_planet(j, &pldist, p->closest_pl); - p->closest_pl_dist = pldist; if(j->p_flags & PFBOMB) p->bombing = _udcounter; @@ -404,6 +408,8 @@ struct planet *pl; bool ohostile = 0, opl = 0; int pa; + float ptrate; /* planet taking rate */ + static int count=0; if(!(j->p_flags & PFORBIT)) return; /* @@ -468,6 +474,58 @@ p->armies = troop_capacity(j); } + +/* A more intuitive way of figuring out who carries in + a pickup game. Only works with humans */ +army_check3(p, j) + + Player *p; + struct player *j; +{ + float ptrate; /* planet taking rate */ + + /* a human alive for long time with enough kills to drop */ + /* just assume he carries as he can trick a bot */ + if ( j->p_kills == 0 ) /* reset the fuse on death */ + p->killfuse = 0; + + if ( j->p_kills >= 0.51 ) /* increment the fuse tunable JKH */ + p->killfuse = p->killfuse + j->p_kills; + + if ( NotRobot(p,j) ) { + if (p->killfuse >= 3000) { /* about 5 min with 1 kill */ + p->armies = troop_capacity(j); + p->plcarry = 100.0; + } + } + + /* > 1.5 kill & high planet rating on player database */ + if ( j->p_kills >= 1.5 ) { + ptrate = (j->p_stats.st_tplanets * 100000) / j->p_stats.st_tticks; + if ( ptrate > 7.0 ) { /* about a planet rating of 4 */ + if ( NotRobot(p,j) ) { + p->armies = troop_capacity(j); + p->plcarry = 100.0; + } + } + } + +} + +NotRobot(p, j) + + Player *p; + struct player *j; +{ + + if ( (strcmp(j->p_login,"robot!") != 0) || !(j->p_flags&PFBPROBOT) ) { + return 1; + } else { + return 0; + } + +} + calc_speed(p, j) Player *p; @@ -1321,7 +1379,7 @@ { register k; - register struct planet *pl, *rp = NULL; + register struct planet *pl, *rp = opl; register d, mdist = INT_MAX; if(opl && (mdist = ihypot((double)(j->p_x - opl->pl_x), @@ -1330,8 +1388,6 @@ return opl; } - *dist = INT_MAX; - for(k=0, pl=planets; k < MAXPLANETS; k++, pl++){ d = ihypot((double)(j->p_x - pl->pl_x), (double)(j->p_y - pl->pl_y)); Index: input.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/input.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- input.c 22 Apr 2006 02:16:46 -0000 1.2 +++ input.c 1 Jun 2006 03:17:25 -0000 1.3 @@ -22,18 +22,51 @@ int recflag = 0; + +/* setflag() + * + * Returns an incrementing number from 0 during start of program + * and stores it in global variable _udcounter. + * _udcounter increments by 1 for every 100ms of time that + * has passed using the mtime function, which returns + * gettimeofday information to the nearest millisecond. + * + * Function used to return negative numbers when mtime + * cycled (anywhere between 2 and 18 hours). Added code + * so udcounter is always incrementing + * + * Function may still break if unix super-user executes + * set-time-of-day function, via unix command. + */ setflag() { - static int start; + static int start=0; /* start of the robot program */ + static int cycle=0; /* how many times udtime cycles */ + static int cyclestarted=0; + int udtime; /* 100ms increments JKH */ + + udtime = mtime(1)/100; + if(!start){ - start = mtime(1)/100; + start = udtime; _udcounter = 0; } - else - _udcounter = mtime(1)/100 - start; - /* - printf("_udcounter %d\n", _udcounter); - */ + else { + _udcounter = udtime - start + + (cycle * ( (0x0000ffff*1000+999)/100 + 1 ) ); + } /* the max udtime could ever be + 1 */ + + /* increment cycle once when udtime flips */ + if ( (udtime < start) && (cyclestarted == 0) ) { + cyclestarted = 1; + cycle = cycle + 1; + } + + /* reset cyclestart when udtime is "normal" again */ + if ( udtime > start ) { + cyclestarted = 0; + } + } input() Index: data.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/data.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- data.c 22 Apr 2006 02:16:46 -0000 1.3 +++ data.c 1 Jun 2006 03:17:25 -0000 1.4 @@ -83,7 +83,7 @@ int lastUpdate[MAXPLAYER]={0}; /* Last update of this player */ int timerDelay=200000; /* micro secs between updates */ int reportKills=1; /* report kill messages? */ -float updates=1.0; +float updates=2.0; int nopwd=0; int randtorp=0; @@ -156,4 +156,6 @@ int oggv_packet=0; int off=0,def=0; -int ignoreTMode = 0; +int ignoreTMode = 0; +int hm_cr = 0; /* assume humans carry if they have kills */ +int ogg_happy = 0; /* ogg carriers while bombing */ Index: robot.h =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/robot.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- robot.h 21 Mar 2005 05:23:45 -0000 1.1 +++ robot.h 1 Jun 2006 03:17:25 -0000 1.2 @@ -35,6 +35,7 @@ int run_t; int fuel, subshield, shield, wpntemp, subdamage, damage; int armies, pl_armies, beam_fuse; + int killfuse; /* how long with kills */ float plcarry; int last_comm_beamup; /* last position */ Index: data.h =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/data.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- data.h 22 Apr 2006 02:16:46 -0000 1.3 +++ data.h 1 Jun 2006 03:17:25 -0000 1.4 @@ -160,7 +160,9 @@ extern int oggv_packet; extern int off,def; -extern int ignoreTMode; +extern int ignoreTMode; +extern int hm_cr; /* assume a human carries mode */ +extern int ogg_happy; /* ogg close by carriers if bombing */ /*this is also defined in ../include/data.h*/ #define PRE_T_ROBOT_LOGIN "Pre_T_Robot!" Index: escort.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/escort.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- escort.c 21 Mar 2005 05:23:45 -0000 1.1 +++ escort.c 1 Jun 2006 03:17:25 -0000 1.2 @@ -49,7 +49,7 @@ /* check internal state */ switch(_state.escort){ case 0: - req_cloak_off(); + req_cloak_off("escort: 0"); /* just got request, need to go to planet */ if(DEBUG & DEBUG_ESCORT) printf("goto escort planet %s\n", escpl->pl_name); @@ -58,7 +58,7 @@ case 1: /* close enough to escort planet .. wait for escortee */ - req_cloak_off(); + req_cloak_off("escort: 1"); if(DEBUG & DEBUG_ESCORT) printf("wait for escort %s\n", escp->p->p_mapchars); wait_for_escort(escp, escpl); @@ -82,7 +82,7 @@ break; case 5: - req_cloak_off(); + req_cloak_off("escort: 5"); /* do defenders */ if(DEBUG & DEBUG_ESCORT) printf("no defenders\n"); Index: util.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/util.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- util.c 22 Apr 2006 02:16:46 -0000 1.4 +++ util.c 1 Jun 2006 03:17:25 -0000 1.5 @@ -442,19 +442,16 @@ } #endif - -mfprintf(char *format, ...) +mfprintf(FILE *fo, char *format, ...) { - FILE *fo; va_list ap; if(!read_stdin) return; va_start(ap, format); - fo = va_arg(ap, FILE *); (void)vfprintf(fo, format, ap); - fflush(stdout); + fflush(fo); va_end(ap); } Index: struct.h =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/struct.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- struct.h 22 Apr 2006 02:16:46 -0000 1.3 +++ struct.h 1 Jun 2006 03:17:25 -0000 1.4 @@ -44,6 +44,7 @@ #define PFTRACT 0x400000 /* tractor beam activated */ #define PFPRESS 0x800000 /* pressor beam activated */ #define PFDOCKOK 0x1000000 /* docking permission */ +#define PFBPROBOT 0x80000000 /* OggV Packet to ID other bots */ #define KQUIT 0x01 /* Player quit */ #define KTORP 0x02 /* killed by torp */ Index: decide.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/decide.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- decide.c 12 May 2006 03:44:48 -0000 1.4 +++ decide.c 1 Jun 2006 03:17:25 -0000 1.5 @@ -238,21 +238,24 @@ else if(!unknownpl(_state.assault_planet) && _state.assault_planet->pl_armies < 5){ unassault_c("already bombed."); - check_ogg(NULL,20000); /* test JKH */ + if (ogg_happy) + check_ogg(NULL,20000); /* test JKH */ check_bomb(NULL); return; } if(myteam_bombing(_state.assault_planet, _state.assault_planet->pl_mydist)){ unassault_c("somebody else bombing"); - check_ogg(NULL,20000); /* test JKH */ + if (ogg_happy) + check_ogg(NULL,20000); /* test JKH */ check_bomb(NULL); return; } if(_state.assault_planet->pl_mydist < 20000 && pl_defended(_state.assault_planet, 2)){ unassault_c("planet defended"); - check_ogg(NULL,20000); /* test JKH */ + if (ogg_happy) + check_ogg(NULL,20000); /* test JKH */ check_bomb(NULL); return; } @@ -683,6 +686,7 @@ if(pls->total_textra_armies == 0 && me->p_armies == 0) return 0; + /* Look for closest takeable enemy planet */ for(k=0; k< pls->num_warteamsp; k++){ pl = pls->warteam_planets[k]; @@ -697,20 +701,23 @@ min_dist = pl->pl_mydist; } } - if(!(pl->pl_flags & PLAGRI) || me->p_armies >= 5){ - min_dist = GWIDTH; /* ind overrides non-ind */ - for(k=0; k< pls->num_indsp; k++){ - pl = pls->ind_planets[k]; - /* - if(pl->pl_mydist < 20000 && pl_defended(pl,3)) continue; - */ + /* take indep planet first over regular planets */ + /* but take agris first if you have the armies */ + if (!tpl || !(tpl->pl_flags&PLAGRI && me->p_armies >= 5) ) { + min_dist = GWIDTH; /* ind overrides non-ind */ + for(k=0; k< pls->num_indsp; k++){ + pl = pls->ind_planets[k]; + + /* + if(pl->pl_mydist < 20000 && pl_defended(pl,3)) continue; + */ - if(pl->pl_mydist < min_dist){ - tpl = pl; - min_dist = pl->pl_mydist; - } - } + if(pl->pl_mydist < min_dist){ + tpl = pl; + min_dist = pl->pl_mydist; + } + } } if(tpl){ if(pls->total_textra_armies + me->p_armies < tpl->pl_armies) Index: assault.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/assault.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- assault.c 12 May 2006 03:44:48 -0000 1.3 +++ assault.c 1 Jun 2006 03:17:25 -0000 1.4 @@ -46,25 +46,38 @@ /* determine if there is risk of death due to res of opponent */ static int risk_res_death(struct planet *pl) { - if (pl == NULL) return 0; - /* One of the home planets identified by server etc/sysdef PLANETS */ - if (pl->pl_flags & PLHOME) return 1; - /* Altair in standard position */ - if (pl->pl_no == 7 && pl->pl_x == 11000 && pl->pl_y == 75000) return 1; - /* Draconis in standard position */ - if (pl->pl_no == 16 && pl->pl_x == 28000 && pl->pl_y == 23000) return 1; - /* Scorpii in standard position */ - if (pl->pl_no == 26 && pl->pl_x == 70720 && pl->pl_y == 26320) return 1; - /* Within rectangular phaser distance of any home planet res point */ - int i; - for (i=0,pl=planets;i<MAXPLANETS;i++,pl++) { - if (pl->pl_flags & PLHOME) { - if(ABS(pl->pl_x - me->p_x) < 12000 && ABS(pl->pl_y - me->p_y) < 12000) { - return 1; + /* Home planet locations. This will not work if the HWs are not at + their normal indexes. This should always be the case, even for + non-standard planet layouts. */ + const static int hw[4] = {0, 10, 20, 30}; + int i; + +#if 0 + /* Code to find home planets by name, like the bot does to refit. */ + static int found_hw = 0; + if(!found_hw) { + extern struct planet *team_planet(int); + hw[0] = (team_planet(FED)?:&planets[0])->pl_no; + hw[1] = (team_planet(ROM)?:&planets[0])->pl_no; + hw[2] = (team_planet(KLI)?:&planets[0])->pl_no; + hw[3] = (team_planet(ORI)?:&planets[0])->pl_no; + found_hw = 1; + mfprintf(stderr, "planets at %d %d %d %d\n", hw[0], hw[1], hw[2], hw[3]); + } +#endif + + if(pl == NULL) return 0; + + for(i = 0; i < 4; i++){ + if((1<<i) == me->p_team) continue; /* No danger at MY homeworld */ + + pl = &planets[hw[i]]; + /* Inside rectangular phaser/tractor range of a ressing ship. */ + if(ABS(pl->pl_x - me->p_x) < 12200 && ABS(pl->pl_y - me->p_y) < 12200){ + return 1; } - } - } - return 0; + } + return 0; } goto_assault_planet() @@ -176,7 +189,7 @@ #ifdef nodef if(!do_cloak(0)) - req_cloak_off(); + req_cloak_off("no do cloak"); #endif cloak=0; /* start assuming you don't need to cloak */ @@ -195,7 +208,31 @@ else req_cloak_off("no cloak in assault_planet()"); - if(armies > 4){ + /* Planets that _can_ be dropped on: + 1. Planets owned by your team + 2. Planets that you are hostile to + 3. Independent planets (owned by team 0) + Everything else can't be dropped on. Planets in groups 1 and 3 _can't_ + be bombed, only group 2 can be bombed, ie. bombable planets is a + proper subset of droppable planets. */ + + /* Turn off assault for non-droppable (thus non-bombable too) planets. */ + if(!unknownpl(pl) && !( (pl->pl_owner == me->p_team) || + ((me->p_swar|me->p_hostile) & pl->pl_owner) || + (pl->pl_owner == 0) )){ + req_shields_up(); + unassault_c("planet not droppable"); + return; + } + + if(pl->pl_owner == me->p_team && pl->pl_armies >= 4){ + req_shields_up(); + unassault_c("planet fully reinforced"); + return; + } + + /* Only bomb bombable planets. */ + if(armies > 4 && ((me->p_swar|me->p_hostile) & pl->pl_owner)){ req_bomb(); return; } Index: main.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/main.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- main.c 22 Apr 2006 02:16:46 -0000 1.3 +++ main.c 1 Jun 2006 03:17:25 -0000 1.4 @@ -430,9 +430,9 @@ if(team != _state.team && team != -1){ timer2 = 0; _state.team = team; - if(!teamRequest(team, s_type)){ - mfprintf(stderr, "team or ship rejected.\n"); - showteams(); + if (!teamRequest(team, s_type)){ + mfprintf(stderr, "team or ship rejected.\n"); + showteams(); } else break; Index: socket.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/socket.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- socket.c 22 Apr 2006 02:16:46 -0000 1.3 +++ socket.c 1 Jun 2006 03:17:25 -0000 1.4 @@ -1708,6 +1708,7 @@ } thetorp->pt_status=packet->status; thetorp->pt_war=packet->war; + thetorp->pt_team=players[thetorp->pt_owner].p_team; if (thetorp->pt_status == PTEXPLODE) { do_plasmadamage(p, j, thetorp); j->p_nplasmatorp--; @@ -1919,8 +1920,8 @@ #ifdef ATM if (fd == udpSock) { mfprintf(stderr, "Tried to write %d, 0x%x, %d (error %d)\n", - fd, buf, bytes, errno); - perror("write"); + fd, buf, bytes, errno); + perror("write"); printUdpInfo(); } #endif @@ -2391,7 +2392,7 @@ break; default: mfprintf(stderr, "netrek: Got funny reply (%d) in UDP_REPLY packet\n", - packet->reply); + packet->reply); break; } Index: getarmies.c =================================================================== RCS file: /cvsroot/netrek/server/Vanilla/robotd/getarmies.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- getarmies.c 22 Apr 2006 02:16:46 -0000 1.2 +++ getarmies.c 1 Jun 2006 03:17:25 -0000 1.3 @@ -173,7 +173,7 @@ else{ _state.lock = 0; req_shields_up(); - req_cloak_off(); + req_cloak_off("no armies to beam"); _state.p_desspeed = me->p_speed; return; }