src/hcode/debug.c

Go to the documentation of this file.
00001 /*
00002  * Debug.c
00003  *
00004  *  File for debug of the hardcode routines.
00005  *
00006  * Serious knifing / new functions by Markus Stenberg <fingon@iki.fi>
00007  */
00008 
00009 #include "config.h"
00010 #include "externs.h"
00011 #include "debug.h"
00012 #include "glue.h"
00013 #include "muxevent.h"
00014 #include "mech.h"
00015 #include "create.h"
00016 #include "mux_tree.h"
00017 #include "p.mux_tree.h"
00018 #include "p.map.obj.h"
00019 #include "p.mech.startup.h"
00020 #include "p.mech.partnames.h"
00021 
00022 void GoThruTree(Tree tree, int (*func) (Node *));
00023 
00024 void debug_list(dbref player, void *data, char *buffer)
00025 {
00026         char *args[3];
00027         int argc;
00028 
00029         argc = mech_parseattributes(buffer, args, 3);
00030         if(argc == 0)
00031                 return;
00032         else if(args[0][0] == 'M' || args[0][0] == 'm')
00033                 if(args[0][1] == 'E' || args[0][1] == 'e')
00034                         DumpMechs(player);
00035         if(args[0][1] == 'A' || args[0][1] == 'a')
00036                 DumpMaps(player);
00037 }
00038 
00039 void debug_savedb(dbref player, void *data, char *buffer)
00040 {
00041         notify(player, "--- Saving ---");
00042         SaveSpecialObjects(DUMP_NORMAL);
00043         notify(player, "---  Done  ---");
00044 }
00045 
00046 void debug_loaddb(dbref player, void *data, char *buffer)
00047 {
00048         notify(player, "--- Loading ---");
00049         LoadSpecialObjects();
00050         notify(player, "---  Done   ---");
00051 }
00052 
00053 static int *number;
00054 static int *smallest;
00055 static int *largest;
00056 static int *total;
00057 static dbref cheat_player;
00058 extern Tree xcode_tree;
00059 extern int global_specials;
00060 extern SpecialObjectStruct SpecialObjects[];
00061 
00062 static int debug_check_stuff(Node * tmp)
00063 {
00064         int osize, size, t;
00065         MAP *map;
00066 
00067         t = NodeType(tmp);
00068         osize = size = SpecialObjects[t].datasize;
00069         switch (t) {
00070         case GTYPE_MAP:
00071                 map = (MAP *) NodeData(tmp);
00072                 if(map->map) {
00073                         size += sizeof(map->map[0][0]) * map->map_width * map->map_height;
00074                         size += bit_size(map);
00075                         size += obj_size(map);
00076                         size += mech_size(map);
00077                 }
00078                 break;
00079         }
00080         if(smallest[t] < 0 || size < smallest[t])
00081                 smallest[t] = size;
00082         if(largest[t] < 0 || size > largest[t])
00083                 largest[t] = size;
00084         total[t] += size;
00085         number[t]++;
00086         if(cheat_player > 0 && osize != size)
00087                 notify_printf(cheat_player, "#%d: %s (%d bytes)", NodeKey(tmp),
00088                                           SpecialObjects[t].type, size);
00089         return 1;
00090 }
00091 
00092 void debug_memory(dbref player, void *data, char *buffer)
00093 {
00094         int i, gtotal = 0;
00095 
00096         Create(number, int, global_specials);
00097         Create(smallest, int, global_specials);
00098         Create(largest, int, global_specials);
00099         Create(total, int, global_specials);
00100 
00101         for(i = 0; i < global_specials; i++) {
00102                 number[i] = 0;
00103                 smallest[i] = -1;
00104                 largest[i] = -1;
00105                 total[i] = 0;
00106         }
00107         cheat_player = player;
00108         skipws(buffer);
00109         if(strcmp(buffer, ""))
00110                 cheat_player = player;
00111         else
00112                 cheat_player = -1;
00113         GoThruTree(xcode_tree, debug_check_stuff);
00114         for(i = 0; i < global_specials; i++) {
00115                 if(number[i]) {
00116                         if(smallest[i] == largest[i])
00117                                 notify_printf(player,
00118                                                           "%4d %-20s: %d bytes total, %d each",
00119                                                           number[i], SpecialObjects[i].type, total[i],
00120                                                           total[i] / number[i]);
00121                         else
00122                                 notify_printf(player,
00123                                                           "%4d %-20s: %d bytes total, %d avg, %d/%d small/large",
00124                                                           number[i], SpecialObjects[i].type, total[i],
00125                                                           total[i] / number[i], smallest[i], largest[i]);
00126                 }
00127                 gtotal += total[i];
00128         }
00129         notify_printf(player, "Grand total: %d bytes.", gtotal);
00130         free((void *) number);
00131         free((void *) total);
00132         free((void *) smallest);
00133         free((void *) largest);
00134 }
00135 
00136 void ShutDownMap(dbref player, dbref mapnumber)
00137 {
00138         MAP *map;
00139         MECH *mech;
00140         int j;
00141         Node *tmp;
00142 
00143         tmp = FindNode(xcode_tree, mapnumber);
00144         if(tmp) {
00145                 map = (MAP *) NodeData(tmp);
00146                 for(j = 0; j < map->first_free; j++)
00147                         if(map->mechsOnMap[j] != -1) {
00148                                 mech = getMech(map->mechsOnMap[j]);
00149                                 if(mech) {
00150                                         notify_printf(player,
00151                                                                   "Shutting down Mech #%d and restting map index to -1....",
00152                                                                   map->mechsOnMap[j]);
00153                                         mech_shutdown(GOD, (void *) mech, "");
00154                                         MechLastX(mech) = 0;
00155                                         MechLastY(mech) = 0;
00156                                         MechX(mech) = 0;
00157                                         MechY(mech) = 0;
00158                                         remove_mech_from_map(map, mech);
00159                                 }
00160                         }
00161                 map->first_free = 0;
00162                 notify(player, "Map Cleared");
00163                 return;
00164         }
00165 }
00166 
00167 void debug_shutdown(dbref player, void *data, char *buffer)
00168 {
00169         char *args[3];
00170         int argc;
00171 
00172         argc = mech_parseattributes(buffer, args, 3);
00173         if(argc > 0)
00174                 ShutDownMap(player, atoi(args[0]));
00175 }
00176 
00177 void debug_setvrt(dbref player, void *data, char *buffer)
00178 {
00179         char *args[3];
00180         int vrt;
00181         int id, brand;
00182 
00183         DOCHECK(mech_parseattributes(buffer, args, 3) != 2, "Invalid arguments!");
00184         DOCHECK(Readnum(vrt, args[1]), "Invalid value!");
00185         DOCHECK(vrt <= 0, "VRT needs to be >0");
00186         DOCHECK(vrt > 127, "VRT can be at max 127");
00187         DOCHECK(!find_matching_vlong_part(args[0], NULL, &id, &brand),
00188                         "That is no weapon!");
00189         DOCHECK(!IsWeapon(id), "That is no weapon!");
00190         MechWeapons[Weapon2I(id)].vrt = vrt;
00191         notify_printf(player, "VRT for %s set to %d.",
00192                                   MechWeapons[Weapon2I(id)].name, vrt);
00193     log_error(LOG_WIZARD, "WIZ", "CHANGE", "VRT for %s set to %d by #%d", 
00194                                                  MechWeapons[Weapon2I(id)].name, vrt, player);
00195 }

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