Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS update: Vanilla/robotd



Date:	Sunday March 5, 2000 @ 9:56
Author:	xyzzy

Update of /home/netrek/cvsroot/Vanilla/robotd
In directory swashbuckler.fortress.real-time.com:/var/tmp/cvs-serv10187

Modified Files:
	defs.h dmessage.c getarmies.c struct.h util.c 
Log Message:
Give the robot the ability to send RCDs.  It will currently only use them when
sending its status or when taking planets.


****************************************

Index: Vanilla/robotd/defs.h
diff -u Vanilla/robotd/defs.h:1.1 Vanilla/robotd/defs.h:1.2
--- Vanilla/robotd/defs.h:1.1	Tue Feb 22 16:49:30 2000
+++ Vanilla/robotd/defs.h	Sun Mar  5 09:56:48 2000
@@ -52,6 +52,8 @@
 #define MAXMESSAGE 50
 #define MAXREVIEWMESSAGE 20
 
+#define MSG_LEN		80
+
 #define rosette(x)   ((((x) + 8) / 16) & 15)
 /* #define rosette(x)   ((((x) + 256/VIEWS/2) / (256/VIEWS) + VIEWS) % VIEWS) */
 /*                      (((x + 8) / 16 + 16)  %  16)  */
Index: Vanilla/robotd/dmessage.c
diff -u Vanilla/robotd/dmessage.c:1.1 Vanilla/robotd/dmessage.c:1.2
--- Vanilla/robotd/dmessage.c:1.1	Tue Feb 22 16:49:30 2000
+++ Vanilla/robotd/dmessage.c	Sun Mar  5 09:56:48 2000
@@ -1823,3 +1823,93 @@
    else
       return "none";
 }
+
+struct distress *loaddistress(enum dist_type i)
+{
+    static struct distress dist;
+
+    dist.sender = me->p_no;
+    dist.dam = (100 * me->p_damage) / me->p_ship.s_maxdamage;
+    dist.shld = (100 * me->p_shield) / me->p_ship.s_maxshield;
+    dist.arms = me->p_armies;
+    dist.fuelp = (100 * me->p_fuel) / me->p_ship.s_maxfuel;
+    dist.wtmp = (100 * me->p_wtemp) / me->p_ship.s_maxwpntemp;
+    dist.etmp = (100 * me->p_etemp) / me->p_ship.s_maxegntemp;
+    
+    /* What is this for??? */
+    dist.sts = (me->p_flags & 0xff) | 0x80;
+
+    dist.wtmpflag =  me->p_flags&PFWEP   ? 1 : 0;
+    dist.etempflag = me->p_flags&PFENG   ? 1 : 0;
+    dist.cloakflag = me->p_flags&PFCLOAK ? 1 : 0;
+
+    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;
+                    
+    /* These are just guesses.... */
+    dist.tclose_pl = 0;
+    dist.tclose_en = 0;
+    dist.tclose_fr = 0;
+    dist.tclose_j = 0;
+
+    dist.cclist[0] = 0x80;
+    dist.preappend[0] = '\0';
+    dist.macroflag = 0;
+
+    return &dist;
+}
+
+/* this converts a dist struct to the appropriate text
+   (excludes F1->FED text bit).. sorry if this is not what we said 
+   earlier jeff.. but I lost the paper towel I wrote it all down on */
+static void Dist2Mesg(struct distress *dist, char *buf)
+{
+    int len, i;
+
+    sprintf(buf, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
+	   (dist->macroflag << 5) + (dist->distype),
+	   dist->fuelp | 0x80,
+	   dist->dam | 0x80,
+	   dist->shld | 0x80,
+	   dist->etmp | 0x80,
+	   dist->wtmp | 0x80,
+	   dist->arms | 0x80,
+	   dist->sts | 0x80,
+	   dist->close_pl | 0x80,
+	   dist->close_en | 0x80,
+	   dist->tclose_pl | 0x80,
+	   dist->tclose_en | 0x80,
+	   dist->tclose_j | 0x80,
+	   dist->close_j | 0x80,
+	   dist->tclose_fr | 0x80,
+           dist->close_fr | 0x80);
+	   
+    /* cclist better be terminated properly otherwise we hose here */
+    i=0;
+    while (((dist->cclist[i] & 0xc0) == 0xc0)) {
+	buf[16+i]=dist->cclist[i];
+	i++;
+    }
+    /* get the pre/append cclist terminator in there */
+    buf[16+i]=dist->cclist[i];
+    buf[16+i+1]='\0';
+
+    len = 16+i+1;
+    if (dist->preappend[0] != '\0') {
+	strncat(buf, dist->preappend, MSG_LEN - len);/* false sense of security? */
+	buf[MSG_LEN - 1] = '\0';
+    }
+}
+
+void send_RCD(struct distress *dist)
+{
+    char buf[MSG_LEN];
+
+    Dist2Mesg(dist, buf);
+    sendMessage(buf, MTEAM|MDISTR, me->p_team);
+}
Index: Vanilla/robotd/getarmies.c
diff -u Vanilla/robotd/getarmies.c:1.1 Vanilla/robotd/getarmies.c:1.2
--- Vanilla/robotd/getarmies.c:1.1	Tue Feb 22 16:49:30 2000
+++ Vanilla/robotd/getarmies.c	Sun Mar  5 09:56:48 2000
@@ -11,6 +11,8 @@
 #include "packets.h"
 #include "robot.h"
 
+struct distress *loaddistress(enum dist_type i);
+void send_RCD(struct distress *dist);
 struct planet *find_army_planet();
 
 /* get armies */
@@ -298,17 +300,21 @@
 {
    static int 	tms;
    char 	*short_name_print();
+   struct distress *dist;
    
    if(!inl && !_state.take_notify) return;
    if(!aspl) return;
 
    if(phase == 0){
       tms = _udcounter;
-      emergency();
+      dist = loaddistress(CARRYING);
+      send_RCD(dist);
    }
    else if(tms > -1){
       if(_udcounter - tms > 10){
-	 pmessage(teamlet[me->p_team], short_name_print(aspl));
+	 dist = loaddistress(TAKE);
+	 dist->tclose_pl = aspl->pl_no;
+	 send_RCD(dist);
 	 tms = -1;
       }
    }
Index: Vanilla/robotd/struct.h
diff -u Vanilla/robotd/struct.h:1.1 Vanilla/robotd/struct.h:1.2
--- Vanilla/robotd/struct.h:1.1	Tue Feb 22 16:49:31 2000
+++ Vanilla/robotd/struct.h	Sun Mar  5 09:56:48 2000
@@ -319,6 +319,7 @@
 #define MINDIV 0x02
 #define MTEAM  0x04
 #define MALL   0x08
+#define MDISTR 0xC0
 
 struct message {
     int m_no;
@@ -358,4 +359,39 @@
     struct phaser	phasers[MAXPLAYER];
     struct mctl		mctl[1];
     struct message	messages[MAXMESSAGE];
+};
+
+enum dist_type {
+        /* help me do series */
+        TAKE=1, OGG, BOMB, SPACE_CONTROL, HELP1, HELP2, HELP3, HELP4,
+
+        /* doing series */
+        ESCORTING, OGGING, BOMBING, CONTROLLING, DOING1, DOING2, DOING3, DOING4,
+
+        /* other info series */
+        FREE_BEER, /* ie. player x is totally hosed now */
+        NO_GAS, /* ie. player x has no gas */
+        CRIPPLED, /* ie. player x is way hurt but may have gas */
+        PICKUP, /* player x picked up armies */
+        POP, /* there was a pop somewhere */
+        CARRYING, /* I am carrying */
+        OTHER1, OTHER2,
+
+        /* just a generic distress call */
+        GENERIC };
+
+        /* help1-4, doing1-4, and other1-2 are for future expansion */
+
+/* from BRM struct.h */
+struct distress {
+    unsigned char sender;
+    unsigned char dam, shld, arms, wtmp, etmp, fuelp, sts;
+    unsigned char wtmpflag, etempflag, cloakflag, distype, macroflag, ttype;
+    unsigned char close_pl, close_en, target, tclose_pl, tclose_en, pre_app, i;
+    unsigned char close_j, close_fr, tclose_j, tclose_fr;
+    unsigned char cclist[6]; /* allow us some day to cc a message 
+                                up to 5 people */
+        /* sending this to the server allows the server to do the cc action */
+        /* otherwise it would have to be the client ... less BW this way */
+    char preappend[80]; /* text which we pre or append */
 };
Index: Vanilla/robotd/util.c
diff -u Vanilla/robotd/util.c:1.1 Vanilla/robotd/util.c:1.2
--- Vanilla/robotd/util.c:1.1	Tue Feb 22 16:49:31 2000
+++ Vanilla/robotd/util.c	Sun Mar  5 09:56:48 2000
@@ -393,26 +393,10 @@
 
 emergency()
 {
-    char addrbuf[ADDRLEN];
-    char ebuf[80];
+    struct distress *dist;
 
-    if (myship->s_type==STARBASE) {
-        sprintf(ebuf,
-"Distress Call from %c%c(SB!):  %d%% dmg, %d%% shld, %d armies, %d%% wtmp",
-            teamlet[me->p_team], shipnos[me->p_no],
-            (100*me->p_damage)/me->p_ship.s_maxdamage,
-            (100*me->p_shield)/me->p_ship.s_maxshield,
-            me->p_armies,
-	    (100*me->p_wtemp)/me->p_ship.s_maxwpntemp);
-    } else {
-        sprintf(ebuf,
-            "Distress Call from %c%c:  %d%% damage, %d%% shields, %d armies!",
-            teamlet[me->p_team], shipnos[me->p_no],
-            (100*me->p_damage)/me->p_ship.s_maxdamage,
-            (100*me->p_shield)/me->p_ship.s_maxshield,
-            me->p_armies);
-    }
-    pmessage(teamlet[me->p_team], ebuf);
+    dist = loaddistress(GENERIC);
+    send_RCD(dist);
 }
 
 /*