src/hcode/glue.scode.c

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: glue.scode.c,v 1.5 2005/08/08 09:43:09 murrayma Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *  Copyright (c) 1998-2002 Thomas Wouters 
00009  *  Copyright (c) 2000-2002 Cord Awtry 
00010  *  Copyright (c) 1999-2005 Kevin Stevens
00011  *       All rights reserved
00012  *
00013  * Created: Wed Oct  9 19:13:52 1996 fingon
00014  * Last modified: Tue Sep  8 10:00:29 1998 fingon
00015  *
00016  */
00017 
00018 #include "config.h"
00019 
00020 #include <stdio.h>
00021 #include <string.h>
00022 
00023 #include "mech.h"
00024 #include "mech.events.h"
00025 #include "glue.h"
00026 #include "coolmenu.h"
00027 #include "mycool.h"
00028 #include "turret.h"
00029 #include "p.template.h"
00030 #include "p.mech.tech.h"
00031 #include "p.mech.utils.h"
00032 #include "p.mech.partnames.h"
00033 #include "p.econ.h"
00034 #include "p.map.obj.h"
00035 #include "p.mech.tech.damages.h"
00036 #include "p.mech.status.h"
00037 #include "p.mech.sensor.h"
00038 #include "p.btechstats.h"
00039 #include "p.mech.combat.h"
00040 #include "p.mech.damage.h"
00041 #include "p.mechrep.h"
00042 #include "p.mech.move.h"
00043 #include "p.mech.los.h"
00044 #include "p.event.h"
00045 #include "p.mech.restrict.h"
00046 #include "mech.partnames.h"
00047 #include "p.functions.h"
00048 #include "p.mech.tech.commands.h"
00049 #include "p.mech.consistency.h"
00050 
00051 extern SpecialObjectStruct SpecialObjects[];
00052 dbref match_thing(dbref player, char *name);
00053 char *mechref_path(char *id);
00054 char *setarmorstatus_func(MECH * mech, char *sectstr, char *typestr,
00055                                                   char *valuestr);
00056 
00057 typedef struct {
00058         int gtype;
00059         char *name;
00060         void *rel_addr;
00061         int type;
00062         int size;
00063 } GMV;
00064 
00065 static MECH tmpm;
00066 static MAP tmpmap;
00067 static TURRET_T tmpturret;
00068 
00069 enum { TYPE_STRING, TYPE_CHAR, TYPE_SHORT, TYPE_INT, TYPE_FLOAT,
00070         TYPE_DBREF, TYPE_STRFUNC, TYPE_STRFUNC_S, TYPE_BV,
00071         TYPE_STRFUNC_BD, TYPE_CBV, TYPE_CHAR_RO, TYPE_SHORT_RO, TYPE_INT_RO,
00072         TYPE_FLOAT_RO, TYPE_DBREF_RO, TYPE_LAST_TYPE
00073 };
00074 
00075 /* INDENT OFF */
00076 static int scode_in_out[TYPE_LAST_TYPE] =
00077 /* st ch sh in fl db sf sfs bv sfb cbv ro-ch ro-sh ro-in ro-fl ro-db*/
00078 { 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 1, 1, 1, 1, 1 };
00079 /* INDENT ON */
00080 
00081 #define Uglie(dat) ((void *) &dat((MECH *)0))
00082 #define UglieV(dat,val) ((void *) &dat((MECH *)0,val))
00083 
00084 #define MeEntry(Name,Func,Type) {GTYPE_MECH,Name,Uglie(Func),Type,0}
00085 
00086 #define MeEntryS(Name,Func,Type,Size)  {GTYPE_MECH,Name,Uglie(Func),Type,Size}
00087 
00088 #define MeVEntry(Name,Func,Val,Type) {GTYPE_MECH,Name,UglieV(Func,Val),Type,0}
00089 
00090 #define UglieM(dat) ((void *)&((MAP *)0)->dat)
00091 #define MaEntry(Name,Func,Type) {GTYPE_MAP,Name,UglieM(Func),Type,0}
00092 #define MaEntryS(Name,Func,Type,Size)  {GTYPE_MAP,Name,UglieM(Func),Type,Size}
00093 
00094 #define UglieT(dat) (void *)&((TURRET_T *)0)->dat
00095 
00096 #define TuEntry(Name,Func,Type)  {GTYPE_TURRET,Name,UglieT(Func),Type,0}
00097 #define TuEntryS(Name,Func,Type,Size)  {GTYPE_TURRET,Name,UglieT(Func),Type,Size}
00098 
00099 char *mechIDfunc(int mode, MECH * mech)
00100 {
00101         static char buf[3];
00102 
00103         buf[0] = MechID(mech)[0];
00104         buf[1] = MechID(mech)[1];
00105         buf[2] = 0;
00106         return buf;
00107 }
00108 
00109 static char *mech_getset_ref(int mode, MECH * mech, char *data)
00110 {
00111         if(mode) {
00112                 strncpy(MechType_Ref(mech), data, 14);
00113                 MechType_Ref(mech)[14] = '\0';
00114                 return NULL;
00115         } else
00116                 return MechType_Ref(mech);
00117 }
00118 
00119 extern char *mech_types[];
00120 extern char *move_types[];
00121 
00122 char *mechTypefunc(int mode, MECH * mech, char *arg)
00123 {
00124         int i;
00125 
00126         if(!mode)
00127                 return mech_types[(short) MechType(mech)];
00128         /* Should _alter_ mechtype.. weeeel. */
00129         if((i = compare_array(mech_types, arg)) >= 0)
00130                 MechType(mech) = i;
00131         return NULL;
00132 }
00133 
00134 char *mechMovefunc(int mode, MECH * mech, char *arg)
00135 {
00136         int i;
00137 
00138         if(!mode)
00139                 return move_types[(short) MechMove(mech)];
00140         if((i = compare_array(move_types, arg)) >= 0)
00141                 MechMove(mech) = i;
00142         return NULL;
00143 }
00144 
00145 char *mechTechTimefunc(int mode, MECH * mech)
00146 {
00147         static char buf[MBUF_SIZE];
00148         int n = figure_latest_tech_event(mech);
00149 
00150         sprintf(buf, "%d", n);
00151         return buf;
00152 }
00153 
00154 void apply_mechDamage(MECH * omech, char *buf)
00155 {
00156         MECH mek;
00157         MECH *mech = &mek;
00158         int i, j, i1, i2, i3;
00159         char *s;
00160         int do_mag = 0;
00161 
00162         memcpy(mech, omech, sizeof(MECH));
00163         for(i = 0; i < NUM_SECTIONS; i++) {
00164                 SetSectInt(mech, i, GetSectOInt(mech, i));
00165                 SetSectArmor(mech, i, GetSectOArmor(mech, i));
00166                 SetSectRArmor(mech, i, GetSectORArmor(mech, i));
00167                 for(j = 0; j < NUM_CRITICALS; j++)
00168                         if(GetPartType(mech, i, j) && !IsCrap(GetPartType(mech, i, j))) {
00169                                 if(PartIsDestroyed(mech, i, j))
00170                                         UnDestroyPart(mech, i, j);
00171                                 if(IsAmmo(GetPartType(mech, i, j)))
00172                                         SetPartData(mech, i, j, FullAmmo(mech, i, j));
00173                                 else
00174                                         SetPartTempNuke(mech, i, j, 0);
00175                         }
00176         }
00177         s = buf;
00178         while (*s) {
00179                 while (*s && (*s == ' ' || *s == ','))
00180                         s++;
00181                 if(!(*s))
00182                         break;
00183                 /* Parse the keyword ; it's one of the many known types */
00184                 if(sscanf(s, "A:%d/%d", &i1, &i2) == 2) {
00185                         /* Ordinary armor damage */
00186                         if(i1 >= 0 && i1 < NUM_SECTIONS)
00187                                 SetSectArmor(mech, i1, GetSectOArmor(mech, i1) - i2);
00188                 } else if(sscanf(s, "A(R):%d/%d", &i1, &i2) == 2) {
00189                         /* Ordinary rear armor damage */
00190                         if(i1 >= 0 && i1 < NUM_SECTIONS)
00191                                 SetSectRArmor(mech, i1, GetSectORArmor(mech, i1) - i2);
00192                 } else if(sscanf(s, "I:%d/%d", &i1, &i2) == 2) {
00193                         /* Ordinary int damage */
00194                         if(i1 >= 0 && i1 < NUM_SECTIONS)
00195                                 SetSectInt(mech, i1, GetSectOInt(mech, i1) - i2);
00196                 } else if(sscanf(s, "C:%d/%d", &i1, &i2) == 2) {
00197                         /* Dest'ed crit */
00198                         if(i1 >= 0 && i1 < NUM_SECTIONS)
00199                                 DestroyPart(mech, i1, i2);
00200                 } else if(sscanf(s, "G:%d/%d(%d)", &i1, &i2, &i3) == 3) {
00201                         /* Glitch */
00202                         if(i1 >= 0 && i1 < NUM_SECTIONS)
00203                                 if(i2 >= 0 && i2 < NUM_CRITICALS)
00204                                         SetPartTempNuke(mech, i1, i2, i3);
00205                 } else if(sscanf(s, "R:%d/%d(%d)", &i1, &i2, &i3) == 3) {
00206                         /* Reload */
00207                         if(i1 >= 0 && i1 < NUM_SECTIONS)
00208                                 if(i2 >= 0 && i2 < NUM_CRITICALS)
00209                                         SetPartData(mech, i1, i2, FullAmmo(mech, i1, i2) - i3);
00210                 }
00211                 while (*s && (*s != ' ' && *s != ','))
00212                         s++;
00213         }
00214         for(i = 0; i < NUM_SECTIONS; i++) {
00215                 if(GetSectInt(mech, i) != GetSectInt(omech, i))
00216                         SetSectInt(omech, i, GetSectInt(mech, i));
00217                 if(GetSectArmor(mech, i) != GetSectArmor(omech, i))
00218                         SetSectArmor(omech, i, GetSectArmor(mech, i));
00219                 if(GetSectRArmor(mech, i) != GetSectRArmor(omech, i))
00220                         SetSectRArmor(omech, i, GetSectRArmor(mech, i));
00221                 for(j = 0; j < NUM_CRITICALS; j++)
00222                         if(GetPartType(mech, i, j) && !IsCrap(GetPartType(mech, i, j))) {
00223                                 if(PartIsDestroyed(mech, i, j) &&
00224                                    !PartIsDestroyed(omech, i, j)) {
00225                                         /* Blast a part */
00226                                         DestroyPart(omech, i, j);
00227                                         do_mag = 1;
00228                                 } else if(!PartIsDestroyed(mech, i, j) &&
00229                                                   PartIsDestroyed(omech, i, j)) {
00230                                         mech_RepairPart(omech, i, j);
00231                                         SetPartTempNuke(omech, i, j, 0);
00232                                         do_mag = 1;
00233                                 }
00234                                 if(IsAmmo(GetPartType(mech, i, j))) {
00235                                         if(GetPartData(mech, i, j) != GetPartData(omech, i, j))
00236                                                 SetPartData(omech, i, j, GetPartData(mech, i, j));
00237                                 } else {
00238                                         if(PartTempNuke(mech, i, j) != PartTempNuke(omech, i, j))
00239                                                 SetPartTempNuke(omech, i, j,
00240                                                                                 PartTempNuke(mech, i, j));
00241 
00242                                 }
00243                         }
00244         }
00245         if(do_mag && MechType(omech) == CLASS_MECH)
00246                 do_magic(omech);
00247 }
00248 
00249 #define ADD(foo...) { if (count++) strcat(buf,","); sprintf(buf+strlen(buf), foo); }
00250 
00251 char *mechDamagefunc(int mode, MECH * mech, char *arg)
00252 {
00253         /* Lists damage in form:
00254            A:LOC/num[,LOC/num[,LOC(R)/num]],I:LOC/num
00255            C:LOC/num,R:LOC/num(num),G:LOC/num(num) */
00256         int i, j;
00257         static char buf[LBUF_SIZE];
00258         int count = 0;
00259 
00260         if(mode) {
00261                 apply_mechDamage(mech, arg);
00262                 return "?";
00263         };
00264         buf[0] = 0;
00265         for(i = 0; i < NUM_SECTIONS; i++)
00266                 if(GetSectOInt(mech, i)) {
00267                         if(GetSectArmor(mech, i) != GetSectOArmor(mech, i))
00268                                 ADD("A:%d/%d", i, GetSectOArmor(mech,
00269                                                                                                 i) - GetSectArmor(mech, i));
00270                         if(GetSectRArmor(mech, i) != GetSectORArmor(mech, i))
00271                                 ADD("A(R):%d/%d", i, GetSectORArmor(mech,
00272                                                                                                         i) - GetSectRArmor(mech,
00273                                                                                                                                            i));
00274                 }
00275         for(i = 0; i < NUM_SECTIONS; i++)
00276                 if(GetSectOInt(mech, i))
00277                         if(GetSectInt(mech, i) != GetSectOInt(mech, i))
00278                                 ADD("I:%d/%d", i, GetSectOInt(mech, i) - GetSectInt(mech, i));
00279         for(i = 0; i < NUM_SECTIONS; i++)
00280                 for(j = 0; j < CritsInLoc(mech, i); j++) {
00281                         if(GetPartType(mech, i, j) && !IsCrap(GetPartType(mech, i, j))) {
00282                                 if(PartIsDestroyed(mech, i, j)) {
00283                                         ADD("C:%d/%d", i, j);
00284                                 } else {
00285                                         if(IsAmmo(GetPartType(mech, i, j))) {
00286                                                 if(GetPartData(mech, i, j) != FullAmmo(mech, i, j))
00287                                                         ADD("R:%d/%d(%d)", i, j, FullAmmo(mech,
00288                                                                                                                           i,
00289                                                                                                                           j) -
00290                                                                 GetPartData(mech, i, j));
00291                                         } else if(PartTempNuke(mech, i, j))
00292                                                 ADD("G:%d/%d(%d)", i, j, PartTempNuke(mech, i, j));
00293                                 }
00294                         }
00295                 }
00296         return buf;
00297 }
00298 
00299 char *mechCentBearingfunc(int mode, MECH * mech, char *arg)
00300 {
00301         int x = MechX(mech);
00302         int y = MechY(mech);
00303         float fx, fy;
00304         static char buf[SBUF_SIZE];
00305 
00306         MapCoordToRealCoord(x, y, &fx, &fy);
00307         sprintf(buf, "%d", FindBearing(MechFX(mech), MechFY(mech), fx, fy));
00308         return buf;
00309 }
00310 
00311 char *mechCentDistfunc(int mode, MECH * mech, char *arg)
00312 {
00313         int x = MechX(mech);
00314         int y = MechY(mech);
00315         float fx, fy;
00316         static char buf[SBUF_SIZE];
00317 
00318         MapCoordToRealCoord(x, y, &fx, &fy);
00319         sprintf(buf, "%.2f", FindHexRange(fx, fy, MechFX(mech), MechFY(mech)));
00320         return buf;
00321 }
00322 
00323 /* Mode:
00324    0 = char -> bit field
00325    1 = bit field -> char
00326    */
00327 
00328 static int bv_val(int in, int mode)
00329 {
00330         int p = 0;
00331 
00332         if(mode == 0) {
00333                 if(in >= 'a' && in <= 'z')
00334                         return 1 << (in - 'a');
00335                 return 1 << ('z' - 'a' + 1 + (in - 'A'));
00336         }
00337         while (in > 0) {
00338                 p++;
00339                 in >>= 1;
00340         }
00341         /* Hmm. */
00342         p--;
00343         if(p > ('z' - 'a'))
00344                 return 'A' + (p - ('z' - 'a' + 1));
00345         return 'a' + p;
00346 }
00347 
00348 static int text2bv(char *text)
00349 {
00350         char *c;
00351         int j = 0;
00352         int mode_not = 0;
00353 
00354         if(!Readnum(j, text))
00355                 return j;                               /* Allow 'old style' as well */
00356 
00357         /* Valid bitvector letters are: a-z (=27), A-Z (=27 more) */
00358         for(c = text; *c; c++) {
00359                 if(*c == '!') {
00360                         mode_not = 1;
00361                         c++;
00362                 };
00363                 if((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z')) {
00364                         int k = bv_val(*c, 0);
00365 
00366                         if(k) {
00367                                 if(mode_not)
00368                                         j &= ~k;
00369                                 else
00370                                         j |= k;
00371                         }
00372                 }
00373                 mode_not = 0;
00374         }
00375         return j;
00376 }
00377 
00378 static char *bv2text(int i)
00379 {
00380         static char buf[SBUF_SIZE];
00381         int p = 1;
00382         char *c = buf;
00383 
00384         while (i > 0) {
00385                 if(i & 1)
00386                         *(c++) = bv_val(p, 1);
00387                 i >>= 1;
00388                 p <<= 1;
00389         }
00390         if(c == buf)
00391                 *(c++) = '-';
00392         *c = 0;
00393         return buf;
00394 }
00395 
00396 #undef offsetof
00397 #ifdef __compiler_offsetof
00398 #define offsetof(TYPE,MEMBER) (void *)__compiler_offsetof(TYPE,MEMBER)
00399 #else
00400 #define offsetof(TYPE, MEMBER) (void *)((size_t) &((TYPE *)0)->MEMBER)
00401 #endif
00402 
00403 static GMV xcode_data[] = {
00404         {GTYPE_MECH, "mapindex", offsetof(MECH, mapindex), TYPE_DBREF_RO},
00405         {GTYPE_MECH, "id", mechIDfunc, TYPE_STRFUNC},
00406         MeEntryS("mechname", MechType_Name, TYPE_STRING, 31),
00407         MeEntry("maxspeed", MechMaxSpeed, TYPE_FLOAT),
00408         MeEntry("templatesp",TemplateMaxSpeed,TYPE_FLOAT),
00409         MeEntry("pilotnum", MechPilot, TYPE_DBREF),
00410         MeEntry("xpmod", MechXPMod, TYPE_FLOAT),
00411         MeEntry("pilotdam", MechPilotStatus, TYPE_CHAR),
00412         MeEntry("si", AeroSI, TYPE_CHAR),
00413         MeEntry("si_orig", AeroSIOrig, TYPE_CHAR),
00414         MeEntry("speed", MechSpeed, TYPE_FLOAT),
00415         MeEntry("basewalkspeed", MechBaseWalk, TYPE_INT),
00416         MeEntry("baserunspeed", MechBaseRun, TYPE_INT),
00417         MeEntry("heading", MechRFacing, TYPE_SHORT),
00418         MeEntry("stall", MechStall, TYPE_INT),
00419         MeEntry("status", MechStatus, TYPE_BV),
00420         MeEntry("status2", MechStatus2, TYPE_BV),
00421         MeEntry("critstatus", MechCritStatus, TYPE_BV),
00422         MeEntry("critstatus2", MechCritStatus2, TYPE_BV),
00423         MeEntry("tankcritstatus", MechTankCritStatus, TYPE_BV),
00424         MeEntry("target", MechTarget, TYPE_DBREF),
00425         MeEntry("team", MechTeam, TYPE_INT),
00426         MeEntry("tons", MechTons, TYPE_INT),
00427         MeEntry("towing", MechCarrying, TYPE_INT_RO),
00428         MeEntry("heat", MechPlusHeat, TYPE_FLOAT),
00429         MeEntry("disabled_hs", MechDisabledHS, TYPE_INT_RO),
00430         MeEntry("overheat", MechHeat, TYPE_FLOAT),
00431         MeEntry("dissheat", MechMinusHeat, TYPE_FLOAT),
00432         MeEntry("heatsinks", MechRealNumsinks, TYPE_CHAR_RO),
00433         MeEntry("last_startup", MechLastStartup, TYPE_INT),
00434         MeEntry("C3iNetworkSize", MechC3iNetworkSize, TYPE_INT_RO),
00435         MeEntry("MaxSuits", MechMaxSuits, TYPE_INT),
00436         MeEntry("realweight", MechRTonsV, TYPE_INT),
00437         MeEntry("StaggerDamage", StaggerDamage, TYPE_INT_RO),
00438         MeEntry("MechPrefs", MechPrefs, TYPE_BV),
00439         MeEntry("SwarmTarget", MechSwarmTarget, TYPE_DBREF),
00440         MeEntry("SwarmedBy", MechSwarmer, TYPE_DBREF),
00441         
00442         {GTYPE_MECH, "mechtype", mechTypefunc, TYPE_STRFUNC_BD},
00443         {GTYPE_MECH, "mechmovetype", mechMovefunc, TYPE_STRFUNC_BD},
00444         {GTYPE_MECH, "mechdamage", mechDamagefunc, TYPE_STRFUNC_BD},
00445         {GTYPE_MECH, "techtime", mechTechTimefunc, TYPE_STRFUNC},
00446         {GTYPE_MECH, "centdist", mechCentDistfunc, TYPE_STRFUNC},
00447         {GTYPE_MECH, "centbearing", mechCentBearingfunc, TYPE_STRFUNC},
00448         {GTYPE_MECH, "sensors", mechSensorInfo, TYPE_STRFUNC},
00449         {GTYPE_MECH, "mechref", mech_getset_ref, TYPE_STRFUNC_BD},
00450 
00451         MeEntry("fuel", AeroFuel, TYPE_INT),
00452         MeEntry("fuel_orig", AeroFuelOrig, TYPE_INT),
00453         MeEntry("cocoon", MechCocoon, TYPE_INT_RO),
00454         MeEntry("numseen", MechNumSeen, TYPE_SHORT),
00455 
00456         MeEntry("fx", MechFX, TYPE_FLOAT),
00457         MeEntry("fy", MechFY, TYPE_FLOAT),
00458         MeEntry("fz", MechFZ, TYPE_FLOAT),
00459         MeEntry("x", MechX, TYPE_SHORT),
00460         MeEntry("y", MechY, TYPE_SHORT),
00461         MeEntry("z", MechZ, TYPE_SHORT),
00462         MeEntry("elevation", MechElev, TYPE_CHAR),
00463 
00464         MeEntry("targcomp", MechTargComp, TYPE_CHAR),
00465         MeEntry("lrsrange", MechLRSRange, TYPE_CHAR),
00466         MeEntry("radiorange", MechRadioRange, TYPE_SHORT),
00467         MeEntry("scanrange", MechScanRange, TYPE_CHAR),
00468         MeEntry("tacrange", MechTacRange, TYPE_CHAR),
00469         MeEntry("radiotype", MechRadioType, TYPE_CHAR),
00470         MeEntry("bv", MechBV, TYPE_INT),
00471         MeEntry("cargospace", CargoSpace, TYPE_INT),
00472         MeEntry("carmaxton", CarMaxTon, TYPE_CHAR_RO),
00473 
00474         MeVEntry("bay0", AeroBay, 0, TYPE_DBREF),
00475         MeVEntry("bay1", AeroBay, 1, TYPE_DBREF),
00476         MeVEntry("bay2", AeroBay, 2, TYPE_DBREF),
00477         MeVEntry("bay3", AeroBay, 3, TYPE_DBREF),
00478 
00479         MeVEntry("turret0", AeroTurret, 0, TYPE_DBREF),
00480         MeVEntry("turret1", AeroTurret, 1, TYPE_DBREF),
00481         MeVEntry("turret2", AeroTurret, 2, TYPE_DBREF),
00482 
00483         MeEntry("unusablearcs", AeroUnusableArcs, TYPE_INT_RO),
00484         MeEntry("maxjumpspeed", MechJumpSpeed, TYPE_FLOAT),
00485         MeEntry("jumpheading", MechJumpHeading, TYPE_SHORT),
00486         MeEntry("jumplength", MechJumpLength, TYPE_SHORT),
00487 
00488         MaEntry("buildflag", buildflag, TYPE_CHAR),
00489         MaEntry("buildonmap", onmap, TYPE_DBREF_RO),
00490         MaEntry("cf", cf, TYPE_SHORT),
00491         MaEntry("cfmax", cfmax, TYPE_SHORT),
00492         MaEntry("gravity", grav, TYPE_CHAR),
00493         MaEntry("firstfree", first_free, TYPE_CHAR_RO),
00494         MaEntry("mapheight", map_height, TYPE_SHORT_RO),
00495         MaEntry("maplight", maplight, TYPE_CHAR),
00496         MaEntryS("mapname", mapname, TYPE_STRING, 30),
00497         MaEntry("mapvis", mapvis, TYPE_CHAR),
00498         MaEntry("mapwidth", map_width, TYPE_SHORT_RO),
00499         MaEntry("maxvis", maxvis, TYPE_SHORT),
00500         MaEntry("temperature", temp, TYPE_CHAR),
00501         MaEntry("winddir", winddir, TYPE_SHORT),
00502         MaEntry("windspeed", windspeed, TYPE_SHORT),
00503         MaEntry("cloudbase", cloudbase, TYPE_SHORT),
00504         MaEntry("flags", flags, TYPE_BV),
00505         MaEntry("sensorflags", sensorflags, TYPE_BV),
00506 
00507         TuEntry("arcs", arcs, TYPE_INT),
00508         TuEntry("parent", parent, TYPE_DBREF),
00509         TuEntry("gunner", gunner, TYPE_DBREF),
00510         TuEntry("target", target, TYPE_DBREF),
00511         TuEntry("targx", target, TYPE_SHORT),
00512         TuEntry("targy", target, TYPE_SHORT),
00513         TuEntry("targz", target, TYPE_SHORT),
00514         TuEntry("lockmode", lockmode, TYPE_INT),
00515 
00516         MeEntry("radio", MechRadio, TYPE_CHAR),
00517         MeEntry("computer", MechComputer, TYPE_CHAR),
00518         MeEntry("perception", MechPer, TYPE_INT),
00519 
00520         {-1, NULL, 0, TYPE_STRING}
00521 };
00522 
00523 void fun_btsetxcodevalue(char *buff, char **bufc, dbref player, dbref cause,
00524                                                  char *fargs[], int nfargs, char *cargs[], int ncargs)
00525 {
00526         /* fargs[0] = id of the mech
00527            fargs[1] = name of the value
00528            fargs[2] = what the value's to be set as
00529          */
00530         dbref it;
00531         int i, spec;
00532         void *foo;
00533         void *bar;
00534         void *(*tempfun) ();
00535 
00536         it = match_thing(player, fargs[0]);
00537         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
00538         spec = WhichSpecial(it);
00539         FUNCHECK(!(foo = FindObjectsData(it)), "#-1");
00540         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00541         for(i = 0; xcode_data[i].name; i++)
00542                 if(!strcasecmp(fargs[1], xcode_data[i].name) &&
00543                    xcode_data[i].gtype == spec &&
00544                    (scode_in_out[xcode_data[i].type] & 2)) {
00545                         bar = (void *) ((int) foo + xcode_data[i].rel_addr);
00546                         switch (xcode_data[i].type) {
00547                         case TYPE_STRFUNC_BD:
00548                         case TYPE_STRFUNC_S:
00549                                 tempfun = (void *) xcode_data[i].rel_addr;
00550                                 tempfun(1, (MECH *) foo, (char *) fargs[2]);
00551                                 break;
00552                         case TYPE_STRING:
00553                                 strncpy((char *) bar, fargs[2], xcode_data[i].size - 1);
00554                                 ((char *) bar)[xcode_data[i].size - 1] = '\0';
00555                                 break;
00556                         case TYPE_DBREF:
00557                                 *((dbref *) bar) = atoi(fargs[2]);
00558                                 break;
00559                         case TYPE_CHAR:
00560                                 *((char *) bar) = atoi(fargs[2]);
00561                                 break;
00562                         case TYPE_SHORT:
00563                                 *((short *) bar) = atoi(fargs[2]);
00564                                 break;
00565                         case TYPE_INT:
00566                                 *((int *) bar) = atoi(fargs[2]);
00567                                 break;
00568                         case TYPE_FLOAT:
00569                                 *((float *) bar) = atof(fargs[2]);
00570                                 break;
00571                         case TYPE_BV:
00572                                 *((int *) bar) = text2bv(fargs[2]);
00573                                 break;
00574                         case TYPE_CBV:
00575                                 *((byte *) bar) = (byte) text2bv(fargs[2]);
00576                                 break;
00577                         }
00578                         safe_tprintf_str(buff, bufc, "1");
00579                         return;
00580                 }
00581         safe_tprintf_str(buff, bufc, "#-1");
00582         return;
00583 }
00584 
00585 static char *RetrieveValue(void *data, int i)
00586 {
00587         void *bar = (void *) ((int) data + xcode_data[i].rel_addr);
00588         static char buf[LBUF_SIZE];
00589         char *(*tempfun) ();
00590 
00591         switch (xcode_data[i].type) {
00592         case TYPE_STRFUNC_BD:
00593         case TYPE_STRFUNC:
00594                 tempfun = (void *) xcode_data[i].rel_addr;
00595                 sprintf(buf, "%s", (char *) tempfun(0, (MECH *) data));
00596                 break;
00597         case TYPE_STRING:
00598                 sprintf(buf, "%s", (char *) bar);
00599                 break;
00600         case TYPE_DBREF:
00601         case TYPE_DBREF_RO:
00602                 sprintf(buf, "%d", (dbref) * ((dbref *) bar));
00603                 break;
00604         case TYPE_CHAR:
00605         case TYPE_CHAR_RO:
00606                 sprintf(buf, "%d", (char) *((char *) bar));
00607                 break;
00608         case TYPE_SHORT:
00609         case TYPE_SHORT_RO:
00610                 sprintf(buf, "%d", (short) *((short *) bar));
00611                 break;
00612         case TYPE_INT:
00613         case TYPE_INT_RO:
00614                 sprintf(buf, "%d", (int) *((int *) bar));
00615                 break;
00616         case TYPE_FLOAT:
00617         case TYPE_FLOAT_RO:
00618                 sprintf(buf, "%.2f", (float) *((float *) bar));
00619                 break;
00620         case TYPE_BV:
00621                 strcpy(buf, bv2text((int) *((int *) bar)));
00622                 break;
00623         case TYPE_CBV:
00624                 strcpy(buf, bv2text((int) *((char *) bar)));
00625                 break;
00626         }
00627         return buf;
00628 }
00629 
00630 void fun_btgetxcodevalue(char *buff, char **bufc, dbref player, dbref cause,
00631                                                  char *fargs[], int nfargs, char *cargs[], int ncargs)
00632 {
00633         /* fargs[0] = id of the mech
00634            fargs[1] = name of the value
00635          */
00636         dbref it;
00637         int i;
00638         void *foo;
00639         int spec;
00640 
00641         it = match_thing(player, fargs[0]);
00642         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
00643         spec = WhichSpecial(it);
00644         FUNCHECK(!(foo = FindObjectsData(it)), "#-1");
00645         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00646         for(i = 0; xcode_data[i].name; i++)
00647                 if(!strcasecmp(fargs[1], xcode_data[i].name) &&
00648                    xcode_data[i].gtype == spec &&
00649                    (scode_in_out[xcode_data[i].type] & 1)) {
00650                         safe_tprintf_str(buff, bufc, "%s", RetrieveValue(foo, i));
00651                         return;
00652                 }
00653         safe_tprintf_str(buff, bufc, "#-1");
00654         return;
00655 }
00656 
00657 void fun_btgetxcodevalue_ref(char *buff, char **bufc, dbref player,
00658                                                          dbref cause, char *fargs[], int nfargs,
00659                                                          char *cargs[], int ncargs)
00660 {
00661         /* fargs[0] = mech ref
00662            fargs[1] = name of the value
00663          */
00664         int i;
00665         MECH *foo;
00666         int spec;
00667 
00668         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00669         FUNCHECK((foo = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
00670         spec = GTYPE_MECH;
00671         for(i = 0; xcode_data[i].name; i++)
00672                 if(!strcasecmp(fargs[1], xcode_data[i].name) &&
00673                    xcode_data[i].gtype == spec &&
00674                    (scode_in_out[xcode_data[i].type] & 1)) {
00675                         safe_tprintf_str(buff, bufc, "%s", RetrieveValue(foo, i));
00676                         return;
00677                 }
00678         safe_tprintf_str(buff, bufc, "#-1");
00679         return;
00680 }
00681 
00682 void set_xcodestuff(dbref player, void *data, char *buffer)
00683 {
00684         char *args[2];
00685         int t, i;
00686         void *bar;
00687         void *(*tempfun) ();
00688 
00689         memset(args, 0, sizeof(char *) * 2);
00690 
00691         DOCHECK(silly_parseattributes(buffer, args, 2) != 2,
00692                         "Invalid arguments!");
00693         t = WhichSpecial(Location(player));
00694         for(i = 0; xcode_data[i].name; i++)
00695                 if(xcode_data[i].gtype == t)
00696                         break;
00697         DOCHECK(!xcode_data[i].name,
00698                         "Error: No xcode values for this type of object found.");
00699         for(i = 0; xcode_data[i].name; i++)
00700                 if(!strcasecmp(args[0], xcode_data[i].name) &&
00701                    xcode_data[i].gtype == t && (scode_in_out[xcode_data[i].type] & 2))
00702                         break;
00703         DOCHECK(!xcode_data[i].name,
00704                         "Error: No matching xcode value for this type of object found.");
00705         bar =
00706                 (void *) ((int) FindObjectsData(Location(player)) +
00707                                   xcode_data[i].rel_addr);
00708         switch (xcode_data[i].type) {
00709         case TYPE_STRFUNC_BD:
00710         case TYPE_STRFUNC_S:
00711                 tempfun = (void *) xcode_data[i].rel_addr;
00712                 tempfun(1, getMech(Location(player)), (char *) args[1]);
00713                 break;
00714         case TYPE_STRING:
00715                 strncpy((char *) bar, args[1], xcode_data[i].size - 1);
00716                 ((char *) bar)[xcode_data[i].size - 1] = '\0';
00717                 break;
00718         case TYPE_DBREF:
00719                 *((dbref *) bar) = atoi(args[1]);
00720                 break;
00721         case TYPE_CHAR:
00722                 *((char *) bar) = atoi(args[1]);
00723                 break;
00724         case TYPE_SHORT:
00725                 *((short *) bar) = atoi(args[1]);
00726                 break;
00727         case TYPE_INT:
00728                 *((int *) bar) = atoi(args[1]);
00729                 break;
00730         case TYPE_FLOAT:
00731                 *((float *) bar) = atof(args[1]);
00732                 break;
00733         case TYPE_BV:
00734                 *((int *) bar) = text2bv(args[1]);
00735                 break;
00736         case TYPE_CBV:
00737                 *((byte *) bar) = (byte) text2bv(args[1]);
00738         }
00739 }
00740 
00741 void list_xcodestuff(dbref player, void *data, char *buffer)
00742 {
00743         int t, i, flag = CM_TWO, se_len = 37;
00744         coolmenu *c = NULL;
00745 
00746         t = WhichSpecial(Location(player));
00747         for(i = 0; xcode_data[i].name; i++)
00748                 if(xcode_data[i].gtype == t && (scode_in_out[xcode_data[i].type] & 1))
00749                         break;
00750         DOCHECK(!xcode_data[i].name,
00751                         "Error: No xcode values for this type of object found.");
00752         addline();
00753         cent(tprintf("Data for %s (%s)", Name(Location(player)),
00754                                  SpecialObjects[t].type));
00755         addline();
00756         if(*buffer == '1') {
00757                 flag = CM_ONE;
00758                 se_len = se_len * 2;
00759         };
00760         if(*buffer == '4') {
00761                 flag = CM_FOUR;
00762                 se_len = se_len / 2;
00763         };
00764         if(*buffer == '1' || *buffer == '4')
00765                 buffer++;
00766         for(i = 0; xcode_data[i].name; i++) {
00767                 if(xcode_data[i].gtype == t && (scode_in_out[xcode_data[i].type] & 1)) {
00768                         /* 1/3(left) = name, 2/3(right)=value */
00769                         char mask[SBUF_SIZE];
00770                         char lab[SBUF_SIZE];
00771 
00772                         if(*buffer)
00773                                 if(strncasecmp(xcode_data[i].name, buffer, strlen(buffer)))
00774                                         continue;
00775                         strcpy(lab, xcode_data[i].name);
00776                         lab[se_len / 3] = 0;
00777                         sprintf(mask, "%%-%ds%%%ds", se_len / 3, se_len * 2 / 3);
00778                         sim(tprintf(mask, lab, RetrieveValue(data, i)), flag);
00779                 }
00780         }
00781         addline();
00782         ShowCoolMenu(player, c);
00783         KillCoolMenu(c);
00784 }
00785 
00786 void fun_btunderrepair(char *buff, char **bufc, dbref player, dbref cause,
00787                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
00788 {
00789         /* fargs[0] = ref of the mech to be checked */
00790         int n;
00791         MECH *mech;
00792         dbref it;
00793 
00794         it = match_thing(player, fargs[0]);
00795         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
00796         FUNCHECK(!IsMech(it), "#-2");
00797         mech = FindObjectsData(it);
00798         n = figure_latest_tech_event(mech);
00799         safe_tprintf_str(buff, bufc, "%d", n > 0);
00800 }
00801 
00802 void fun_btstores(char *buff, char **bufc, dbref player, dbref cause,
00803                                   char *fargs[], int nfargs, char *cargs[], int ncargs)
00804 {
00805         /* fargs[0] = id of the bay/mech */
00806         /* fargs[1] = (optional) name of the part */
00807         dbref it;
00808         int i = -1, x = 0;
00809         int p, b;
00810         int pile[BRANDCOUNT + 1][NUM_ITEMS];
00811         char *t;
00812 
00813         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00814         FUNCHECK(nfargs < 1 || nfargs > 2,
00815                          "#-1 FUNCTION (BTSTORES) EXPECTS 1 OR 2 ARGUMENTS");
00816         it = match_thing(player, fargs[0]);
00817         FUNCHECK(!Good_obj(it), "#-1 INVALID TARGET");
00818         if(nfargs > 1) {
00819                 i = -1;
00820                 if(!find_matching_long_part(fargs[1], &i, &p, &b)) {
00821                         i = -1;
00822                         FUNCHECK(!find_matching_vlong_part(fargs[1], &i, &p, &b),
00823                                          "#-1 INVALID PART NAME");
00824                 }
00825                 safe_tprintf_str(buff, bufc, "%d", econ_find_items(it, p, b));
00826         } else {
00827                 memset(pile, 0, sizeof(pile));
00828                 t = silly_atr_get(it, A_ECONPARTS);
00829                 while (*t) {
00830                         if(*t == '[')
00831                                 if((sscanf(t, "[%d,%d,%d]", &i, &p, &b)) == 3)
00832                                         pile[p][i] += b;
00833                         t++;
00834                 }
00835                 for(i = 0; i < object_count; i++) {
00836                         UNPACK_PART(short_sorted[i]->index, p, b);
00837                         if(pile[b][p]) {
00838                                 if(x)
00839                                         safe_str("|", buff, bufc);
00840                                 x = pile[b][p];
00841                                 safe_tprintf_str(buff, bufc, "%s:%d",
00842                                                                  part_name_long(p, b), x);
00843                         }
00844                 }
00845         }
00846 }
00847 
00848 void fun_btmapterr(char *buff, char **bufc, dbref player, dbref cause,
00849                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
00850 {
00851         /* fargs[0] = reference of map
00852            fargs[1] = x
00853            fargs[2] = y
00854          */
00855         dbref it;
00856         MAP *map;
00857         int x, y;
00858         int spec;
00859         char terr;
00860 
00861         it = match_thing(player, fargs[0]);
00862         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
00863         spec = WhichSpecial(it);
00864         FUNCHECK(spec != GTYPE_MAP, "#-1");
00865         FUNCHECK(!(map = FindObjectsData(it)), "#-1");
00866         FUNCHECK(Readnum(x, fargs[1]), "#-2");
00867         FUNCHECK(Readnum(y, fargs[2]), "#-2");
00868         FUNCHECK(x < 0 || y < 0 || x >= map->map_width ||
00869                          y >= map->map_height, "?");
00870         terr = GetTerrain(map, x, y);
00871         if(terr == GRASSLAND)
00872                 terr = '.';
00873 
00874         safe_tprintf_str(buff, bufc, "%c", terr);
00875 }
00876 
00877 void fun_btmapelev(char *buff, char **bufc, dbref player, dbref cause,
00878                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
00879 {
00880         /* fargs[0] = reference of map
00881            fargs[1] = x
00882            fargs[2] = y
00883          */
00884         dbref it;
00885         int i;
00886         MAP *map;
00887         int x, y;
00888         int spec;
00889 
00890         it = match_thing(player, fargs[0]);
00891         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
00892         spec = WhichSpecial(it);
00893         FUNCHECK(spec != GTYPE_MAP, "#-1");
00894         FUNCHECK(!(map = FindObjectsData(it)), "#-1");
00895         FUNCHECK(Readnum(x, fargs[1]), "#-2");
00896         FUNCHECK(Readnum(y, fargs[2]), "#-2");
00897         FUNCHECK(x < 0 || y < 0 || x >= map->map_width
00898                          || y >= map->map_height, "?");
00899         i = Elevation(map, x, y);
00900         if(i < 0)
00901                 safe_tprintf_str(buff, bufc, "-%c", '0' + -i);
00902         else
00903                 safe_tprintf_str(buff, bufc, "%c", '0' + i);
00904 }
00905 
00906 void list_xcodevalues(dbref player)
00907 {
00908         int i;
00909 
00910         notify(player, "Xcode attributes accessible thru get/setxcodevalue:");
00911         for(i = 0; xcode_data[i].name; i++)
00912                 notify(player, tprintf("\t%d\t%s", xcode_data[i].gtype,
00913                                                            xcode_data[i].name));
00914 }
00915 
00916 /* Glue functions for easy scode interface to ton of hcode stuff */
00917 
00918 void fun_btdesignex(char *buff, char **bufc, dbref player, dbref cause,
00919                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
00920 {
00921         char *id = fargs[0];
00922 
00923         if(mechref_path(id)) {
00924                 safe_tprintf_str(buff, bufc, "1");
00925         } else
00926                 safe_tprintf_str(buff, bufc, "0");
00927 }
00928 
00929 void fun_btdamages(char *buff, char **bufc, dbref player, dbref cause,
00930                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
00931 {
00932         /* fargs[0] = id of the mech
00933          */
00934         dbref it;
00935         char *damstr;
00936         MECH *mech;
00937 
00938         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00939         it = match_thing(player, fargs[0]);
00940         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
00941         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
00942         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
00943         damstr = damages_func(mech);
00944         safe_tprintf_str(buff, bufc, damstr ? damstr : "#-1 ERROR");
00945 }
00946 
00947 void fun_btcritstatus(char *buff, char **bufc, dbref player, dbref cause,
00948                                           char *fargs[], int nfargs, char *cargs[], int ncargs)
00949 {
00950         /* fargs[0] = id of the mech
00951          * fargs[1] = location to show
00952          */
00953         dbref it;
00954         char *critstr;
00955         MECH *mech;
00956 
00957         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00958         it = match_thing(player, fargs[0]);
00959         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
00960         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
00961         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
00962         critstr = critstatus_func(mech, fargs[1]);      /* fargs[1] unguaranteed ! */
00963         safe_tprintf_str(buff, bufc, critstr ? critstr : "#-1 ERROR");
00964 }
00965 
00966 void fun_btarmorstatus(char *buff, char **bufc, dbref player, dbref cause,
00967                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
00968 {
00969         /* fargs[0] = id of the mech
00970          * fargs[1] = location to show
00971          */
00972         dbref it;
00973         char *infostr;
00974         MECH *mech;
00975 
00976         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00977         it = match_thing(player, fargs[0]);
00978         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
00979         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
00980         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
00981         infostr = armorstatus_func(mech, fargs[1]);     /* fargs[1] unguaranteed ! */
00982         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1 ERROR");
00983 }
00984 
00985 void fun_btweaponstatus(char *buff, char **bufc, dbref player, dbref cause,
00986                                                 char *fargs[], int nfargs, char *cargs[], int ncargs)
00987 {
00988         /* fargs[0] = id of the mech
00989          * fargs[1] = location to show
00990          */
00991         dbref it;
00992         char *infostr;
00993         MECH *mech;
00994 
00995         FUNCHECK(nfargs < 1 || nfargs > 2,
00996                          "#-1 FUNCTION (BTWEAPONSTATUS) EXPECTS 1 OR 2 ARGUMENTS");
00997 
00998         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
00999         it = match_thing(player, fargs[0]);
01000         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01001         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01002         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01003         infostr = weaponstatus_func(mech, nfargs == 2 ? fargs[1] : NULL);
01004         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1 ERROR");
01005 }
01006 
01007 void fun_btcritstatus_ref(char *buff, char **bufc, dbref player, dbref cause,
01008                                                   char *fargs[], int nfargs, char *cargs[],
01009                                                   int ncargs)
01010 {
01011         /* fargs[0] = ref of the mech
01012          * fargs[1] = location to show
01013          */
01014         char *critstr;
01015         MECH *mech;
01016 
01017         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01018         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01019         critstr = critstatus_func(mech, fargs[1]);      /* fargs[1] unguaranteed ! */
01020         safe_tprintf_str(buff, bufc, critstr ? critstr : "#-1 ERROR");
01021 }
01022 
01023 void fun_btarmorstatus_ref(char *buff, char **bufc, dbref player, dbref cause,
01024                                                    char *fargs[], int nfargs, char *cargs[],
01025                                                    int ncargs)
01026 {
01027         /* fargs[0] = ref of the mech
01028          * fargs[1] = location to show
01029          */
01030         char *infostr;
01031         MECH *mech;
01032 
01033         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01034         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01035         infostr = armorstatus_func(mech, fargs[1]);     /* fargs[1] unguaranteed ! */
01036         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1 ERROR");
01037 }
01038 
01039 void fun_btweaponstatus_ref(char *buff, char **bufc, dbref player,
01040                                                         dbref cause, char *fargs[], int nfargs,
01041                                                         char *cargs[], int ncargs)
01042 {
01043         /* fargs[0] = ref of the mech
01044          * fargs[1] = location to show
01045          */
01046         char *infostr;
01047         MECH *mech;
01048 
01049         FUNCHECK(nfargs < 1 || nfargs > 2,
01050                          "#-1 FUNCTION (BTWEAPONREF) EXPECTS 1 OR 2 ARGUMENTS");
01051 
01052         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01053         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01054         infostr = weaponstatus_func(mech, nfargs == 2 ? fargs[1] : NULL);
01055         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1 ERROR");
01056 }
01057 
01058 void fun_btsetarmorstatus(char *buff, char **bufc, dbref player, dbref cause,
01059                                                   char *fargs[], int nfargs, char *cargs[],
01060                                                   int ncargs)
01061 {
01062         /* fargs[0] = id of the mech
01063          * fargs[1] = location to set
01064          * fargs[2] = what to change
01065          * fargs[3] = value to change to.
01066          */
01067         dbref it;
01068         char *infostr;
01069         MECH *mech;
01070 
01071         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01072         it = match_thing(player, fargs[0]);
01073         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01074         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01075         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01076         infostr = setarmorstatus_func(mech, fargs[1], fargs[2], fargs[3]);      /* fargs[1] unguaranteed ! */
01077         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1 ERROR");
01078 }
01079 
01080 void fun_btthreshold(char *buff, char **bufc, dbref player, dbref cause,
01081                                          char *fargs[], int nfargs, char *cargs[], int ncargs)
01082 {
01083         /*
01084          * fargs[0] = skill to query
01085          */
01086         int xpth;
01087 
01088         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01089         xpth = btthreshold_func(fargs[0]);
01090         safe_tprintf_str(buff, bufc, xpth < 0 ? "#%d ERROR" : "%d", xpth);
01091 }
01092 
01093 void fun_btdamagemech(char *buff, char **bufc, dbref player, dbref cause,
01094                                           char *fargs[], int nfargs, char *cargs[], int ncargs)
01095 {
01096         /*
01097          * fargs[0] = dbref of MECH object
01098          * fargs[1] = total amount of damage
01099          * fargs[2] = clustersize
01100          * fargs[3] = direction of 'attack'
01101          * fargs[4] = (try to) force crit
01102          * fargs[5] = message to send to damaged 'mech
01103          * fargs[6] = message to MechLOSBroadcast, prepended by mech name
01104          */
01105 
01106         int totaldam, clustersize, direction, iscrit;
01107         MECH *mech;
01108         dbref it;
01109 
01110         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01111         it = match_thing(player, fargs[0]);
01112         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01113         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01114         FUNCHECK(!(mech = FindObjectsData(it)), "#-1 UNABLE TO GET MECHDATA");
01115         FUNCHECK(Readnum(totaldam, fargs[1]) || totaldam < 1
01116                          || totaldam > 1000, "#-1 INVALID 2ND ARG");
01117         FUNCHECK(Readnum(clustersize, fargs[2])
01118                          || clustersize < 1, "#-1 INVALID 3RD ARG");
01119         FUNCHECK(Readnum(direction, fargs[3]), "#-1 INVALID 4TH ARG");
01120         FUNCHECK(Readnum(iscrit, fargs[4]), "#-1 INVALID 5TH ARG");
01121         safe_tprintf_str(buff, bufc, "%d", dodamage_func(player, mech,
01122                                                                                                          totaldam, clustersize,
01123                                                                                                          direction, iscrit,
01124                                                                                                          fargs[5], fargs[6]));
01125 }
01126 
01127 void fun_bttechstatus(char *buff, char **bufc, dbref player, dbref cause,
01128                                           char *fargs[], int nfargs, char *cargs[], int ncargs)
01129 {
01130         /*
01131          * fargs[0] = dbref of MECH object
01132          */
01133 
01134         dbref it;
01135         MECH *mech;
01136         char *infostr;
01137 
01138         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01139         it = match_thing(player, fargs[0]);
01140         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01141         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01142         FUNCHECK(!(mech = FindObjectsData(it)), "#-1 UNABLE TO GET MECHDATA");
01143         infostr = techstatus_func(mech);
01144         safe_tprintf_str(buff, bufc, "%s", infostr ? infostr : "#-1 ERROR");
01145 }
01146 
01147 void fun_bthexemit(char *buff, char **bufc, dbref player, dbref cause,
01148                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
01149 {
01150         /* fargs[0] = mapref
01151            fargs[1] = x coordinate
01152            fargs[2] = y coordinate
01153            fargs[3] = message
01154          */
01155         MAP *map;
01156         int x = -1, y = -1;
01157         char *msg = fargs[3];
01158         dbref mapnum;
01159 
01160         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01161 
01162         while (msg && *msg && isspace(*msg))
01163                 msg++;
01164         FUNCHECK(!msg || !*msg, "#-1 INVALID MESSAGE");
01165 
01166         mapnum = match_thing(player, fargs[0]);
01167         FUNCHECK(mapnum < 0, "#-1 INVALID MAP");
01168         map = getMap(mapnum);
01169         FUNCHECK(!map, "#-1 INVALID MAP");
01170 
01171         x = atoi(fargs[1]);
01172         y = atoi(fargs[2]);
01173         FUNCHECK(x < 0 || x > map->map_width || y < 0 || y > map->map_height,
01174                          "#-1 INVALID COORDINATES");
01175         HexLOSBroadcast(map, x, y, msg);
01176         safe_tprintf_str(buff, bufc, "1");
01177 }
01178 
01179 void fun_btmakepilotroll(char *buff, char **bufc, dbref player, dbref cause,
01180                                                  char *fargs[], int nfargs, char *cargs[], int ncargs)
01181 {
01182         /* fargs[0] = mechref
01183            fargs[1] = roll modifier
01184            fargs[2] = damage modifier
01185          */
01186 
01187         MECH *mech;
01188         int rollmod = 0, dammod = 0;
01189         dbref mechnum;
01190 
01191         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01192 
01193         mechnum = match_thing(player, fargs[0]);
01194         FUNCHECK(mechnum == NOTHING || !Examinable(player, mechnum),
01195                          "#-1 INVALID MECH");
01196         FUNCHECK(!IsMech(mechnum), "#-1 INVALID MECH");
01197         FUNCHECK(!(mech = FindObjectsData(mechnum)), "#-1 INVALID MECH");
01198 
01199         /* No checking on rollmod/dammod, they're assumed to be 0 if invalid. */
01200         rollmod = atoi(fargs[1]);
01201         dammod = atoi(fargs[2]);
01202 
01203         if(MadePilotSkillRoll(mech, rollmod)) {
01204                 safe_tprintf_str(buff, bufc, "1");
01205         } else {
01206                 MechFalls(mech, dammod, 1);
01207                 safe_tprintf_str(buff, bufc, "0");
01208         }
01209 }
01210 
01211 void fun_btid2db(char *buff, char **bufc, dbref player, dbref cause,
01212                                  char *fargs[], int nfargs, char *cargs[], int ncargs)
01213 {
01214         /* fargs[0] = mech 
01215            fargs[1] = target ID */
01216         MECH *target;
01217         MECH *mech = NULL;
01218         dbref mechnum;
01219 
01220         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01221         mechnum = match_thing(player, fargs[0]);
01222         FUNCHECK(mechnum == NOTHING || !Examinable(player, mechnum),
01223                          "#-1 INVALID MECH/MAP");
01224         FUNCHECK(strlen(fargs[1]) != 2, "#-1 INVALID TARGETID");
01225         if(IsMech(mechnum)) {
01226                 FUNCHECK(!(mech = getMech(mechnum)), "#-1 INVALID MECH");
01227                 mechnum = FindTargetDBREFFromMapNumber(mech, fargs[1]);
01228         } else if(IsMap(mechnum)) {
01229                 MAP *map;
01230                 FUNCHECK(!(map = getMap(mechnum)), "#-1 INVALID MAP");
01231                 mechnum = FindMechOnMap(map, fargs[1]);
01232         } else {
01233                 safe_str("#-1 INVALID MECH/MAP", buff, bufc);
01234                 return;
01235         }
01236         FUNCHECK(mechnum < 0, "#-1 INVALID TARGETID");
01237         if(mech) {
01238                 FUNCHECK(!(target = getMech(mechnum)), "#-1 INVALID TARGETID");
01239                 FUNCHECK(!InLineOfSight_NB(mech, target, MechX(target), MechY(target),
01240                                                                    FlMechRange(getMap(mech->mapindex), mech,
01241                                                                                            target)),
01242                                  "#-1 INVALID TARGETID");
01243         }
01244         safe_tprintf_str(buff, bufc, "#%d", (int) mechnum);
01245 }
01246 
01247 void fun_bthexlos(char *buff, char **bufc, dbref player, dbref cause,
01248                                   char *fargs[], int nfargs, char *cargs[], int ncargs)
01249 {
01250         /* fargs[0] = mech 
01251            fargs[1] = x
01252            fargs[2] = y
01253          */
01254 
01255         MECH *mech;
01256         MAP *map;
01257         int x = -1, y = -1, mechnum;
01258         float fx, fy;
01259 
01260         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01261         mechnum = match_thing(player, fargs[0]);
01262         FUNCHECK(mechnum == NOTHING || !Examinable(player, mechnum),
01263                          "#-1 INVALID MECH");
01264         FUNCHECK(!IsMech(mechnum), "#-1 INVALID MECH");
01265         FUNCHECK(!(mech = getMech(mechnum)), "#-1 INVALID MECH");
01266         FUNCHECK(!(map = getMap(mech->mapindex)), "#-1 INTERNAL ERROR");
01267 
01268         x = atoi(fargs[1]);
01269         y = atoi(fargs[2]);
01270         FUNCHECK(x < 0 || x > map->map_width || y < 0 || y > map->map_height,
01271                          "#-1 INVALID COORDINATES");
01272         MapCoordToRealCoord(x, y, &fx, &fy);
01273         if(InLineOfSight_NB(mech, NULL, x, y,
01274                                                 FindHexRange(MechFX(mech), MechFY(mech), fx, fy)))
01275                 safe_tprintf_str(buff, bufc, "1");
01276         else
01277                 safe_tprintf_str(buff, bufc, "0");
01278 }
01279 
01280 void fun_btlosm2m(char *buff, char **bufc, dbref player, dbref cause,
01281                                   char *fargs[], int nfargs, char *cargs[], int ncargs)
01282 {
01283         /* fargs[0] = mech
01284            fargs[1] = target
01285          */
01286 
01287         int mechnum;
01288         MECH *mech, *target;
01289 
01290         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01291         mechnum = match_thing(player, fargs[0]);
01292         FUNCHECK(mechnum == NOTHING || !Examinable(player, mechnum),
01293                          "#-1 INVALID MECH");
01294         FUNCHECK(!IsMech(mechnum), "#-1 INVALID MECH");
01295         FUNCHECK(!(mech = getMech(mechnum)), "#-1 INVALID MECH");
01296 
01297         mechnum = match_thing(player, fargs[1]);
01298         FUNCHECK(mechnum == NOTHING || !Examinable(player, mechnum),
01299                          "#-1 INVALID MECH");
01300         FUNCHECK(!IsMech(mechnum), "#-1 INVALID MECH");
01301         FUNCHECK(!(target = getMech(mechnum)), "#-1 INVALID MECH");
01302 
01303         if(InLineOfSight(mech, target, MechX(mech), MechY(mech),                   FlMechRange(getmap(mech->mapindex), mech, target)))
01304                 if(InLineOfSight_NB(mech, target, MechX(mech),                     MechY (mech), FlMechRange(getmap(mech->mapindex), mech,                         target)))
01305                         safe_tprintf_str(buff, bufc, "1");
01306                 else    
01307                         safe_tprintf_str(buff, bufc, "2");
01308         else
01309                 safe_tprintf_str(buff, bufc, "0");
01310 
01311 }
01312 
01313 /*
01314  * btaddstores(<MapDB>, <PartName>, <Amount>)
01315  *
01316  * Adds the specified parts/commodities to a map. The maximum value for <PartName> is the define, ADDSTORES_MAX.
01317  */
01318 void fun_btaddstores(char *buff, char **bufc, dbref player, dbref cause,
01319                                          char *fargs[], int nfargs, char *cargs[], int ncargs)
01320 {
01321         /* fargs[0] = mech/map
01322            fargs[1] = partname
01323            fargs[2] = quantity
01324          */
01325         int loc;
01326         int index = -1, id = 0, brand = 0, count;
01327 
01328         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01329 
01330         loc = match_thing(player, fargs[0]);
01331         FUNCHECK(!Good_obj(loc), "#-1 INVALID TARGET");
01332 
01333         FUNCHECK(strlen(fargs[1]) >= MBUF_SIZE, "#-1 PARTNAME TOO LONG");
01334 
01335         FUNCHECK(!fargs[1], "#-1 NEED PARTNAME");
01336 
01337         /* Add a limit to the number of parts you can add at once to prevent reaching the integer limits. */
01338         count = atoi(fargs[2]);
01339         if(count > ADDSTORES_MAX) {
01340                 count = ADDSTORES_MAX;
01341         }
01342 
01343         FUNCHECK(!count, "1");
01344         FUNCHECK(!find_matching_short_part(fargs[1], &index, &id, &brand) &&
01345                          !find_matching_vlong_part(fargs[1], &index, &id, &brand) &&
01346                          !find_matching_long_part(fargs[1], &index, &id, &brand), "0");
01347         econ_change_items(loc, id, brand, count);
01348         SendEcon(tprintf("#%d added %d %s to #%d", player, count,
01349                                          get_parts_vlong_name(id, brand), loc));
01350         safe_tprintf_str(buff, bufc, "1");
01351 }                                                               /* end btaddstores() */
01352 
01353 extern int xlate(char *);
01354 
01355 void fun_btticweaps(char *buff, char **bufc, dbref player, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)
01356 {
01357         /* fargs[0] = dbref of mech
01358          * fargs[1] = tic #
01359          */
01360 
01361         MECH *mech;
01362         dbref it;
01363         int i, j, k , l, section, critical;
01364         int ticnum;
01365         
01366         it = match_thing(player, fargs[0]);
01367         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01368         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01369         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01370         ticnum = atoi(fargs[1]);
01371 
01372         for( j = 0; j < MAX_WEAPONS_PER_MECH; j++) {
01373                 k = j / SINGLE_TICLONG_SIZE;
01374                 l = j % SINGLE_TICLONG_SIZE;
01375 
01376                 if(mech->tic[ticnum][k] & (1 << l)) {
01377                         if(FindWeaponNumberOnMech(mech, j, &section, &critical) == -1) {
01378                                 j = MAX_WEAPONS_PER_MECH ;
01379                                 continue;
01380                         }
01381                         safe_tprintf_str(buff,bufc,tprintf("%d:%s ",j,&MechWeapons[Weapon2I(GetPartType(mech, section, critical))].name[3]));
01382                 }
01383         }
01384         
01385 
01386 }
01387 void fun_btloadmap(char *buff, char **bufc, dbref player, dbref cause,
01388                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
01389 {
01390         /* fargs[0] = mapobject
01391            fargs[1] = mapname
01392            fargs[2] = clear or not to clear
01393          */
01394         int mapdbref;
01395         MAP *map;
01396 
01397         FUNCHECK(nfargs < 2 || nfargs > 3,
01398                          "#-1 BTLOADMAP TAKES 2 OR 3 ARGUMENTS");
01399         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01400         mapdbref = match_thing(player, fargs[0]);
01401         FUNCHECK(!Good_obj(mapdbref), "#-1 INVALID TARGET");
01402         map = getMap(mapdbref);
01403         FUNCHECK(!map, "#-1 INVALID TARGET");
01404         switch (map_load(map, fargs[1])) {
01405         case -1:
01406                 safe_str("#-1 MAP NOT FOUND", buff, bufc);
01407                 return;
01408         case -2:
01409                 safe_str("#-1 INVALID MAP", buff, bufc);
01410                 return;
01411         case 0:
01412                 break;
01413         default:
01414                 safe_str("#-1 UNKNOWN ERROR", buff, bufc);
01415                 return;
01416         }
01417 /* For now, we're gonna ignore the third arg, and just clear mechs anyways*/
01418 /*      if(nfargs > 2 && xlate(fargs[2])) */
01419                 map_clearmechs(player, (void *) map, "");
01420         safe_str("1", buff, bufc);
01421 }
01422 
01423 void fun_btloadmech(char *buff, char **bufc, dbref player, dbref cause,
01424                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
01425 {
01426         /* fargs[0] = mechobject
01427            fargs[1] = mechref
01428          */
01429         int mechdbref;
01430         MECH *mech;
01431 
01432         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01433         mechdbref = match_thing(player, fargs[0]);
01434         FUNCHECK(!Good_obj(mechdbref), "#-1 INVALID TARGET");
01435         mech = getMech(mechdbref);
01436         FUNCHECK(!mech, "#-1 INVALID TARGET");
01437         if(mech_loadnew(player, mech, fargs[1]) == 1) {
01438                 muxevent_remove_data((void *) mech);
01439                 clear_mech_from_LOS(mech);
01440                 safe_str("1", buff, bufc);
01441         } else {
01442                 safe_str("#-1 UNABLE TO LOAD TEMPLATE", buff, bufc);
01443         }
01444 }
01445 
01446 extern char radio_colorstr[];
01447 
01448 void fun_btmechfreqs(char *buff, char **bufc, dbref player, dbref cause,
01449                                          char *fargs[], int nfargs, char *cargs[], int ncargs)
01450 {
01451         /* fargs[0] = mechobject
01452          */
01453         int mechdbref;
01454         MECH *mech;
01455         int i;
01456 
01457         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01458         mechdbref = match_thing(player, fargs[0]);
01459         FUNCHECK(!Good_obj(mechdbref), "#-1 INVALID TARGET");
01460         mech = getMech(mechdbref);
01461         FUNCHECK(!mech, "#-1 INVALID TARGET");
01462 
01463         for(i = 0; i < MFreqs(mech); i++) {
01464                 if(i)
01465                         safe_str(",", buff, bufc);
01466                 safe_tprintf_str(buff, bufc, "%d|%d|%s",
01467                                                  i + 1, mech->freq[i],
01468                                                  bv2text(mech->freqmodes[i] % FREQ_REST));
01469                 if(mech->freqmodes[i] / FREQ_REST) {
01470                         safe_tprintf_str(buff, bufc, "|%c",
01471                                                          radio_colorstr[mech->freqmodes[i] / FREQ_REST -
01472                                                                                         1]);
01473                 } else {
01474                         safe_str("|-", buff, bufc);
01475                 }
01476         }
01477 }
01478 
01479 void fun_btgetweight(char *buff, char **bufc, dbref player, dbref cause,
01480                                          char *fargs[], int nfargs, char *cargs[], int ncargs)
01481 {
01482         /*
01483            fargs[0] = stringname of part
01484          */
01485         float sw = 0;
01486         int i = -1, p, b;
01487 
01488         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01489 
01490         if(!find_matching_long_part(fargs[0], &i, &p, &b)) {
01491                 i = -1;
01492                 FUNCHECK(!find_matching_vlong_part(fargs[0], &i, &p, &b),
01493                                  "#-1 INVALID PART NAME");
01494         }
01495         sw = GetPartWeight(p);
01496         if(sw <= 0)
01497                 sw = (1024 * 100);
01498         safe_tprintf_str(buff, bufc, tprintf("%.3f", (float) sw / 1024));
01499 }
01500 
01501 void fun_btremovestores(char *buff, char **bufc, dbref player, dbref cause,
01502                                                 char *fargs[], int nfargs, char *cargs[], int ncargs)
01503 {
01504         /* fargs[0] = id of the bay */
01505         /* fargs[1] = name of the part */
01506         /* fargs[2] = amount */
01507         dbref it;
01508         int i = -1, spec;
01509         int num = 0;
01510         void *foo;
01511         int p, b;
01512 
01513         it = match_thing(player, fargs[0]);
01514         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
01515         spec = WhichSpecial(it);
01516         FUNCHECK(!(foo = FindObjectsData(it)), "#-1");
01517         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01518         FUNCHECK(Readnum(num, fargs[2]), "#-2 Illegal Value");
01519         if(!find_matching_long_part(fargs[1], &i, &p, &b)) {
01520                 i = -1;
01521                 FUNCHECK(!find_matching_vlong_part(fargs[1], &i, &p, &b),
01522                                  "#-1 INVALID PART NAME");
01523         }
01524         econ_change_items(it, p, b, 0 - num);
01525         safe_tprintf_str(buff, bufc, "%d", econ_find_items(it, p, b));
01526 }
01527 
01528 void fun_bttechtime(char *buff, char **bufc, dbref player, dbref cause,
01529                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
01530 {
01531         time_t old;
01532         char *olds = silly_atr_get(player, A_TECHTIME);
01533         char buf[MBUF_SIZE];
01534 
01535         if(olds) {
01536                 old = (time_t) atoi(olds);
01537                 if(old < mudstate.now) {
01538                         strcpy(buf, "00:00.00");
01539                 } else {
01540                         old -= mudstate.now;
01541                         sprintf(buf, "%02ld:%02d.%02d", (long) (old / 3600),
01542                                         (int) ((old / 60) % 60), (int) (old % 60));
01543                 }
01544         } else {
01545                 strcpy(buf, "00:00.00");
01546         }
01547 
01548         notify(player, buf);
01549 }
01550 
01551 void fun_btcritslot(char *buff, char **bufc, dbref player, dbref cause,
01552                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
01553 {
01554         /* fargs[0] = id of the mech
01555            fargs[1] = location name
01556            fargs[2] = critslot
01557            fargs[3] = partname type flag, 0 template name, 1 repair part name (differentiate Ammo types basically)
01558          */
01559         dbref it;
01560         MECH *mech;
01561 
01562         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01563 
01564         if(!fn_range_check("BTCRITSLOT", nfargs, 3, 4, buff, bufc))
01565                 return;
01566 
01567         it = match_thing(player, fargs[0]);
01568         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01569         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01570         FUNCHECK(!(mech = FindObjectsData(it)), "#-1 INVALID MECH");
01571 
01572         safe_tprintf_str(buff, bufc, "%s",
01573                                          critslot_func(mech, fargs[1], fargs[2], fargs[3]));
01574 }
01575 
01576 void fun_btcritslot_ref(char *buff, char **bufc, dbref player, dbref cause,
01577                                                 char *fargs[], int nfargs, char *cargs[], int ncargs)
01578 {
01579         /* fargs[0] = ref
01580            fargs[1] = location name
01581            fargs[2] = critslot
01582            fargs[3] = partname type flag, 0 template name, 1 repair part name (differentiate Ammo types basically)
01583          */
01584         MECH *mech;
01585 
01586         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01587 
01588         if(!fn_range_check("BTCRITSLOT_REF", nfargs, 3, 4, buff, bufc))
01589                 return;
01590         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01591 
01592         safe_tprintf_str(buff, bufc, "%s",
01593                                          critslot_func(mech, fargs[1], fargs[2], fargs[3]));
01594 }
01595 
01596 #define NUMBERS ".0123456789"
01597 
01598 void fun_btgetrange(char *buff, char **bufc, dbref player, dbref cause,
01599                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
01600 {
01601 /* fargs[0] - [4] Combos of XY or DBref */
01602         dbref mechAdb, mechBdb, mapdb;
01603         MECH *mechA, *mechB;
01604         MAP *map;
01605         float fxA, fyA, fzA, fxB, fyB, fzB;
01606         int xA, yA, zA, xB, yB, zB;
01607 
01608         FUNCHECK(!WizR(player), "#=1 PERMISSION DENIED");
01609 
01610         if(!fn_range_check("BTGETRANGE", nfargs, 3, 7, buff, bufc))
01611                 return;
01612 
01613         mapdb = match_thing(player, fargs[0]);
01614         FUNCHECK(mapdb == NOTHING
01615                          || !Examinable(player, mapdb), "#-1 INVALID MAPDB");
01616         FUNCHECK(!IsMap(mapdb), "#-1 OBJECT NOT MAP");
01617         FUNCHECK(!(map = getMap(mapdb)), "#-1 INVALID MAP");
01618 
01619         switch (nfargs) {
01620         case 3:
01621                 mechAdb = match_thing(player, fargs[1]);
01622                 FUNCHECK(mechAdb == NOTHING
01623                                  || !Examinable(player, mechAdb), "#-1 INVALID MECHDBREF");
01624                 mechBdb = match_thing(player, fargs[2]);
01625                 FUNCHECK(mechBdb == NOTHING
01626                                  || !Examinable(player, mechBdb), "#-1 INVALID MECHDBREF");
01627                 FUNCHECK(!IsMech(mechAdb) || !IsMech(mechBdb), "#-1 INVALID MECH");
01628                 FUNCHECK(!(mechA = getMech(mechAdb))
01629                                  || !(mechB = getMech(mechBdb)), "#-1 INVALID MECH");
01630                 FUNCHECK(mechA->mapindex != mapdb
01631                                  || mechB->mapindex != mapdb, "#-1 MECH NOT ON MAP");
01632                 safe_tprintf_str(buff, bufc, "%f", FaMechRange(mechA, mechB));
01633                 return;
01634         case 4:
01635                 if(strspn(fargs[1], NUMBERS) < 1) {
01636                         mechAdb = match_thing(player, fargs[1]);
01637                         FUNCHECK(strspn(fargs[2], NUMBERS) < 1, "#-1 INVALID COORDS");
01638                         xA = atoi(fargs[2]);
01639                         FUNCHECK(strspn(fargs[3], NUMBERS) < 1, "#-1 INVALID COORDS");
01640                         yA = atoi(fargs[3]);
01641                 } else {
01642                         FUNCHECK(strspn(fargs[1], NUMBERS) < 1, "#-1 INVALID COORDS");
01643                         xA = atoi(fargs[1]);
01644                         FUNCHECK(strspn(fargs[2], NUMBERS) < 1, "#-1 INVALID COORDS");
01645                         yA = atoi(fargs[2]);
01646                         mechAdb = match_thing(player, fargs[3]);
01647                 }
01648                 FUNCHECK(mechAdb == NOTHING
01649                                  || !Examinable(player, mechAdb), "#-1 INVALID MECHDBREF");
01650                 FUNCHECK(!IsMech(mechAdb), "#-1 INVALID MECH");
01651                 FUNCHECK(!(mechA = getMech(mechAdb)), "#-1 INVALID MECH");
01652                 FUNCHECK(mechA->mapindex != mapdb, "#-1 MECH NOT ON MAP");
01653                 FUNCHECK(xA < 0 || yA < 0 || xA > map->map_width
01654                                  || yA > map->map_height, "#-1 INVALID COORDS");
01655                 MapCoordToRealCoord(xA, yA, &fxA, &fyA);
01656                 safe_tprintf_str(buff, bufc, "%f",
01657                                                  FindRange(MechFX(mechA), MechFY(mechA),
01658                                                                    MechFZ(mechA), fxA, fyA, Elevation(map, xA,
01659                                                                                                                                           yA) *
01660                                                                    ZSCALE));
01661                 return;
01662         case 5:
01663                 if(strspn(fargs[1], NUMBERS) < 1 || strspn(fargs[4], NUMBERS) < 1) {
01664                         // this is the (map, mech, x, y, z) or (map, x, y, z, mech) condition
01665                         if(strspn(fargs[1], NUMBERS) < 1) {
01666                                 // mech first
01667                                 mechAdb = match_thing(player, fargs[1]);
01668                                 FUNCHECK(strspn(fargs[2], NUMBERS) < 1, "#-1 INVALID COORDS");
01669                                 xA = atoi(fargs[2]);
01670                                 FUNCHECK(strspn(fargs[3], NUMBERS) < 1, "#-1 INVALID COORDS");
01671                                 yA = atoi(fargs[3]);
01672                                 FUNCHECK(strspn(fargs[4], NUMBERS) < 1, "#-1 INVALID COORDS");
01673                                 zA = atoi(fargs[4]);
01674                         } else {
01675                                 FUNCHECK(strspn(fargs[1], NUMBERS) < 1, "#-1 INVALID COORDS");
01676                                 xA = atoi(fargs[1]);
01677                                 FUNCHECK(strspn(fargs[2], NUMBERS) < 1, "#-1 INVALID COORDS");
01678                                 yA = atoi(fargs[2]);
01679                                 FUNCHECK(strspn(fargs[3], NUMBERS) < 1, "#-1 INVALID COORDS");
01680                                 zA = atoi(fargs[3]);
01681                                 mechAdb = match_thing(player, fargs[4]);
01682                         }
01683                         FUNCHECK(mechAdb == NOTHING
01684                                          || !Examinable(player, mechAdb),
01685                                          "#-1 INVALID MECHDBREF");
01686                         FUNCHECK(!IsMech(mechAdb), "#-1 INVALID MECH");
01687                         FUNCHECK(!(mechA = getMech(mechAdb)), "#-1 INVALID MECH");
01688                         FUNCHECK(mechA->mapindex != mapdb, "#-1 MECH NOT ON MAP");
01689                         FUNCHECK(xA < 0 || yA < 0 || xA > map->map_width
01690                                          || yA > map->map_height, "#-1 INVALID COORDS");
01691                         MapCoordToRealCoord(xA, yA, &fxA, &fyA);
01692                         safe_tprintf_str(buff, bufc, "%f",
01693                                                          FindRange(MechFX(mechA), MechFY(mechA),
01694                                                                            MechFZ(mechA), fxA, fyA, zA * ZSCALE));
01695                         return;
01696                 }
01697                 // tihs is the (map, x1, y1, x2, y2) condition
01698                 FUNCHECK(strspn(fargs[1], NUMBERS) < 1, "#-1 INVALID COORDS");
01699                 xA = atoi(fargs[1]);
01700                 FUNCHECK(strspn(fargs[2], NUMBERS) < 1, "#-1 INVALID COORDS");
01701                 yA = atoi(fargs[2]);
01702                 FUNCHECK(xA < 0 || yA < 0 || xA > map->map_width
01703                                  || yA > map->map_height, "#-1 INVALID COORDS");
01704                 FUNCHECK(strspn(fargs[3], NUMBERS) < 1, "#-1 INVALID COORDS");
01705                 xB = atoi(fargs[3]);
01706                 FUNCHECK(strspn(fargs[4], NUMBERS) < 1, "#-1 INVALID COORDS");
01707                 yB = atoi(fargs[4]);
01708                 FUNCHECK(xB < 0 || yB < 0 || xB > map->map_width
01709                                  || yB > map->map_height, "#-1 INVALID COORDS");
01710                 MapCoordToRealCoord(xA, yA, &fxA, &fyA);
01711                 MapCoordToRealCoord(xB, yB, &fxB, &fyB);
01712                 safe_tprintf_str(buff, bufc, "%f",
01713                                                  FindRange(fxA, fyA, Elevation(map, xA, yA) * ZSCALE,
01714                                                                    fxB, fyB, Elevation(map, xB, yB)));
01715                 return;
01716         case 7:
01717                 FUNCHECK(strspn(fargs[1], NUMBERS) < 1, "#-1 INVALID COORDS");
01718                 xA = atoi(fargs[1]);
01719                 FUNCHECK(strspn(fargs[2], NUMBERS) < 1, "#-1 INVALID COORDS");
01720                 yA = atoi(fargs[2]);
01721                 FUNCHECK(strspn(fargs[3], NUMBERS) < 1, "#-1 INVALID COORDS");
01722                 zA = atoi(fargs[3]);
01723                 FUNCHECK(strspn(fargs[4], NUMBERS) < 1, "#-1 INVALID COORDS");
01724                 xB = atoi(fargs[4]);
01725                 FUNCHECK(strspn(fargs[5], NUMBERS) < 1, "#-1 INVALID COORDS");
01726                 yB = atoi(fargs[5]);
01727                 FUNCHECK(strspn(fargs[6], NUMBERS) < 1, "#-1 INVALID COORDS");
01728                 zB = atoi(fargs[6]);
01729                 MapCoordToRealCoord(xA, yA, &fxA, &fyA);
01730                 MapCoordToRealCoord(xB, yB, &fxB, &fyB);
01731                 safe_tprintf_str(buff, bufc, "%f",
01732                                                  FindRange(fxA, fyA, zA * ZSCALE, fxB, fyB,
01733                                                                    zB * ZSCALE));
01734                 return;
01735         default:
01736                 safe_tprintf_str(buff, bufc, "#-1 INVALID ARGUMENTS");
01737                 return;
01738         }
01739 }
01740 
01741 extern void correct_speed(MECH *);
01742 
01743 void fun_btsetmaxspeed(char *buff, char **bufc, dbref player, dbref cause,
01744                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
01745 {
01746         /* fargs[0] = id of the mech
01747            fargs[1] = what the new maxspeed should be set too
01748          */
01749         dbref it;
01750         MECH *mech;
01751         float newmaxspeed = atof(fargs[1]);
01752 
01753         it = match_thing(player, fargs[0]);
01754         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01755         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01756         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01757         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01758 
01759         MechMaxSpeed(mech) = newmaxspeed;
01760         correct_speed(mech);
01761 
01762         safe_tprintf_str(buff, bufc, "1");
01763 }
01764 
01765 void fun_btgetrealmaxspeed(char *buff, char **bufc, dbref player, dbref cause,
01766                                                    char *fargs[], int nfargs, char *cargs[],
01767                                                    int ncargs)
01768 {
01769         dbref it;
01770         MECH *mech;
01771         float speed;
01772 
01773         it = match_thing(player, fargs[0]);
01774         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01775         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01776         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01777         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01778 
01779         speed = MechCargoMaxSpeed(mech, MechMaxSpeed(mech));
01780 
01781         safe_tprintf_str(buff, bufc, tprintf("%f", speed));
01782 }
01783 
01784 void fun_btgetbv(char *buff, char **bufc, dbref player, dbref cause,
01785                                  char *fargs[], int nfargs, char *cargs[], int ncargs)
01786 {
01787         dbref it;
01788         MECH *mech;
01789         int bv;
01790 
01791         it = match_thing(player, fargs[0]);
01792         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01793         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01794         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01795         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01796 
01797         bv = CalculateBV(mech, 100, 100);
01798         MechBV(mech) = bv;
01799         safe_tprintf_str(buff, bufc, tprintf("%d", bv));
01800 }
01801 
01802 void fun_btgetbv_ref(char *buff, char **bufc, dbref player, dbref cause,
01803                                          char *fargs[], int nfargs, char *cargs[], int ncargs)
01804 {
01805         MECH *mech;
01806         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01807         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01808 
01809         MechBV(mech) = CalculateBV(mech, 4, 5);
01810         safe_tprintf_str(buff, bufc, "%d", MechBV(mech));
01811 }
01812 
01813 void fun_bttechlist(char *buff, char **bufc, dbref player, dbref cause,
01814                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
01815 {
01816         dbref it;
01817         MECH *mech;
01818         int i, ii, part = 0, axe = 0, sword = 0, mace = 0, hascase = 0;
01819         char *infostr;
01820 
01821         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01822         it = match_thing(player, fargs[0]);
01823         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1 NOT A MECH");
01824         FUNCHECK(!IsMech(it), "#-1 NOT A MECH");
01825         FUNCHECK(!(mech = FindObjectsData(it)), "#-1");
01826         infostr = techlist_func(mech);
01827         safe_tprintf_str(buff, bufc, infostr ? infostr : " ");
01828 }
01829 
01830 void fun_bttechlist_ref(char *buff, char **bufc, dbref player, dbref cause,
01831                                                 char *fargs[], int nfargs, char *cargs[], int ncargs)
01832 {
01833         dbref it;
01834         MECH *mech;
01835         int i, ii, part = 0, axe = 0, sword = 0, mace = 0, hascase = 0;
01836         char *infostr;
01837 
01838         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01839         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01840 
01841         infostr = techlist_func(mech);
01842         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1");
01843 }
01844 
01845 /* Function to return the 'payload' of a unit
01846  * ie: the Guns and Ammo
01847  * in a list format like <item_1> <# of 1>|...|<item_n> <# of n>
01848  * Dany - 06/2005 */
01849 void fun_btpayload_ref(char *buff, char **bufc, dbref player, dbref cause,
01850                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
01851 {
01852         MECH *mech;
01853         char *infostr;
01854 
01855         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01856         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01857 
01858         infostr = payloadlist_func(mech);
01859         safe_tprintf_str(buff, bufc, infostr ? infostr : "#-1");
01860 }
01861 
01862 void fun_btshowstatus_ref(char *buff, char **bufc, dbref player, dbref cause,
01863                                                   char *fargs[], int nfargs, char *cargs[],
01864                                                   int ncargs)
01865 {
01866         dbref outplayer;
01867         MECH *mech;
01868         char *infostr;
01869 
01870         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01871         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01872         outplayer = match_thing(player, fargs[1]);
01873         FUNCHECK(outplayer == NOTHING || !Examinable(player, outplayer)
01874                          || !isPlayer(outplayer), "#-1");
01875 
01876         mech_status(outplayer, (void *) mech, "R");
01877         safe_tprintf_str(buff, bufc, "1");
01878 }
01879 
01880 void fun_btshowwspecs_ref(char *buff, char **bufc, dbref player, dbref cause,
01881                                                   char *fargs[], int nfargs, char *cargs[],
01882                                                   int ncargs)
01883 {
01884         dbref outplayer;
01885         MECH *mech;
01886         char *infostr;
01887 
01888         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01889         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01890         outplayer = match_thing(player, fargs[1]);
01891         FUNCHECK(outplayer == NOTHING || !Examinable(player, outplayer)
01892                          || !isPlayer(outplayer), "#-1");
01893 
01894         mech_weaponspecs(outplayer, (void *) mech, "");
01895         safe_tprintf_str(buff, bufc, "1");
01896 }
01897 
01898 void fun_btshowcritstatus_ref(char *buff, char **bufc, dbref player,
01899                                                           dbref cause, char *fargs[], int nfargs,
01900                                                           char *cargs[], int ncargs)
01901 {
01902         dbref outplayer;
01903         MECH *mech;
01904         char *infostr;
01905 
01906         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01907         FUNCHECK((mech = load_refmech(fargs[0])) == NULL, "#-1 NO SUCH MECH");
01908         outplayer = match_thing(player, fargs[1]);
01909         FUNCHECK(outplayer == NOTHING || !Examinable(player, outplayer)
01910                          || !isPlayer(outplayer), "#-1");
01911 
01912         mech_critstatus(outplayer, (void *) mech, fargs[2]);
01913         safe_tprintf_str(buff, bufc, "1");
01914 }
01915 
01916 void fun_btengrate(char *buff, char **bufc, dbref player, dbref cause,
01917                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
01918 {
01919         dbref mechdb;
01920         MECH *mech;
01921 
01922         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01923         mechdb = match_thing(player, fargs[0]);
01924         FUNCHECK(mechdb == NOTHING
01925                          || !Examinable(player, mechdb), "#-1 NOT A MECH");
01926         FUNCHECK(!IsMech(mechdb), "#-1 NOT A MECH");
01927         FUNCHECK(!(mech = getMech(mechdb)), "#-1");
01928 
01929         safe_tprintf_str(buff, bufc, "%d %d", MechEngineSize(mech),
01930                                          susp_factor(mech));
01931 }
01932 
01933 void fun_btengrate_ref(char *buff, char **bufc, dbref player, dbref cause,
01934                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
01935 {
01936         MECH *mech;
01937 
01938         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01939         FUNCHECK(!(mech = load_refmech(fargs[0])), "#-1 INVALID REF");
01940 
01941         safe_tprintf_str(buff, bufc, "%d %d", MechEngineSize(mech),
01942                                          susp_factor(mech));
01943 }
01944 
01945 void fun_btfasabasecost_ref(char *buff, char **bufc, dbref player,
01946                                                         dbref cause, char *fargs[], int nfargs,
01947                                                         char *cargs[], int ncargs)
01948 {
01949 #ifdef BT_ADVANCED_ECON
01950         MECH *mech;
01951 
01952         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01953         FUNCHECK(!(mech = load_refmech(fargs[0])), "#-1 INVALID REF");
01954 
01955         safe_tprintf_str(buff, bufc, "%lld", CalcFasaCost(mech));
01956 #else
01957         safe_tprintf_str(buff, bufc, "#-1 NO ECONDB SUPPORT");
01958 #endif
01959 }
01960 
01961 void fun_btweapstat(char *buff, char **bufc, dbref player, dbref cause,
01962                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
01963 {
01964         /* fargs[0] = weapon name
01965          * fargs[1] = stat type
01966          */
01967 
01968         int i = -1, p, weapindx, val = -1, b;
01969 
01970         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
01971 
01972         if(!find_matching_long_part(fargs[0], &i, &p, &b)) {
01973                 i = -1;
01974                 FUNCHECK(!find_matching_vlong_part(fargs[0], &i, &p, &b),
01975                                  "#-1 INVALID PART NAME");
01976         }
01977         if(!IsWeapon(p)) {
01978                 safe_tprintf_str(buff, bufc, "#-1 NOT A WEAPON");
01979                 return;
01980         }
01981         weapindx = Weapon2I(p);
01982         if(strcasecmp("VRT", fargs[1]) == 0)
01983                 val = MechWeapons[weapindx].vrt;
01984         else if(strcasecmp("TYPE", fargs[1]) == 0)
01985                 val = MechWeapons[weapindx].type;
01986         else if(strcasecmp("HEAT", fargs[1]) == 0)
01987                 val = MechWeapons[weapindx].heat;
01988         else if(strcasecmp("DAMAGE", fargs[1]) == 0)
01989                 val = MechWeapons[weapindx].damage;
01990         else if(strcasecmp("MIN", fargs[1]) == 0)
01991                 val = MechWeapons[weapindx].min;
01992         else if(strcasecmp("SR", fargs[1]) == 0)
01993                 val = MechWeapons[weapindx].shortrange;
01994         else if(strcasecmp("MR", fargs[1]) == 0)
01995                 val = MechWeapons[weapindx].medrange;
01996         else if(strcasecmp("LR", fargs[1]) == 0)
01997                 val = MechWeapons[weapindx].longrange;
01998         else if(strcasecmp("CRIT", fargs[1]) == 0)
01999                 val = MechWeapons[weapindx].criticals;
02000         else if(strcasecmp("AMMO", fargs[1]) == 0)
02001                 val = MechWeapons[weapindx].ammoperton;
02002         else if(strcasecmp("WEIGHT", fargs[1]) == 0)
02003                 val = MechWeapons[weapindx].weight;
02004         else if(strcasecmp("BV", fargs[1]) == 0)
02005                 val = MechWeapons[weapindx].battlevalue;
02006 #if 0
02007         else if(strcasecmp("ABV", fargs[1]) == 0)
02008                 val = MechWeapons[weapindx].abattlevalue;
02009         else if(strcasecmp("REP", fargs[1]) == 0)
02010                 val = MechWeapons[weapindx].reptime;
02011         else if(strcasecmp("WCLASS", fargs[1]) == 0)
02012                 val = MechWeapons[weapindx].class;
02013 #endif
02014         if(val == -1)
02015                 safe_tprintf_str(buff, bufc, "#-1");
02016         safe_tprintf_str(buff, bufc, "%d", val);
02017 }
02018 
02019 void fun_btnumrepjobs(char *buff, char **bufc, dbref player, dbref cause,
02020                                           char *fargs[], int nfargs, char *cargs[], int ncargs)
02021 {
02022         extern int damage_last;
02023         MECH *mech;
02024         dbref it;
02025 
02026         it = match_thing(player, fargs[0]);
02027         FUNCHECK(it == NOTHING || !Examinable(player, it), "#-1");
02028         FUNCHECK(!IsMech(it), "#-2");
02029         mech = FindObjectsData(it);
02030 
02031         if(unit_is_fixable(mech))
02032                 make_damage_table(mech);
02033         else
02034                 make_scrap_table(mech);
02035 
02036         safe_tprintf_str(buff, bufc, "%d", damage_last);
02037 }
02038 
02039 void fun_btsetxy(char *buff, char **bufc, dbref player, dbref cause,
02040                                  char *fargs[], int nfargs, char *cargs[], int ncargs)
02041 {
02042         /*
02043            fargs[0] = mech
02044            fargs[1] = map
02045            fargs[2] = x
02046            fargs[3] = y
02047            fargs[4] = z
02048 
02049          */
02050         dbref mechdb, mapdb;
02051         int x, y, z;
02052         MECH *mech;
02053     MECH *towee = NULL;
02054         MAP *map;
02055         char buffer[MBUF_SIZE];
02056 
02057         FUNCHECK(nfargs < 4 || nfargs > 5, "#-1 INVALID ARGUMENT");
02058         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02059         mechdb = match_thing(player, fargs[0]);
02060         FUNCHECK(!Good_obj(mechdb), "#-1 INVALID TARGET");
02061         mech = getMech(mechdb);
02062         FUNCHECK(!mech, "#-1 INVALID TARGET");
02063 
02064         mapdb = match_thing(player, fargs[1]);
02065         FUNCHECK(mapdb == NOTHING
02066                          || !Examinable(player, mapdb), "#-1 INVALID MAP");
02067         FUNCHECK(!IsMap(mapdb), "#-1 INVALID MAP");
02068         FUNCHECK(!(map = getMap(mapdb)), "#-1 INVALID MAP");
02069 
02070         x = atoi(fargs[2]);
02071         y = atoi(fargs[3]);
02072         FUNCHECK(x < 0 || x > map->map_width, "#-1 X COORD");
02073         FUNCHECK(y < 0 || y > map->map_height, "#-1 Y COORD");
02074 
02075         if(nfargs == 5) {
02076                 z = atoi(fargs[4]);
02077                 FUNCHECK(z < 0 || z > 10000, "#-1 Z COORD");
02078         }
02079 
02080     if (MechCarrying(mech) > 0)
02081         towee = getMech(MechCarrying(mech));
02082 
02083         snprintf(buffer, MBUF_SIZE, "%d", mapdb);
02084         mech_Rsetmapindex(GOD, (void *) mech, buffer);
02085 
02086     if (towee)
02087         mech_Rsetmapindex(GOD, (void *) towee, buffer);
02088 
02089         if(nfargs == 5) {
02090                 snprintf(buffer, MBUF_SIZE, "%d %d %d", x, y, z);
02091         } else {
02092                 snprintf(buffer, MBUF_SIZE, "%d %d", x, y);
02093         }
02094         mech_Rsetxy(GOD, (void *) mech, buffer);
02095 
02096     if (towee)
02097         mech_Rsetxy(GOD, (void *) towee, buffer);
02098 
02099         safe_tprintf_str(buff, bufc, "1");
02100 }
02101 
02102 void fun_btmapunits(char *buff, char **bufc, dbref player, dbref cause,
02103                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
02104 {
02105         /*
02106          * fargs[0] = mapref
02107          *
02108          * OR
02109          *
02110          * fargs[0] = mapref
02111          * fargs[1] = x
02112          * fargs[2] = y
02113          * fargs[3] = range
02114          *
02115          * OR
02116          *
02117          * fargs[0] = mapref
02118          * fargs[1] = x
02119          * fargs[2] = y
02120          * fargs[3] = z
02121          * fargs[4] = range
02122          */
02123 
02124         MAP *map;
02125         float x, y, z, range, realX, realY;
02126         MECH *mech;
02127         int loop;
02128         dbref mapnum;
02129 
02130         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02131 
02132         switch (nfargs) {
02133                 case 1:
02134                         mapnum = match_thing(player, fargs[0]);
02135                         FUNCHECK(mapnum < 0, "#-1 INVALID MAP");
02136                         map = getMap(mapnum);
02137                         FUNCHECK(!map, "#-1 INVALID MAP");
02138                         for(loop = 0; loop < map->first_free; loop++) {
02139                                 if(map->mechsOnMap[loop] < 0)
02140                                         continue;
02141                                 mech = getMech(map->mechsOnMap[loop]);
02142 
02143                                 if(mech)
02144                                         safe_tprintf_str(buff, bufc, "#%d ", map->mechsOnMap[loop]);
02145                         }
02146                         break;
02147                 case 4:
02148                         mapnum = match_thing(player, fargs[0]);
02149                         FUNCHECK(mapnum < 0, "#-1 INVALID MAP");
02150                         map = getMap(mapnum);
02151                         FUNCHECK(!map, "#-1 INVALID MAP");
02152                         x = atof(fargs[1]);
02153                         y = atof(fargs[2]);
02154                         range = atof(fargs[3]);
02155                         FUNCHECK(x < 0 || x > map->map_width, "#-1 INVALID X COORD");
02156                         FUNCHECK(y < 0 || y > map->map_height, "#-1 INVALID Y COORD");
02157                         FUNCHECK(range < 0, "#-1 INVALID RANGE");
02158                         MapCoordToRealCoord(x, y, &realX, &realY);
02159                         for(loop = 0; loop < map->first_free; loop++) {
02160                                 if(map->mechsOnMap[loop] < 0)
02161                                         continue;
02162                                 mech = getMech(map->mechsOnMap[loop]);
02163                                 if(mech
02164                                                 && FindXYRange(realX, realY, MechFX(mech),
02165                                                         MechFY(mech)) <= range)
02166                                         safe_tprintf_str(buff, bufc, "#%d ", map->mechsOnMap[loop]);
02167                         }
02168                         break;
02169                 case 5:
02170                         mapnum = match_thing(player, fargs[0]);
02171                         FUNCHECK(mapnum < 0, "#-1 INVALID MAP");
02172                         map = getMap(mapnum);
02173                         FUNCHECK(!map, "#-1 INVALID MAP");
02174                         x = atof(fargs[1]);
02175                         y = atof(fargs[2]);
02176                         z = atof(fargs[3]);
02177                         range = atof(fargs[4]);
02178                         FUNCHECK(x < 0 || x > map->map_width, "#-1 INVALID X COORD");
02179                         FUNCHECK(y < 0 || y > map->map_height, "#-1 INVALID Y COORD");
02180                         FUNCHECK(range < 0, "#-1 INVALID RANGE");
02181                         MapCoordToRealCoord(x, y, &realX, &realY);
02182                         for(loop = 0; loop < map->first_free; loop++) {
02183                                 if(map->mechsOnMap[loop] < 0)
02184                                         continue;
02185                                 mech = getMech(map->mechsOnMap[loop]);
02186 
02187                                 if(mech
02188                                                 && FindRange(realX, realY, z * ZSCALE, MechFX(mech),
02189                                                         MechFY(mech), MechFZ(mech)) <= range)
02190                                         safe_tprintf_str(buff, bufc, "#%d ", map->mechsOnMap[loop]);
02191                         }
02192                         break;
02193                 default:
02194                         safe_tprintf_str(buff, bufc, "#-1 INVALID ARGUMENTS");
02195                         break;
02196         }
02197 
02198         return;
02199 }
02200 
02201 int MapLimitedBroadcast3d(MAP * map, float x, float y, float z, float range,
02202                                                   char *message);
02203 int MapLimitedBroadcast2d(MAP * map, float x, float y, float range,
02204                                                   char *message);
02205 
02206 void fun_btmapemit(char *buff, char **bufc, dbref player, dbref cause,
02207                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
02208 {
02209         /* fargs[0] = mapref
02210            fargs[1] = message
02211 
02212            OR
02213 
02214            fargs[0] = mapref
02215            fargs[1] = x
02216            fargs[2] = y
02217            fargs[3] = range
02218            fargs[4] = message
02219 
02220            OR
02221 
02222            fargs[0] = mapref
02223            fargs[1] = x
02224            fargs[2] = y
02225            fargs[3] = z
02226            fargs[4] = range
02227            fargs[5] = message
02228 
02229          */
02230 
02231         MAP *map;
02232         dbref mapnum;
02233         float x, y, realX, realY, z, range;
02234 
02235         FUNCHECK(nfargs < 2, "#-1 TOO FEW ARGUMENTS");
02236         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02237         mapnum = match_thing(player, fargs[0]);
02238         FUNCHECK(mapnum < 0, "#-1 INVALID MAP");
02239         map = getMap(mapnum);
02240         FUNCHECK(!map, "#-1 INVALID MAP");
02241 
02242         switch (nfargs) {
02243         case 2:
02244                 FUNCHECK(!fargs[1] || !*fargs[1], "#-1 INVALID MESSAGE");
02245                 MapBroadcast(map, fargs[1]);
02246                 safe_tprintf_str(buff, bufc, "1");
02247                 break;
02248         case 5:
02249                 x = atof(fargs[1]);
02250                 y = atof(fargs[2]);
02251                 range = atof(fargs[3]);
02252                 FUNCHECK(x < 0 || x > map->map_width, "#-1 ILLEGAL X COORD");
02253                 FUNCHECK(y < 0 || y > map->map_height, "#-1 ILLEGAL Y COORD");
02254                 FUNCHECK(range < 0, "#-1 ILLEGAL RANGE");
02255                 FUNCHECK(!fargs[4] || !*fargs[4], "#-1 INVALID MESSAGE");
02256                 MapCoordToRealCoord(x, y, &realX, &realY);
02257                 safe_tprintf_str(buff, bufc, "%d",
02258                                                  MapLimitedBroadcast2d(map, realX, realY, range,
02259                                                                                            fargs[4]));
02260                 break;
02261         case 6:
02262                 x = atof(fargs[1]);
02263                 y = atof(fargs[2]);
02264                 z = atof(fargs[3]);
02265                 range = atof(fargs[4]);
02266                 FUNCHECK(x < 0 || x > map->map_width, "#-1 ILLEGAL X COORD");
02267                 FUNCHECK(y < 0 || y > map->map_height, "#-1 ILLEGAL Y COORD");
02268                 FUNCHECK(z < 0 || z > 100000, "#-1 ILLEGAL Z COORD");   // XXX: Is this accurate?
02269                 FUNCHECK(range < 0, "#-1 ILLEGAL RANGE");
02270                 FUNCHECK(!fargs[5] || !*fargs[5], "#-1 INVALID MESSAGE");
02271                 MapCoordToRealCoord(x, y, &realX, &realY);      // XXX: should we deal with z?
02272                 safe_tprintf_str(buff, bufc, "%d",
02273                                                  MapLimitedBroadcast3d(map, realX, realY, z * ZSCALE,
02274                                                                                            range, fargs[5]));
02275                 break;
02276         default:
02277                 safe_tprintf_str(buff, bufc, "#-1 INVALID ARGUMENTS");
02278                 return;
02279         }
02280 
02281         return;
02282 }
02283 
02284 void fun_btparttype(char *buff, char **bufc, dbref player, dbref cause,
02285                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
02286 {
02287         /*
02288            fargs[0] = stringname of part
02289          */
02290         int i = -1, p, b;
02291 
02292         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02293 
02294         if(!find_matching_long_part(fargs[0], &i, &p, &b)) {
02295                 i = -1;
02296                 FUNCHECK(!find_matching_vlong_part(fargs[0], &i, &p, &b),
02297                                  "#-1 INVALID PART NAME");
02298         }
02299         if(strstr(fargs[0], "Sword") && !strstr(fargs[0], "PC."))
02300                 p = I2Special(SWORD);
02301         if(IsWeapon(p)) {
02302                 safe_tprintf_str(buff, bufc, "WEAP");
02303                 return;
02304         } else if(IsAmmo(p) || strstr(fargs[0], "Ammo_")) {
02305                 safe_tprintf_str(buff, bufc, "AMMO");
02306                 return;
02307         } else if(IsBomb(p)) {
02308                 safe_tprintf_str(buff, bufc, "BOMB");
02309                 return;
02310         } else if(IsSpecial(p)) {
02311                 safe_tprintf_str(buff, bufc, "PART");
02312                 return;
02313 #ifdef BT_COMPLEXREPAIRS
02314         } else if(mudconf.btech_complexrepair && IsCargo(p)
02315                           && Cargo2I(p) >= TON_SENSORS_FIRST
02316                           && Cargo2I(p) <= TON_ENGINE_COMP_LAST) {
02317                 safe_tprintf_str(buff, bufc, "PART");
02318                 return;
02319 #endif
02320         } else if(IsCargo(p)) {
02321                 safe_tprintf_str(buff, bufc, "CARG");
02322                 return;
02323         } else {
02324                 safe_tprintf_str(buff, bufc, "OTHER");
02325                 return;
02326         }
02327 }
02328 
02329 void fun_btgetpartcost(char *buff, char **bufc, dbref player, dbref cause,
02330                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
02331 {
02332 #ifdef BT_ADVANCED_ECON
02333         int i = -1, p, index, b;
02334 
02335         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02336         if(!find_matching_long_part(fargs[0], &i, &p, &b)) {
02337                 i = -1;
02338                 FUNCHECK(!find_matching_vlong_part(fargs[0], &i, &p, &b),
02339                                  "#-1 INVALID PART NAME");
02340         }
02341         if(strstr(fargs[0], "Sword") && !strstr(fargs[0], "PC."))
02342                 p = I2Special(SWORD);
02343 
02344         safe_tprintf_str(buff, bufc, "%lld", GetPartCost(p));
02345 #else
02346         safe_tprintf_str(buff, bufc, "#-1 NO ECONDB SUPPORT");
02347 #endif
02348 }
02349 
02350 void fun_btsetpartcost(char *buff, char **bufc, dbref player, dbref cause,
02351                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
02352 {
02353 #ifdef BT_ADVANCED_ECON
02354         int i = -1, p, index, b;
02355         unsigned long long int cost;
02356 
02357         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02358         if(!find_matching_long_part(fargs[0], &i, &p, &b)) {
02359                 i = -1;
02360                 FUNCHECK(!find_matching_vlong_part(fargs[0], &i, &p, &b),
02361                                  "#-1 INVALID PART NAME");
02362         }
02363         if(strstr(fargs[0], "Sword") && !strstr(fargs[0], "PC."))
02364                 p = I2Special(SWORD);
02365         cost = atoll(fargs[1]);
02366         /* since we're using an unsigned long long, lets check before we push it to unsigned status */
02367         if(atoll(fargs[1]) < 0) {
02368                 safe_tprintf_str(buff, bufc, "#-1 COST ERROR");
02369                 return;
02370         }
02371         SetPartCost(p, cost);
02372         safe_tprintf_str(buff, bufc, "%lld", cost);
02373 #else
02374         safe_tprintf_str(buff, bufc, "#-1 NO ECONDB SUPPORT");
02375 #endif
02376 }
02377 
02378 void fun_btunitfixable(char *buff, char **bufc, dbref player, dbref cause,
02379                                            char *fargs[], int nfargs, char *cargs[], int ncargs)
02380 {
02381         MECH *mech;
02382         dbref mechdb;
02383 
02384         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02385         mechdb = match_thing(player, fargs[0]);
02386         FUNCHECK(!Good_obj(mechdb), "#-1 INVALID TARGET");
02387         mech = getMech(mechdb);
02388         FUNCHECK(!mech, "#-1 INVALID TARGET");
02389 
02390         safe_tprintf_str(buff, bufc, "%d", unit_is_fixable(mech));
02391 }
02392 
02393 void fun_btlistblz(char *buff, char **bufc, dbref player, dbref cause,
02394                                    char *fargs[], int nfargs, char *cargs[], int ncargs)
02395 {
02396         char buf[MBUF_SIZE] = { '\0' };
02397         dbref mapdb;
02398         MAP *map;
02399         mapobj *tmp;
02400         int i, count = 0, strcount = 0;
02401 
02402         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02403 
02404         mapdb = match_thing(player, fargs[0]);
02405         FUNCHECK(!Good_obj(mapdb), "#-1 INVALID MAP");
02406         FUNCHECK(!(map = getMap(mapdb)), "#-1 INVALID MAP");
02407 
02408         for(i = 0; i < NUM_MAPOBJTYPES; i++)
02409                 for(tmp = first_mapobj(map, i); tmp; tmp = next_mapobj(tmp))
02410                         if(i == TYPE_B_LZ) {
02411                                 count++;
02412                                 if(count == 1)
02413                                         strcount +=
02414                                                 snprintf(buf + strcount, MBUF_SIZE - strcount,
02415                                                                  "%d %d %d", tmp->x, tmp->y, tmp->datai);
02416                                 else
02417                                         strcount +=
02418                                                 snprintf(buf + strcount, MBUF_SIZE - strcount,
02419                                                                  "|%d %d %d", tmp->x, tmp->y, tmp->datai);
02420                         }
02421         safe_tprintf_str(buff, bufc, buf);
02422 }
02423 
02424 void fun_bthexinblz(char *buff, char **bufc, dbref player, dbref cause,
02425                                         char *fargs[], int nfargs, char *cargs[], int ncargs)
02426 {
02427         dbref mapdb;
02428         MAP *map;
02429         mapobj *o;
02430         int x, y, bl = 0;
02431         float fx, fy, tx, ty;
02432 
02433         FUNCHECK(!WizR(player), "#-1 PERMISSION DENIED");
02434 
02435         mapdb = match_thing(player, fargs[0]);
02436         FUNCHECK(!Good_obj(mapdb), "#-1 INVALID MAP");
02437         FUNCHECK(!(map = getMap(mapdb)), "#-1 INVALID MAP");
02438         x = atoi(fargs[1]);
02439         y = atoi(fargs[2]);
02440         FUNCHECK(x < 0 || y < 0 || x > map->map_width
02441                          || y > map->map_height, "#-1 INVALID COORDS");
02442         MapCoordToRealCoord(x, y, &fx, &fy);
02443 
02444         for(o = first_mapobj(map, TYPE_B_LZ); o; o = next_mapobj(o)) {
02445                 if(abs(x - o->x) > o->datai || abs(y - o->y) > o->datai)
02446                         continue;
02447                 MapCoordToRealCoord(o->x, o->y, &tx, &ty);
02448                 if(FindHexRange(fx, fy, tx, ty) <= o->datai) {
02449                         bl = 1;
02450                         break;
02451                 }
02452         }
02453         safe_tprintf_str(buff, bufc, "%d", bl);
02454 }

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