src/hcode/btech/autopilot_radio.c

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: autopilot_command.c,v 1.4 2005/08/10 14:09:34 av1-op Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1997 Markus Stenberg
00008  *  Copyright (c) 1998-2002 Thomas Wouters
00009  *  Copyright (c) 2000-2002 Cord Awtry
00010  *       All rights reserved
00011  *
00012  * Created: Tue Sep 23 20:33:33 1997 fingon
00013  * Last modified: Sat Jun  6 21:47:38 1998 fingon
00014  *
00015  */
00016 
00017 /* Most of the BattleSheep(tm) code is here.. */
00018 
00019 #include <math.h>
00020 #include "mech.h"
00021 #include "autopilot.h"
00022 #include "spath.h"
00023 #include "mech.notify.h"
00024 #include "p.mech.utils.h"
00025 #include "p.mech.sensor.h"
00026 #include "p.mech.los.h"
00027 #include "p.mech.startup.h"
00028 #include "p.mech.maps.h"
00029 #include "p.ds.bay.h"
00030 #include "p.mech.maps.h"
00031 #include "p.bsuit.h"
00032 #include "p.glue.h"
00033 
00034 void sendchannelstuff(MECH * mech, int freq, char *msg);
00035 
00037 #define Clear(a) \
00038     auto_disengage(a->mynum, a, ""); \
00039     auto_delcommand(a->mynum, a, "-1"); \
00040     if (a->target >= -1) { \
00041         if (AssignedTarget(a) && a->target != -1) { \
00042             snprintf(buffer, SBUF_SIZE, "autogun target %d", a->target); \
00043         } else { \
00044             snprintf(buffer, SBUF_SIZE, "autogun on"); \
00045         } \
00046         auto_addcommand(a->mynum, autopilot, buffer); \
00047     } \
00048 
00049 #define BACMD(name) char * name (AUTO *autopilot, MECH *mech, char **args, int argc, int chn)
00050 #define ACMD(name) static BACMD(name)
00051 
00052 /* 
00053  * Master list of AI - radio commands
00054  */
00055 struct {
00056         char *sho;
00057         char *name;
00058         int args;
00059         int silent;
00060         void (*fun) (AUTO * autopilot, MECH * mech, char **args, int argc,
00061                                  char *mesg);
00062 } auto_cmds[] = {
00063         {
00064         "auto", "autogun", 1, 0, auto_radio_command_autogun}, {
00065         "auto", "autogun", 2, 0, auto_radio_command_autogun}, {
00066 #if 0
00067         "att", "attackleg", 1, 0, auto_attackleg}, {
00068         "chanf", "chanfreq", 2, 0, auto_setchanfreq}, {
00069         "chanm", "chanmode", 2, 0, auto_setchanmode}, {
00070 #endif
00071         "chase", "chasetarg", 1, 0, auto_radio_command_chasetarg}, {
00072 #if 0
00073         "cm", "cmode", 2, 0, auto_cmode}, {
00074 #endif
00075         "dfo", "dfollow", 1, 0, auto_radio_command_dfollow}, {
00076         "dgo", "dgoto", 2, 0, auto_radio_command_dgoto}, {
00077 #if 0
00078         "dr", "drally", 2, 0, auto_drally}, {
00079         "dr", "drally", 3, 0, auto_drally}, {
00080 #endif
00081         "drop", "dropoff", 0, 0, auto_radio_command_dropoff}, {
00082         "emb", "embark", 1, 0, auto_radio_command_embark}, {
00083         "en", "enterbase", 0, 0, auto_radio_command_enterbase}, {
00084         "en", "enterbase", 1, 0, auto_radio_command_enterbase}, {
00085 #if 0
00086         "en", "enterbay", 0, 0, auto_enterbay}, {
00087         "en", "enterbay", 1, 0, auto_enterbay}, {
00088 #endif
00089         "fo", "follow", 1, 0, auto_radio_command_follow}, {
00090 #if 0
00091         "fr", "freq", 1, 0, auto_freq}, {
00092 #endif
00093         "go", "goto", 2, 0, auto_radio_command_goto}, {
00094         "he", "heading", 1, 0, auto_radio_command_heading}, {
00095         "he", "help", 0, 1, auto_radio_command_help}, {
00096         "hi", "hide", 0, 0, auto_radio_command_hide}, {
00097         "jump", "jumpjet", 1, 0, auto_radio_command_jumpjet}, {
00098         "jump", "jumpjet", 2, 0, auto_radio_command_jumpjet}, {
00099         "le", "leavebase", 1, 0, auto_radio_command_leavebase}, {
00100 #if 0
00101         "nog", "nogun", 0, 0, auto_nogun}, {
00102         "not", "notarget", 0, 0, auto_notarget}, {
00103 #endif
00104         "ogo", "ogoto", 2, 0, auto_radio_command_ogoto}, {
00105         "pick", "pickup", 1, 0, auto_radio_command_pickup}, {
00106         "pos", "position", 2, 0, auto_radio_command_position}, {
00107         "pr", "prone", 0, 0, auto_radio_command_prone}, {
00108 #if 0
00109         "ra", "rally", 2, 0, auto_rally}, {
00110         "ra", "rally", 3, 0, auto_rally}, {
00111 #endif
00112         "re", "report", 0, 1, auto_radio_command_report}, {
00113         "reset", "reset", 0, 0, auto_radio_command_reset}, {
00114 #if 0
00115         "roam", "roammode", 1, 0, auto_roammode}, {
00116 #endif
00117         "se", "sensor", 2, 0, auto_radio_command_sensor}, {
00118         "se", "sensor", 0, 0, auto_radio_command_sensor}, {
00119         "sh", "shutdown", 0, 0, auto_radio_command_shutdown}, {
00120         "sp", "speed", 1, 0, auto_radio_command_speed}, {
00121         "st", "stand", 0, 0, auto_radio_command_stand}, {
00122         "st", "startup", 0, 0, auto_radio_command_startup}, {
00123         "st", "startup", 1, 0, auto_radio_command_startup}, {
00124         "st", "stop", 0, 0, auto_radio_command_stop}, {
00125         "sw", "sweight", 2, 1, auto_radio_command_sweight}, {
00126 #if 0
00127         "swa", "swarm", 1, 0, auto_swarm}, {
00128         "swarmc", "swarmcharge", 1, 0, auto_swarmcharge}, {
00129         "swarmm", "swarmmode", 1, 0, auto_swarmmode}, {
00130 #endif
00131         "ta", "target", 1, 0, auto_radio_command_target}, {
00132 #if 0
00133         "ta", "target", 2, 0, auto_target}, {
00134 #endif
00135         NULL, NULL, 0, 0, NULL}
00136 };
00137 
00138 /*
00139  * The autogun radio interface
00140  */
00141 void auto_radio_command_autogun(AUTO * autopilot, MECH * mech,
00142                                                                 char **args, int argc, char *mesg)
00143 {
00144 
00145         int threshold;
00146 
00147         if(strcmp(args[1], "on") == 0) {
00148 
00149                 autopilot->target = -1;
00150                 autopilot->target_score = 0;
00151                 autopilot->target_update_tick = AUTO_GUN_UPDATE_TICK;
00152 
00153                 /* Reset the Assigned target flag */
00154                 if(AssignedTarget(autopilot)) {
00155                         UnassignTarget(autopilot);
00156                 }
00157 
00158                 if(Gunning(autopilot)) {
00159                         DoStopGun(autopilot);
00160                 }
00161                 DoStartGun(autopilot);
00162 
00163                 snprintf(mesg, LBUF_SIZE, "shooting at whatever I want");
00164                 return;
00165 
00166         } else if(strcmp(args[1], "off") == 0) {
00167 
00168                 /* Reset the AI */
00169                 autopilot->target = -2;
00170                 autopilot->target_score = 0;
00171                 autopilot->target_update_tick = 0;
00172 
00173                 /* Reset this flag since we don't want to be shooting anything */
00174                 if(AssignedTarget(autopilot)) {
00175                         UnassignTarget(autopilot);
00176                 }
00177 
00178                 if(Gunning(autopilot))
00179                         DoStopGun(autopilot);
00180 
00181                 snprintf(mesg, LBUF_SIZE, "powering down weapons");
00182                 return;
00183 
00184         } else if(strcmp(args[1], "threshold") == 0) {
00185 
00186                 /* Ok user specifying a threshold" */
00187                 /* Right now we're only going to allow them to specify a value
00188                  * between 0 and 100 - basicly how much percentage wise over
00189                  * the current value does the new target have to be to switch */
00190                 if(argc == 3 && !Readnum(threshold, args[2]) &&
00191                    threshold >= 0 && threshold <= 100) {
00192 
00193                         /* Set the new threshold value */
00194                         autopilot->target_threshold = threshold;
00195 
00196                         snprintf(mesg, LBUF_SIZE, "new threshold set to %d%%", threshold);
00197                         return;
00198 
00199                 } else {
00200 
00201                         /* Bad value for threshold */
00202                         snprintf(mesg, LBUF_SIZE, "!Invalid value used with threshold: "
00203                                          "Usage autogun threshold [0-100]");
00204                         return;
00205 
00206                 }
00207 
00208         }
00209 
00210         snprintf(mesg, LBUF_SIZE, "!Invalid Input for autogun:"
00211                          " use 'on' or 'off'");
00212 
00213 }
00214 
00215 /*
00216  * Tell the AI to chase whatever its targeting
00217  */
00218 void auto_radio_command_chasetarg(AUTO * autopilot, MECH * mech,
00219                                                                   char **args, int argc, char *mesg)
00220 {
00221 
00222         if(strcmp(args[1], "on") == 0) {
00223 
00224                 auto_set_chasetarget_mode(autopilot, AUTO_CHASETARGET_ON);
00225                 snprintf(mesg, LBUF_SIZE, "Chase Target Mode is Activated");
00226                 return;
00227 
00228         } else if(strcmp(args[1], "off") == 0) {
00229 
00230                 auto_set_chasetarget_mode(autopilot, AUTO_CHASETARGET_OFF);
00231                 snprintf(mesg, LBUF_SIZE, "Chase Target Mode is Deactivated");
00232                 return;
00233         }
00234         snprintf(mesg, LBUF_SIZE,
00235                          "!Invalid Input for chasetarg: use 'on' or 'off'");
00236 
00237 }
00238 
00239 /*
00240  * Radio command to force AI to [dumbly] follow a given target
00241  */
00242 void auto_radio_command_dfollow(AUTO * autopilot, MECH * mech,
00243                                                                 char **args, int argc, char *mesg)
00244 {
00245 
00246         dbref targetref;
00247         char buffer[SBUF_SIZE];
00248 
00249         targetref = FindTargetDBREFFromMapNumber(mech, args[1]);
00250         if(targetref <= 0) {
00251                 snprintf(mesg, LBUF_SIZE, "!Invalid target to follow");
00252                 return;
00253         }
00254 
00255         Clear(autopilot);
00256 
00257         snprintf(buffer, SBUF_SIZE, "dumbfollow %d", targetref);
00258         auto_addcommand(autopilot->mynum, autopilot, buffer);
00259         auto_engage(autopilot->mynum, autopilot, "");
00260         snprintf(mesg, LBUF_SIZE, "following %s [dumbly] (%d degrees, %d away)",
00261                          args[1], autopilot->ofsx, autopilot->ofsy);
00262 }
00263 
00264 /*
00265  * Radio command to force AI to [dumbly] goto a given hex
00266  */
00267 void auto_radio_command_dgoto(AUTO * autopilot, MECH * mech,
00268                                                           char **args, int argc, char *mesg)
00269 {
00270 
00271         int x, y;
00272         char buffer[SBUF_SIZE];
00273 
00274         if(Readnum(x, args[1])) {
00275                 snprintf(mesg, LBUF_SIZE, "!First number not an integer");
00276                 return;
00277         }
00278         if(Readnum(y, args[2])) {
00279                 snprintf(mesg, LBUF_SIZE, "!First number not an integer");
00280                 return;
00281         }
00282 
00283         Clear(autopilot);
00284 
00285         snprintf(buffer, SBUF_SIZE, "dumbgoto %d %d", x, y);
00286         auto_addcommand(autopilot->mynum, autopilot, buffer);
00287         auto_engage(autopilot->mynum, autopilot, "");
00288         snprintf(mesg, LBUF_SIZE, "going [dumbly] to %d,%d", x, y);
00289 
00290 }
00291 
00292 /*
00293  * Radio command to force AI to drop whatever its carrying
00294  */
00295 void auto_radio_command_dropoff(AUTO * autopilot, MECH * mech,
00296                                                                 char **args, int argc, char *mesg)
00297 {
00298 
00299         char buffer[SBUF_SIZE];
00300 
00301         Clear(autopilot);
00302 
00303         snprintf(buffer, SBUF_SIZE, "dropoff");
00304         auto_addcommand(autopilot->mynum, autopilot, buffer);
00305         auto_engage(autopilot->mynum, autopilot, "");
00306         snprintf(mesg, LBUF_SIZE, "dropping off");
00307 
00308 }
00309 
00310 /*
00311  * Radio command to force AI to embark a carrier
00312  */
00313 void auto_radio_command_embark(AUTO * autopilot, MECH * mech,
00314                                                            char **args, int argc, char *mesg)
00315 {
00316 
00317         dbref targetref;
00318         char buffer[SBUF_SIZE];
00319 
00320         targetref = FindTargetDBREFFromMapNumber(mech, args[1]);
00321         if(targetref <= 0) {
00322                 snprintf(mesg, LBUF_SIZE, "!Invalid target to embark");
00323                 return;
00324         }
00325 
00326         Clear(autopilot);
00327         snprintf(buffer, SBUF_SIZE, "embark %d", targetref);
00328         auto_addcommand(autopilot->mynum, autopilot, buffer);
00329         auto_engage(autopilot->mynum, autopilot, "");
00330         snprintf(mesg, LBUF_SIZE, "embarking %s", args[1]);
00331         return;
00332 
00333 }
00334 
00335 /*
00336  * Radio command to force AI to enterbase
00337  */
00338 void auto_radio_command_enterbase(AUTO * autopilot, MECH * mech,
00339                                                                   char **args, int argc, char *mesg)
00340 {
00341 
00342         char buffer[SBUF_SIZE];
00343 
00344         if(argc - 1) {
00345                 snprintf(buffer, SBUF_SIZE, "enterbase %s", args[1]);
00346                 snprintf(mesg, LBUF_SIZE, "entering base (%s side)", args[1]);
00347         } else {
00348                 strncpy(buffer, "enterbase n", SBUF_SIZE);
00349                 snprintf(mesg, LBUF_SIZE, "entering base");
00350         }
00351 
00352         Clear(autopilot);
00353         auto_addcommand(autopilot->mynum, autopilot, buffer);
00354         auto_engage(autopilot->mynum, autopilot, "");
00355 
00356 }
00357 
00358 /*
00359  * New smart follow system based on A*'s goto
00360  */
00361 void auto_radio_command_follow(AUTO * autopilot, MECH * mech,
00362                                                            char **args, int argc, char *mesg)
00363 {
00364 
00365         char buffer[SBUF_SIZE];
00366         dbref targetref;
00367 
00368         targetref = FindTargetDBREFFromMapNumber(mech, args[1]);
00369         if(targetref <= 0) {
00370                 snprintf(mesg, LBUF_SIZE, "!Invalid target to follow");
00371                 return;
00372         }
00373 
00374         Clear(autopilot);
00375 
00376         snprintf(buffer, SBUF_SIZE, "follow %d", targetref);
00377         auto_addcommand(autopilot->mynum, autopilot, buffer);
00378         auto_engage(autopilot->mynum, autopilot, "");
00379         snprintf(mesg, LBUF_SIZE, "following %s (%d degrees, %d away)", args[1],
00380                          autopilot->ofsx, autopilot->ofsy);
00381 
00382 }
00383 
00384 /*
00385  * Smart goto system based on Astar path finding
00386  */
00387 void auto_radio_command_goto(AUTO * autopilot, MECH * mech,
00388                                                          char **args, int argc, char *mesg)
00389 {
00390 
00391         int x, y;
00392         char buffer[SBUF_SIZE];
00393     MAP *map;
00394 
00395         if(Readnum(x, args[1])) {
00396                 snprintf(mesg, LBUF_SIZE, "!First number not integer");
00397                 return;
00398         }
00399         if(Readnum(y, args[2])) {
00400                 snprintf(mesg, LBUF_SIZE, "!Second number not integer");
00401                 return;
00402         }
00403 
00404         if(MechX(mech) == x && MechY(mech) == y) {
00405                 snprintf(mesg, LBUF_SIZE, "!Already in that hex");
00406                 return;
00407         }
00408 
00409     map = getMap(mech->mapindex);
00410 
00411     if (x < 0 || y < 0 || x >= map->map_width || y >= map->map_height) {
00412         snprintf(mesg, LBUF_SIZE, "!Bad hex to travel to");
00413         return;
00414     }
00415 
00416         Clear(autopilot);
00417 
00418         snprintf(buffer, SBUF_SIZE, "goto %d %d", x, y);
00419         auto_addcommand(autopilot->mynum, autopilot, buffer);
00420         auto_engage(autopilot->mynum, autopilot, "");
00421         snprintf(mesg, LBUF_SIZE, "going to %d,%d", x, y);
00422 
00423 }
00424 
00425 /*
00426  * Radio command to alter an AI's heading
00427  */
00428 void auto_radio_command_heading(AUTO * autopilot, MECH * mech,
00429                                                                 char **args, int argc, char *mesg)
00430 {
00431 
00432         int heading;
00433         char buffer[SBUF_SIZE];
00434 
00435         if(Readnum(heading, args[1])) {
00436                 snprintf(mesg, LBUF_SIZE, "!Number not integer");
00437                 return;
00438         }
00439 
00440         Clear(autopilot);
00441         auto_engage(autopilot->mynum, autopilot, "");
00442         snprintf(buffer, SBUF_SIZE, "%d", heading);
00443         mech_heading(autopilot->mynum, mech, buffer);
00444         strcpy(buffer, "0");
00445         mech_speed(autopilot->mynum, mech, buffer);
00446         snprintf(buffer, LBUF_SIZE, "stopped and heading changed to %d", heading);
00447 
00448 }
00449 
00450 /*
00451  * Help message, lists the various commands for the AI
00452  */
00453 void auto_radio_command_help(AUTO * autopilot, MECH * mech,
00454                                                          char **args, int argc, char *mesg)
00455 {
00456 
00457         int i;
00458 
00461         snprintf(mesg, LBUF_SIZE, "The following commands are possible:");
00462 
00463         for(i = 0; auto_cmds[i].name; i++) {
00464                 if(i > 0 && !strcmp(auto_cmds[i].name, auto_cmds[i - 1].name))
00465                         continue;
00466                 strncat(mesg, " ", LBUF_SIZE);
00467                 strncat(mesg, auto_cmds[i].name, LBUF_SIZE);
00468         }
00469 
00470         auto_reply(mech, mesg);
00471 
00472 }
00473 
00474 /*
00475  * Radio command to force AI to try and hide itself
00476  */
00477 void auto_radio_command_hide(AUTO * autopilot, MECH * mech,
00478                                                          char **args, int argc, char *mesg)
00479 {
00480 
00481         if((HasCamo(mech)) ?
00482            0 : MechType(mech) != CLASS_BSUIT && MechType(mech) != CLASS_MW) {
00483                 snprintf(mesg, LBUF_SIZE,
00484                                  "!Last I checked I was kind of big for that");
00485                 return;
00486         }
00487 
00488         if(!(MechRTerrain(mech) == HEAVY_FOREST ||
00489                  MechRTerrain(mech) == LIGHT_FOREST ||
00490                  MechRTerrain(mech) == ROUGH ||
00491                  MechRTerrain(mech) == MOUNTAINS ||
00492                  (MechType(mech) == CLASS_BSUIT ? MechRTerrain(mech) ==
00493                   BUILDING : 0))) {
00494                 snprintf(mesg, LBUF_SIZE, "!Invalid Terrain");
00495                 return;
00496         }
00497 
00498         bsuit_hide(autopilot->mynum, mech, "");
00499         snprintf(mesg, LBUF_SIZE, "Begining to hide");
00500 
00501 }
00502 
00503 /*
00504  * Radio command to force AI to jump either on a target or 
00505  * in a given direction range
00506  */
00507 void auto_radio_command_jumpjet(AUTO * autopilot, MECH * mech,
00508                                                                 char **args, int argc, char *mesg)
00509 {
00510 
00511         dbref target;
00512         char buffer[SBUF_SIZE];
00513         int bear, rng;
00514 
00515         if(!abs(MechJumpSpeed(mech))) {
00516                 snprintf(mesg, LBUF_SIZE, "!I don't do hiphop and jump around");
00517                 return;
00518         }
00519 
00520         if((argc - 1) == 1) {
00521                 if((target = FindTargetDBREFFromMapNumber(mech, args[1])) <= 0) {
00522                         snprintf(mesg, LBUF_SIZE, "!Unable to see such a target");
00523                         return;
00524                 }
00525                 strcpy(buffer, args[1]);
00526                 mech_jump(autopilot->mynum, mech, buffer);
00527                 snprintf(mesg, LBUF_SIZE, "jumping on [%s]", args[1]);
00528                 return;
00529         } else {
00530                 if(Readnum(bear, args[1])) {
00531                         snprintf(mesg, LBUF_SIZE, "!Invalid bearing");
00532                         return;
00533                 }
00534                 if(Readnum(rng, args[2])) {
00535                         snprintf(mesg, LBUF_SIZE, "!Invalid range");
00536                         return;
00537                 }
00538                 snprintf(buffer, SBUF_SIZE, "%s %s", args[1], args[2]);
00539                 mech_jump(autopilot->mynum, mech, buffer);
00540                 snprintf(mesg, LBUF_SIZE, "jump %s degrees %s hexes", args[1],
00541                                  args[2]);
00542                 return;
00543         }
00544 }
00545 
00546 /*
00547  * Radio command to force AI to leavebase
00548  */
00549 void auto_radio_command_leavebase(AUTO * autopilot, MECH * mech,
00550                                                                   char **args, int argc, char *mesg)
00551 {
00552 
00553         char buffer[SBUF_SIZE];
00554         int direction;
00555 
00556         if(Readnum(direction, args[1])) {
00557                 snprintf(mesg, LBUF_SIZE, "!Invalid value for direction");
00558                 return;
00559         }
00560 
00561         /* Make sure chasetarget doesn't interfere with this */
00562         if(ChasingTarget(autopilot)) {
00563                 StopChasingTarget(autopilot);
00564         }
00565 
00566         Clear(autopilot);
00567 
00568         snprintf(buffer, SBUF_SIZE, "leavebase %d", direction);
00569         auto_addcommand(autopilot->mynum, autopilot, buffer);
00570         auto_engage(autopilot->mynum, autopilot, "");
00571         snprintf(mesg, LBUF_SIZE, "leaving base at %d heading", direction);
00572 
00573 }
00574 
00575 /*
00576  * Old goto system - will phase out
00577  */
00578 void auto_radio_command_ogoto(AUTO * autopilot, MECH * mech,
00579                                                           char **args, int argc, char *mesg)
00580 {
00581 
00582         int x, y;
00583         char buffer[SBUF_SIZE];
00584 
00585         if(Readnum(x, args[1])) {
00586                 snprintf(mesg, LBUF_SIZE, "!First number not integer");
00587                 return;
00588         }
00589         if(Readnum(y, args[2])) {
00590                 snprintf(mesg, LBUF_SIZE, "!Second number not integer");
00591                 return;
00592         }
00593 
00594         Clear(autopilot);
00595 
00596         snprintf(buffer, SBUF_SIZE, "oldgoto %d %d", x, y);
00597         auto_addcommand(autopilot->mynum, autopilot, buffer);
00598         auto_engage(autopilot->mynum, autopilot, "");
00599         snprintf(mesg, LBUF_SIZE, "going [old version] to %d,%d", x, y);
00600 
00601 }
00602 
00603 /*
00604  * Radio command to force AI to pickup a target
00605  */
00606 void auto_radio_command_pickup(AUTO * autopilot, MECH * mech,
00607                                                            char **args, int argc, char *mesg)
00608 {
00609 
00610         dbref targetref;
00611         char buffer[SBUF_SIZE];
00612 
00613         targetref = FindTargetDBREFFromMapNumber(mech, args[1]);
00614         if(targetref <= 0) {
00615                 snprintf(mesg, LBUF_SIZE, "!Invalid target to pickup");
00616                 return;
00617         }
00618 
00619         /* Make sure chasetarget doesn't interfere with this */
00620         if(ChasingTarget(autopilot)) {
00621                 StopChasingTarget(autopilot);
00622         }
00623 
00624         Clear(autopilot);
00625 
00626         snprintf(buffer, SBUF_SIZE, "pickup %d", targetref);
00627         auto_addcommand(autopilot->mynum, autopilot, buffer);
00628         auto_engage(autopilot->mynum, autopilot, "");
00629         snprintf(mesg, LBUF_SIZE, "picking up %s", args[1]);
00630 
00631 }
00632 
00633 /*
00634  * Radio command to make AI take up a given position (dir & range) from
00635  * their current target (hex or unit)
00636  */
00637 void auto_radio_command_position(AUTO * autopilot, MECH * mech,
00638                                                                  char **args, int argc, char *mesg)
00639 {
00640 
00641         int x, y;
00642 
00645         if(Readnum(x, args[1])) {
00646                 snprintf(mesg, LBUF_SIZE, "!Invalid first int");
00647                 return;
00648         }
00649         if(Readnum(y, args[2])) {
00650                 snprintf(mesg, LBUF_SIZE, "!Invalide second int");
00651                 return;
00652         }
00653 
00654         autopilot->ofsx = x;
00655         autopilot->ofsy = y;
00656         snprintf(mesg, LBUF_SIZE, "following %d degrees, %d away", x, y);
00657 
00658 }
00659 
00660 /*
00661  * Radio command to force AI to go prone
00662  */
00663 void auto_radio_command_prone(AUTO * autopilot, MECH * mech,
00664                                                           char **args, int argc, char *mesg)
00665 {
00666 
00667         mech_drop(autopilot->mynum, mech, "");
00668         snprintf(mesg, LBUF_SIZE, "hitting the deck");
00669 
00670 }
00671 
00672 /*
00673  * Radio command so the AI can report its status
00674  */
00676 void auto_radio_command_report(AUTO * autopilot, MECH * mech,
00677                                                            char **args, int argc, char *mesg)
00678 {
00679 
00680         char buffer[MBUF_SIZE];
00681         MECH *target;
00682 
00683         /* Is the AI moving or something */
00684         if(Jumping(mech))
00685                 strcpy(buffer, "Jumping");
00686         else if(Fallen(mech))
00687                 strcpy(buffer, "Prone");
00688         else if(IsRunning(MechSpeed(mech), MMaxSpeed(mech)))
00689                 strcpy(buffer, "Running");
00690         else if(MechSpeed(mech) > 1.0)
00691                 strcpy(buffer, "Walking");
00692         else
00693                 strcpy(buffer, "Standing");
00694 
00695         snprintf(mesg, LBUF_SIZE, "%s at %d, %d", buffer, MechX(mech),
00696                          MechY(mech));
00697 
00698         /* Which way is the AI going */
00699         if(MechSpeed(mech) > 1.0) {
00700                 snprintf(buffer, MBUF_SIZE, ", headed %d speed %.2f",
00701                                  MechFacing(mech), MechSpeed(mech));
00702                 strncat(mesg, buffer, LBUF_SIZE);
00703         } else {
00704                 snprintf(buffer, MBUF_SIZE, ", headed %d", MechFacing(mech));
00705                 strncat(mesg, buffer, LBUF_SIZE);
00706         }
00707 
00708         /* Is the AI targeting something */
00709         if(MechTarget(mech) != -1) {
00710                 target = getMech(MechTarget(mech));
00711 
00712                 if(target) {
00713                         snprintf(buffer, MBUF_SIZE, ", targeting %s %s",
00714                                          GetMechToMechID(mech, target),
00715                                          InLineOfSight(mech, target, MechX(target),
00716                                                                    MechY(target), FaMechRange(mech, target)) ?
00717                                          "" : "(not in LOS)");
00718                         strncat(mesg, buffer, LBUF_SIZE);
00719                 }
00720         }
00721 
00722         /* Send the mesg to the reply system, this is a silent command */
00723         auto_reply(mech, mesg);
00724 
00725 }
00726 
00727 /*
00728  * Radio command to reset the AI's internal flags what not
00729  */
00730 void auto_radio_command_reset(AUTO * autopilot, MECH * mech,
00731                                                           char **args, int argc, char *mesg)
00732 {
00733 
00734         char buffer[SBUF_SIZE];
00735 
00736         auto_disengage(autopilot->mynum, autopilot, "");
00737         auto_delcommand(autopilot->mynum, autopilot, "-1");
00738         auto_init(autopilot, mech);
00739         auto_engage(autopilot->mynum, autopilot, "");
00740         snprintf(mesg, LBUF_SIZE, "all internal events and flags reset!");
00741 
00742 }
00743 
00744 /*
00745  * Radio command to alter or let the AI alter
00746  * its sensors
00747  */
00748 void auto_radio_command_sensor(AUTO * autopilot, MECH * mech,
00749                                                            char **args, int argc, char *mesg)
00750 {
00751 
00752         char buf[SBUF_SIZE];
00753 
00754         /* Make sure no sensor event running */
00755         muxevent_remove_type_data(EVENT_AUTO_SENSOR, autopilot);
00756 
00757         if((argc - 1) == 2) {
00758 
00759                 /* Set the user specified sensors */
00760                 snprintf(buf, SBUF_SIZE, "%s %s", args[1], args[2]);
00761                 mech_sensor(autopilot->mynum, mech, buf);
00762                 autopilot->flags |= AUTOPILOT_LSENS;
00763                 snprintf(mesg, LBUF_SIZE, "updated my sensors");
00764                 return;
00765 
00766         }
00767 
00768         /* Let AI decide */
00769         autopilot->flags &= ~AUTOPILOT_LSENS;
00770         snprintf(mesg, LBUF_SIZE, "using my own judgement with sensors");
00771         return;
00772 
00773 }
00774 
00775 /*
00776  * Radio command to force AI to shutdown
00777  */
00778 void auto_radio_command_shutdown(AUTO * autopilot, MECH * mech,
00779                                                                  char **args, int argc, char *mesg)
00780 {
00781 
00782         mech_shutdown(autopilot->mynum, mech, "");
00783         snprintf(mesg, LBUF_SIZE, "shutting down");
00784 
00785 }
00786 
00787 /*
00788  * Radio command to alter the speed of an AI (% of speed)
00789  */
00790 void auto_radio_command_speed(AUTO * autopilot, MECH * mech,
00791                                                           char **args, int argc, char *mesg)
00792 {
00793 
00794         int speed = 100;
00795 
00796         if(Readnum(speed, args[1])) {
00797                 snprintf(mesg, LBUF_SIZE, "!Invalid value - not a number");
00798                 return;
00799         }
00800 
00801         if(speed < 1 || speed > 100) {
00802                 snprintf(mesg, LBUF_SIZE, "!Invalid speed");
00803                 return;
00804         }
00805 
00806         autopilot->speed = speed;
00807         snprintf(mesg, LBUF_SIZE, "setting speed to %d %%", speed);
00808 
00809 }
00810 
00811 /*
00812  * Radio Command to force AI to stand
00813  */
00814 void auto_radio_command_stand(AUTO * autopilot, MECH * mech,
00815                                                           char **args, int argc, char *mesg)
00816 {
00817 
00818         mech_stand(autopilot->mynum, mech, "");
00819         snprintf(mesg, LBUF_SIZE, "standing up");
00820 
00821 }
00822 
00823 /*
00824  * Radio command to force AI to startup
00825  */
00826 void auto_radio_command_startup(AUTO * autopilot, MECH * mech,
00827                                                                 char **args, int argc, char *mesg)
00828 {
00829 
00830         if(argc > 1) {
00831                 if(!strncasecmp(args[1], "override", strlen(args[1]))) {
00832                         mech_startup(autopilot->mynum, mech, "override");
00833                         snprintf(mesg, LBUF_SIZE, "emergency override startup triggered");
00834                         return;
00835                 }
00836         }
00837 
00838         mech_startup(autopilot->mynum, mech, "");
00839         snprintf(mesg, LBUF_SIZE, "starting up");
00840 
00841 }
00842 
00843 /*
00844  * Radio command to stop the AI
00845  */
00846 void auto_radio_command_stop(AUTO * autopilot, MECH * mech,
00847                                                          char **args, int argc, char *mesg)
00848 {
00849 
00850         char buffer[SBUF_SIZE];
00851 
00852         strcpy(buffer, "0");
00853 
00854         /* Turn chasetarget off */
00855         auto_set_chasetarget_mode(autopilot, AUTO_CHASETARGET_OFF);
00856 
00857         Clear(autopilot);
00858 
00859         auto_engage(autopilot->mynum, autopilot, "");
00860         mech_speed(autopilot->mynum, mech, buffer);
00861         snprintf(mesg, LBUF_SIZE, "halting");
00862 
00863 }
00864 
00865 /*
00866  * Command for the old goto, will phase it out
00867  */
00868 void auto_radio_command_sweight(AUTO * autopilot, MECH * mech,
00869                                                                 char **args, int argc, char *mesg)
00870 {
00871 
00872         int x, y;
00873 
00874         if(Readnum(x, args[1])) {
00875                 snprintf(mesg, LBUF_SIZE, "!Invalid first int");
00876                 return;
00877         }
00878         if(Readnum(y, args[2])) {
00879                 snprintf(mesg, LBUF_SIZE, "!Invalide second int");
00880                 return;
00881         }
00882         x = MAX(1, x);
00883         y = MAX(1, y);
00884         autopilot->auto_goweight = x;
00885         autopilot->auto_fweight = y;
00886         snprintf(mesg, LBUF_SIZE, "sweight'ed to %d:%d. (go:fight)", x, y);
00887         return;
00888 
00889 }
00890 
00891 /*
00892  * Tell the AI to target a specific unit
00893  */
00894 void auto_radio_command_target(AUTO * autopilot, MECH * mech,
00895                                                            char **args, int argc, char *mesg)
00896 {
00897 
00898         dbref targetref;
00899 
00900         if(!strcmp(args[1], "-")) {
00901 
00902                 /* Basicly doing the same as 'autogun on' */
00903                 autopilot->target = -1;
00904                 autopilot->target_score = 0;
00905                 autopilot->target_update_tick = AUTO_GUN_UPDATE_TICK;
00906 
00907                 if(AssignedTarget(autopilot)) {
00908                         UnassignTarget(autopilot);
00909                 }
00910 
00911                 if(Gunning(autopilot)) {
00912                         DoStopGun(autopilot);
00913                 }
00914                 DoStartGun(autopilot);
00915 
00916                 snprintf(mesg, LBUF_SIZE, "shooting at whatever I want");
00917                 return;
00918 
00919         } else {
00920 
00921                 targetref = FindTargetDBREFFromMapNumber(mech, args[1]);
00922                 if(targetref <= 0) {
00923                         snprintf(mesg, LBUF_SIZE, "!Unable to see such a target");
00924                         return;
00925                 }
00926 
00927         }
00928 
00929         autopilot->target = targetref;
00930         autopilot->target_score = 0;
00931         autopilot->target_update_tick = 0;
00932 
00933         /* Let the AI know its an assigned target */
00934         if(!AssignedTarget(autopilot)) {
00935                 AssignTarget(autopilot);
00936         }
00937 
00938         if(Gunning(autopilot)) {
00939                 DoStopGun(autopilot);
00940         }
00941         DoStartGun(autopilot);
00942 
00943         snprintf(mesg, LBUF_SIZE, "aiming for [%s] (and ignoring everyone else)",
00944                          args[1]);
00945 
00946 }
00947 
00948 #if 0
00949 ACMD(auto_swarm)
00950 {
00951         dbref targetref;
00952 
00953         if(!mech || MechType(mech) != CLASS_BSUIT)
00954                 return "!Not a bsuit";
00955         targetref = FindTargetDBREFFromMapNumber(mech, args[0]);
00956         if(targetref <= 0)
00957                 return "!Invalid target to swarm";
00958         Clear(a);
00959         auto_addcommand(a->mynum, a, tprintf("swarm %d", targetref));
00960         auto_engage(a->mynum, a, "");
00961         return tprintf("swarming %s.", args[0]);
00962 }
00963 #endif
00964 #if 0
00965 ACMD(auto_attackleg)
00966 {
00967         dbref targetref;
00968 
00969         if(!mech || MechType(mech) != CLASS_BSUIT)
00970                 return "!Not a bsuit";
00971         targetref = FindTargetDBREFFromMapNumber(mech, args[0]);
00972         if(targetref <= 0)
00973                 return "!Invalid target to attackleg";
00974         Clear(a);
00975         auto_addcommand(a->mynum, a, tprintf("attackleg %d", targetref));
00976         auto_engage(a->mynum, a, "");
00977         return tprintf("attacklegging %s.", args[0]);
00978 }
00979 #endif
00980 #if 0
00981 ACMD(auto_notarget)
00982 {
00983         a->targ = -1;
00984         if(Gunning(a)) {
00985                 DoStopGun(a);
00986                 DoStartGun(a);
00987         }
00988         return "shooting at anything that moves";
00989 }
00990 #endif
00991 #if 0
00992 ACMD(auto_nogun)
00993 {
00994         a->targ = -2;
00995         if(Gunning(a))
00996                 DoStopGun(a);
00997         return "powering down weapons";
00998 }
00999 #endif
01000 #if 0
01001 ACMD(auto_rally)
01002 {
01003         char xb[6], yb[6];
01004         int x, y, h;
01005 
01006         if(Readnum(x, args[0]))
01007                 return "!Invalid X coord";
01008         if(Readnum(y, args[1]))
01009                 return "!Invalid Y coord";
01010         if(argc < 3)
01011                 h = MechFacing(mech);
01012         else if(Readnum(h, args[2]))
01013                 return "!Invalid heading";
01014         /* Base things on the <h = heading> */
01015         x = x + a->ofsy * cos(TWOPIOVER360 * (270 + (a->ofsx + h)));
01016         y = y + a->ofsy * sin(TWOPIOVER360 * (270 + (a->ofsx + h)));
01017         sprintf(xb, "%d", x);
01018         sprintf(yb, "%d", y);
01019         args[0] = xb;
01020         args[1] = yb;
01021         return auto_goto(a, mech, args, 2, chn);
01022 }
01023 #endif
01024 #if 0
01025 ACMD(auto_drally)
01026 {
01027         char xb[6], yb[6];
01028         int x, y, h;
01029 
01030         if(Readnum(x, args[0]))
01031                 return "!Invalid X coord";
01032         if(Readnum(y, args[1]))
01033                 return "!Invalid Y coord";
01034         if(argc < 3)
01035                 h = MechFacing(mech);
01036         else if(Readnum(h, args[2]))
01037                 return "!Invalid heading";
01038         /* Base things on the <h = heading> */
01039         x = x + a->ofsy * cos(TWOPIOVER360 * (270 + (a->ofsx + h)));
01040         y = y + a->ofsy * sin(TWOPIOVER360 * (270 + (a->ofsx + h)));
01041         sprintf(xb, "%d", x);
01042         sprintf(yb, "%d", y);
01043         args[0] = xb;
01044         args[1] = yb;
01045         return auto_dgoto(a, mech, args, 2, chn);
01046 }
01047 #endif
01048 #if 0
01049 ACMD(auto_roammode)
01050 {
01051         if(strcmp(args[0], "on") == 0) {
01052                 Clear(a);
01053                 auto_addcommand(a->mynum, a, tprintf("roammode 1"));
01054                 auto_engage(a->mynum, a, "");
01055                 return "Roam mode is ON";
01056         } else if(strcmp(args[0], "off") == 0) {
01057                 Clear(a);
01058                 auto_addcommand(a->mynum, a, tprintf("roammode 0"));
01059                 auto_engage(a->mynum, a, "");
01060                 return "Roam mode is OFF";
01061         }
01062         return "!Invalid input use on or off";
01063 }
01064 #endif
01065 #if 0
01066 ACMD(auto_swarmmode)
01067 {
01068         if(MechType(mech) != CLASS_BSUIT)
01069                 return "!I am not a battlesuit";
01070 
01071         if(strcmp(args[0], "on") == 0) {
01072                 a->flags |= AUTOPILOT_SWARMCHARGE;
01073                 return "Swarm Mode is ON";
01074         } else if(strcmp(args[0], "off") == 0) {
01075                 a->flags &= ~AUTOPILOT_SWARMCHARGE;
01076                 return "Swarm Mode is OFF";
01077         }
01078         return "!Invalid input use on or off";
01079 }
01080 #endif
01081 #if 0
01082 ACMD(auto_swarmcharge)
01083 {
01084         dbref targetref;
01085 
01086         if(MechType(mech) != CLASS_BSUIT)
01087                 return "!I am not a battlesuit";
01088 
01089         if(strcmp(args[0], "cancel") == 0) {
01090                 a->flags &= ~AUTOPILOT_SWARMCHARGE;
01091                 return "Canceling swarm charge";
01092         }
01093 
01094         targetref = FindTargetDBREFFromMapNumber(mech, args[0]);
01095         if(targetref <= 0)
01096                 return "!Invalid target to swarmcharge";
01097         Clear(a);
01098         auto_addcommand(a->mynum, a, tprintf("dumbfollow %d", targetref));
01099         auto_engage(a->mynum, a, "");
01100         a->flags |= AUTOPILOT_SWARMCHARGE;
01101         return tprintf("swarmcharging %s (%d degrees, %d away)", args[0],
01102                                    a->ofsx, a->ofsy);
01103 }
01104 #endif
01105 #if 0
01106 ACMD(auto_freq)
01107 {
01108         int freq;
01109 
01110         if(Readnum(freq, args[0]))
01111                 return "!Invalid freq";
01112         mech_set_channelfreq(a->mynum, mech, tprintf("a=%s", args[0]));
01113         return "channel changed";
01114 }
01115 #endif
01116 #if 0
01117 ACMD(auto_setchanfreq)
01118 {
01119         mech_set_channelfreq(a->mynum, mech, tprintf("%s=%s", args[0], args[1]));
01120         return tprintf("set channelfreq %s=%s", args[0], args[1]);
01121 }
01122 #endif
01123 #if 0
01124 ACMD(auto_setchanmode)
01125 {
01126         mech_set_channelmode(a->mynum, mech, tprintf("%s=%s", args[0], args[1]));
01127         return tprintf("set channelmode %s=%s", args[0], args[1]);
01128 }
01129 #endif
01130 #if 0
01131 ACMD(auto_enterbay)
01132 {
01133         mech_enterbay(a->mynum, mech, argc ? tprintf("%s",
01134                                                                                                  args[0]) : tprintf(""));
01135         return argc ? tprintf("entering bay (of %s)", args[0]) : "entering bay";
01136 }
01137 #endif
01138 #if 0
01139 ACMD(auto_cmode)
01140 {
01141         int mod, ran;
01142         static char buf[MBUF_SIZE];
01143 
01144         if(Readnum(mod, args[0]))
01145                 return "!Invalid mode [0-2]";
01146         if(mod < 0 || mod > 2)
01147                 return "!Invalid mode [0-2]";
01148         if(Readnum(ran, args[1]))
01149                 return "!Invalid range [0-999]";
01150         if(ran < 0 || ran > 999)
01151                 return "!Invalid range [0-999]";
01152         a->auto_cdist = ran;
01153         a->auto_cmode = mod;
01154         switch (mod) {
01155         case 0:
01156                 sprintf(buf, "fleeing, at least to range %d {from all foes}", ran);
01157                 break;
01158         case 1:
01159                 sprintf(buf, "trying to maintain range %d {from all foes}", ran);
01160                 break;
01161         case 2:
01162                 sprintf(buf, "charging to range %d {from all foes}", ran);
01163                 break;
01164         }
01165         return buf;
01166 }
01167 #endif
01168 
01169 /*
01170  * Event to get AI to radio a message
01171  */
01172 void auto_reply_event(MUXEVENT * muxevent)
01173 {
01174 
01175         MECH *mech = (MECH *) muxevent->data;
01176         char *buf = (char *) muxevent->data2;
01177         MAP *map;
01178 
01179         /* Make sure its a mech */
01180         if(!IsMech(mech->mynum)) {
01181                 free(buf);
01182                 return;
01183         }
01184 
01185         /* If valid object */
01186         if(mech)
01187                 if((map = (getMap(mech->mapindex))))
01188                         sendchannelstuff(mech, 0, buf);
01189 
01190         free(buf);
01191 }
01192 
01193 /*
01194  * Force the AI to reply over radio
01195  */
01196 void auto_reply(MECH * mech, char *buf)
01197 {
01198 
01199         char *reply;
01200 
01201         /* No zero freq messages */
01202         if(!mech->freq[0])
01203                 return;
01204 
01205         /* Make sure there is an autopilot */
01206         if(MechAuto(mech) <= 0)
01207                 return;
01208 
01209         /* Make sure valid objects */
01210         if(!(FindObjectsData(MechAuto(mech))) ||
01211            !Good_obj(MechAuto(mech)) || Location(MechAuto(mech)) != mech->mynum) {
01212                 MechAuto(mech) = -1;
01213                 return;
01214         }
01215 
01216         /* Copy the buffer */
01217         reply = strdup(buf);
01218 
01219         if(reply) {
01220                 MECHEVENT(mech, EVENT_AUTO_REPLY, auto_reply_event, Number(1, 2),
01221                                   reply);
01222         } else {
01223                 SendAI
01224                         ("Interal AI Error: Attempting to radio reply but unable to copy string");
01225         }
01226 
01227 }
01228 
01229 /*
01230  * Parse an AI radio command
01231  */
01232 void auto_parse_command(AUTO * autopilot, MECH * mech, int chn, char *buffer)
01233 {
01234 
01235         int argc, cmd;
01236         char *args[2];
01237         char *command_args[AUTOPILOT_MAX_ARGS];
01238         char mech_id[3];
01239         char message[LBUF_SIZE];
01240         char reply[LBUF_SIZE];
01241         int i;
01242 
01243         /* Basic checks */
01244         if(!autopilot || !mech)
01245                 return;
01246         if(Destroyed(mech))
01247                 return;
01248 
01249         /* Get the args - just need the first one */
01250         if(proper_explodearguments(buffer, args, 2) < 2) {
01251                 /* free args */
01252                 for(i = 0; i < 2; i++) {
01253                         if(args[i])
01254                                 free(args[i]);
01255                 }
01256                 return;
01257         }
01258 
01259         /* Check to see if the command was given to this AI */
01260         if(strcmp(args[0], "all")) {
01261                 mech_id[0] = MechID(mech)[0];
01262                 mech_id[1] = MechID(mech)[1];
01263                 mech_id[2] = '\0';
01264 
01265                 if(strcasecmp(mech_id, args[0])) {
01266                         /* free args */
01267                         for(i = 0; i < 2; i++) {
01268                                 if(args[i])
01269                                         free(args[i]);
01270                         }
01271                         return;
01272                 }
01273 
01274         }
01275 
01276         /* Parse the command */
01277         cmd = -1;
01278         argc = proper_explodearguments(args[1], command_args, AUTOPILOT_MAX_ARGS);
01279 
01280         /* Loop through the various possible commands looking for ours */
01281         for(i = 0; auto_cmds[i].sho; i++) {
01282                 if(!strncmp
01283                    (auto_cmds[i].sho, command_args[0], strlen(auto_cmds[i].sho)))
01284                         if(!strncmp
01285                            (auto_cmds[i].name, command_args[0],
01286                                 strlen(command_args[0]))) {
01287                                 if(argc == (auto_cmds[i].args + 1)) {
01288                                         cmd = i;
01289                                         break;
01290                                 }
01291                         }
01292         }
01293 
01294         /* Did we find a command */
01295         if(cmd < 0) {
01296 
01297                 snprintf(message, LBUF_SIZE, "Unable to comprehend the command.");
01298                 auto_reply(mech, message);
01299 
01300                 /* free args */
01301                 for(i = 0; i < 2; i++) {
01302                         if(args[i])
01303                                 free(args[i]);
01304                 }
01305                 for(i = 0; i < AUTOPILOT_MAX_ARGS; i++) {
01306                         if(command_args[i])
01307                                 free(command_args[i]);
01308                 }
01309                 return;
01310 
01311         }
01312 
01313         /* Zero the buffer */
01314         memset(message, 0, sizeof(message));
01315         memset(reply, 0, sizeof(reply));
01316 
01317         /* Call the radio command function */
01318         (*(auto_cmds[cmd].fun)) (autopilot, mech, command_args, argc, message);
01319 
01320         /* If its a silent command there is no reply */
01321         if(auto_cmds[cmd].silent) {
01322 
01323                 /* Free args and exit */
01324                 for(i = 0; i < 2; i++) {
01325                         if(args[i])
01326                                 free(args[i]);
01327                 }
01328                 for(i = 0; i < AUTOPILOT_MAX_ARGS; i++) {
01329                         if(command_args[i])
01330                                 free(command_args[i]);
01331                 }
01332                 return;
01333 
01334         }
01335 
01336         /* Check to see if a message was returned */
01337         if(*message) {
01338 
01339                 /* Check if there was an error message
01340                  * otherwise add a front and back to the message */
01341                 if(message[0] == '!') {
01342                         snprintf(reply, LBUF_SIZE, "ERROR: %s!", message + 1);
01343                 } else {
01344 
01345                         switch (Number(0, 20)) {
01346                         case 0:
01347                         case 1:
01348                         case 2:
01349                         case 4:
01350                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Affirmative, ",
01351                                                  message, ".");
01352                                 break;
01353                         case 5:
01354                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Nod, ", message, ".");
01355                                 break;
01356                         case 6:
01357                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Fine, ", message, ".");
01358                                 break;
01359                         case 7:
01360                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Aye aye, Captain, ",
01361                                                  message, "!");
01362                                 break;
01363                         case 8:
01364                         case 9:
01365                         case 10:
01366                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Da, boss, ",
01367                                                  message, "!");
01368                                 break;
01369                         case 11:
01370                         case 12:
01371                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Ok, ", message, ".");
01372                                 break;
01373                         case 13:
01374                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Okay, okay, ",
01375                                                  message, ", happy now?");
01376                                 break;
01377                         case 14:
01378                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Okidoki, ",
01379                                                  message, "!");
01380                                 break;
01381                         case 15:
01382                         case 16:
01383                         case 17:
01384                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Aye, ", message, ".");
01385                                 break;
01386                         default:
01387                                 snprintf(reply, LBUF_SIZE, "%s%s%s", "Roger, Roger, ",
01388                                                  message, ".");
01389                                 break;
01390                         }                                       /* End of switch */
01391 
01392                 }
01393 
01394                 auto_reply(mech, reply);
01395 
01396         } else if(!auto_cmds[cmd].silent) {
01397 
01398                 /* Command isn't silent but it didn't return a message */
01399                 snprintf(reply, LBUF_SIZE, "Ok.");
01400                 auto_reply(mech, reply);
01401 
01402         }
01403 
01404         /* free args */
01405         for(i = 0; i < 2; i++) {
01406                 if(args[i])
01407                         free(args[i]);
01408         }
01409         for(i = 0; i < AUTOPILOT_MAX_ARGS; i++) {
01410                 if(command_args[i])
01411                         free(command_args[i]);
01412         }
01413 
01414 }

Generated on Mon May 28 04:25:20 2007 for BattletechMUX by  doxygen 1.4.7