src/hcode/btech/econ_cmds.c File Reference

#include <stdio.h>
#include "mech.h"
#include "coolmenu.h"
#include "math.h"
#include "mech.partnames.h"
#include "p.aero.bomb.h"
#include "p.econ.h"
#include "p.mech.partnames.h"
#include "p.crit.h"
#include "p.mech.status.h"
#include "p.mech.utils.h"

Include dependency graph for econ_cmds.c:

Go to the source code of this file.

Defines

#define MY_DO_LIST(t)
#define silly_search(func)
#define MY_ECON_MODIFY(loc, num)

Functions

void SetCargoWeight (MECH *mech)
int loading_bay_whine (dbref player, dbref cargobay, MECH *mech)
void mech_Rfixstuff (dbref player, void *data, char *buffer)
void list_matching (dbref player, char *header, dbref loc, char *buf)
void mech_manifest (dbref player, void *data, char *buffer)
void mech_stores (dbref player, void *data, char *buffer)
static void stuff_change_sub (dbref player, char *buffer, dbref loc1, dbref loc2, int mod, int mort)
void mech_Raddstuff (dbref player, void *data, char *buffer)
void mech_Rremovestuff (dbref player, void *data, char *buffer)
void mech_loadcargo (dbref player, void *data, char *buffer)
void mech_unloadcargo (dbref player, void *data, char *buffer)
void mech_Rresetstuff (dbref player, void *data, char *buffer)


Define Documentation

#define MY_DO_LIST (  ) 

Value:

if (*buffer) \
  list_matching(player, tprintf("Part listing for %s matching %s", Name(t), buffer), t, buffer); \
else \
  list_matching(player, tprintf("Part listing for %s", Name(t)), t, NULL)

Definition at line 201 of file econ_cmds.c.

Referenced by mech_manifest(), and mech_stores().

#define MY_ECON_MODIFY ( loc,
num   ) 

Value:

econ_change_items(loc, id, brand, num); \
      SendEcon(tprintf("#%d %s %d %s %s #%d.", \
                            player, num>0 ? "added": "removed",  \
                            abs(num), (c=get_parts_long_name(id,brand)), \
                            num>0 ? "to": "from", \
                            loc))

Referenced by stuff_change_sub().

#define silly_search ( func   ) 

Value:

if (!count) {  \
    i = -1 ; while (func(args[0], &i, &id, &brand)) \
      count++; \
    DOCHECK(count > 1, "Too many matches!"); \
    if (count > 0) sfun = func; }

Definition at line 236 of file econ_cmds.c.

Referenced by stuff_change_sub().


Function Documentation

void list_matching ( dbref  player,
char *  header,
dbref  loc,
char *  buf 
)

Definition at line 138 of file econ_cmds.c.

References A_ECONPARTS, BRANDCOUNT, BT_PART_WEIGHTS, c, CM_CENTER, CM_LINE, CM_NOTOG, CM_NUMBER, CM_ONE, CM_TWO, CreateMenuEntry_Killer(), CreateMenuEntry_Simple, find_matching_long_part(), GetPartWeight(), KillCoolMenu(), LBUF_SIZE, NUM_ITEMS, object_count, part_name_long(), SendError, short_sorted, ShowCoolMenu(), silly_atr_get(), tprintf(), UNPACK_PART, and x.

00139 {
00140         int pile[BRANDCOUNT + 1][NUM_ITEMS];
00141         int pile2[BRANDCOUNT + 1][NUM_ITEMS];
00142         char *t, *ch;
00143         int i1, i2, i3, id, brand;
00144         int x, i;
00145 
00146 #ifdef BT_PART_WEIGHTS
00147         char tmpstr[LBUF_SIZE];
00148         int sw = 0;
00149 #endif /* BT_PART_WEIGHTS */
00150         coolmenu *c = NULL;
00151         int found = 0;
00152 
00153         bzero(pile, sizeof(pile));
00154         bzero(pile2, sizeof(pile2));
00155         CreateMenuEntry_Simple(&c, NULL, CM_ONE | CM_LINE);
00156         CreateMenuEntry_Simple(&c, header, CM_ONE | CM_CENTER);
00157         CreateMenuEntry_Simple(&c, NULL, CM_ONE | CM_LINE);
00158         /* Then, we go on a mad rampage ;-) */
00159         t = silly_atr_get(loc, A_ECONPARTS);
00160         while (*t) {
00161                 if(*t == '[')
00162                         if((sscanf(t, "[%d,%d,%d]", &i1, &i2, &i3)) == 3)
00163                                 pile[i2][i1] += i3;
00164                 t++;
00165         }
00166         i = 0;
00167         if(buf)
00168                 while (find_matching_long_part(buf, &i, &id, &brand))
00169                         pile2[brand][id] = pile[brand][id];
00170         for(i = 0; i < object_count; i++) {
00171                 UNPACK_PART(short_sorted[i]->index, id, brand);
00172                 if((buf && (x = pile2[brand][id])) || ((!buf &&
00173                                                                                                 (x = pile[brand][id])))) {
00174 #ifndef BT_PART_WEIGHTS
00175                         ch = part_name_long(id, brand);
00176 #else
00177                         sw = GetPartWeight(id);
00178                         sprintf(tmpstr, "%s (%.1ft)", part_name_long(id, brand),
00179                                         (sw * x) / 1024.0);
00180                         ch = tmpstr;
00181 #endif /* BT_PART_WEIGHTS */
00182                         if(!ch) {
00183                                 SendError(tprintf
00184                                                   ("#%d in %d encountered odd thing: %d %d/%d's.",
00185                                                    player, loc, pile[brand][id], id, brand));
00186                                 continue;
00187                         }
00188                         /* x = amount of things */
00189                         CreateMenuEntry_Killer(&c, ch, CM_TWO | CM_NUMBER | CM_NOTOG,
00190                                                                    0, x, x);
00191                         found++;
00192                 }
00193         }
00194         if(!found)
00195                 CreateMenuEntry_Simple(&c, "None", CM_ONE);
00196         CreateMenuEntry_Simple(&c, NULL, CM_ONE | CM_LINE);
00197         ShowCoolMenu(player, c);
00198         KillCoolMenu(c);
00199 }

int loading_bay_whine ( dbref  player,
dbref  cargobay,
MECH mech 
)

Definition at line 82 of file econ_cmds.c.

References A_MECHSKILLS, c, MechX, MechY, notify, notify_printf(), and silly_atr_get().

Referenced by mech_loadcargo(), and mech_stores().

00083 {
00084         char *c;
00085         int i1, i2, i3 = 0;
00086 
00087         c = silly_atr_get(cargobay, A_MECHSKILLS);
00088         if(c && *c)
00089                 if(sscanf(c, "%d %d %d", &i1, &i2, &i3) >= 2)
00090                         if(MechX(mech) != i1 || MechY(mech) != i2) {
00091                                 notify(player, "You're not where the cargo is!");
00092                                 if(i3)
00093                                         notify_printf(player,
00094                                                                   "Try looking around %d,%d instead.", i1,
00095                                                                   i2);
00096                                 return 1;
00097                         }
00098         return 0;
00099 }

void mech_loadcargo ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 333 of file econ_cmds.c.

References CARGO_TECH, cch, correct_speed(), DOCHECK, In_Character, loading_bay_whine(), Location, MECH::mapindex, MECH_USUALO, MechSpecials, MechSpeed, MECH::mynum, and stuff_change_sub().

00334 {
00335         MECH *mech = (MECH *) data;
00336 
00337         cch(MECH_USUALO);
00338         DOCHECK(!(MechSpecials(mech) & CARGO_TECH),
00339                         "This unit cannot haul cargo!");
00340         DOCHECK(fabs(MechSpeed(mech)) > 0.0, "You're moving too fast!");
00341         DOCHECK(Location(mech->mynum) != mech->mapindex ||
00342                         In_Character(Location(mech->mynum)), "You aren't inside hangar!");
00343         if(loading_bay_whine(player, Location(mech->mynum), mech))
00344                 return;
00345         stuff_change_sub(player, buffer, mech->mynum, mech->mapindex, 1, 1);
00346         correct_speed(mech);
00347 }

void mech_manifest ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 207 of file econ_cmds.c.

References Location, and MY_DO_LIST.

00208 {
00209         while (isspace(*buffer))
00210                 buffer++;
00211         MY_DO_LIST(Location(player));
00212 }

void mech_Raddstuff ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 323 of file econ_cmds.c.

References Location, and stuff_change_sub().

00324 {
00325         stuff_change_sub(player, buffer, Location(player), -1, 1, 0);
00326 }

void mech_Rfixstuff ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 101 of file econ_cmds.c.

References A_ECONPARTS, BRANDCOUNT, econ_change_items(), get_parts_long_name(), IsCrap, loc, Location, notify_printf(), NUM_ITEMS, silly_atr_get(), and silly_atr_set().

Referenced by eliminate_empties().

00102 {
00103         int loc = Location(player);
00104         int pile[BRANDCOUNT + 1][NUM_ITEMS];
00105         char *t;
00106         int ol, nl, items = 0, kinds = 0;
00107         int i1, i2, i3, id, brand;
00108 
00109         if(!data)
00110                 loc = atoi(buffer);
00111         bzero(pile, sizeof(pile));
00112         t = silly_atr_get(loc, A_ECONPARTS);
00113         ol = strlen(t);
00114         while (*t) {
00115                 if(*t == '[')
00116                         if((sscanf(t, "[%d,%d,%d]", &i1, &i2, &i3)) == 3)
00117                                 if(!IsCrap(i1))
00118                                         pile[i2][i1] += i3;
00119                 t++;
00120         }
00121         silly_atr_set(loc, A_ECONPARTS, "");
00122         for(id = 0; id < NUM_ITEMS; id++)
00123                 for(brand = 0; brand <= BRANDCOUNT; brand++)
00124                         if(pile[brand][id] > 0 && get_parts_long_name(id, brand)) {
00125                                 econ_change_items(loc, id, brand, pile[brand][id]);
00126                                 kinds++;
00127                                 items += pile[brand][id];
00128                         }
00129         t = silly_atr_get(loc, A_ECONPARTS);
00130         nl = strlen(t);
00131         notify_printf(player,
00132                                   "Fixing done. Original length: %d. New length: %d.", ol,
00133                                   nl);
00134         notify_printf(player, "Items in new: %d. Unique items in new: %d.",
00135                                   items, kinds);
00136 }

void mech_Rremovestuff ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 328 of file econ_cmds.c.

References Location, and stuff_change_sub().

00329 {
00330         stuff_change_sub(player, buffer, Location(player), -1, -1, 0);
00331 }

void mech_Rresetstuff ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 360 of file econ_cmds.c.

References A_ECONPARTS, Location, notify, SendEcon, silly_atr_set(), and tprintf().

00361 {
00362         notify(player, "Inventory cleaned!");
00363         silly_atr_set(Location(player), A_ECONPARTS, "");
00364         SendEcon(tprintf("#%d reset #%d's stuff.", player, Location(player)));
00365 }

void mech_stores ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 214 of file econ_cmds.c.

References cch, DOCHECK, In_Character, loading_bay_whine(), Location, MECH::mapindex, MECH_USUAL, MY_DO_LIST, and MECH::mynum.

00215 {
00216         MECH *mech = (MECH *) data;
00217 
00218         cch(MECH_USUAL);
00219         DOCHECK(Location(mech->mynum) != mech->mapindex ||
00220                         In_Character(Location(mech->mynum)),
00221                         "You aren't inside a hangar!");
00222         if(loading_bay_whine(player, Location(mech->mynum), mech))
00223                 return;
00224         while (isspace(*buffer))
00225                 buffer++;
00226         MY_DO_LIST(Location(mech->mynum));
00227 }

void mech_unloadcargo ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 349 of file econ_cmds.c.

References CARGO_TECH, cch, correct_speed(), DOCHECK, MECH::mapindex, MECH_USUALSO, MechSpecials, MECH::mynum, and stuff_change_sub().

Referenced by auto_com_event().

00350 {
00351         MECH *mech = (MECH *) data;
00352 
00353         cch(MECH_USUALSO);
00354         DOCHECK(!(MechSpecials(mech) & CARGO_TECH),
00355                         "This unit cannot haul cargo!");
00356         stuff_change_sub(player, buffer, mech->mynum, mech->mapindex, -1, 1);
00357         correct_speed(mech);
00358 }

void SetCargoWeight ( MECH mech  ) 

Definition at line 40 of file econ_cmds.c.

References A_ECONPARTS, AeroFuel, AeroFuelMax, AeroFuelOrig, FlyingT, FUELTANK, GetPartType, GetPartWeight(), I2Special, IsBomb, IsSpecial, MECH::mynum, NUM_CRITICALS, NUM_ITEMS, NUM_SECTIONS, SetCarriedCargo, silly_atr_get(), and Special2I.

Referenced by bomb_drop(), correct_speed(), FuelCheck(), mech_startup_event(), and mech_udisembark().

00041 {
00042         int pile[NUM_ITEMS];
00043         int sw, weight = 0;                     /* in 1/10 tons */
00044         int i, j, k;
00045         char *t;
00046         int i1, i2, i3;
00047 
00048         t = silly_atr_get(mech->mynum, A_ECONPARTS);
00049         bzero(pile, sizeof(pile));
00050         while (*t) {
00051                 if(*t == '[')
00052                         if((sscanf(t, "[%d,%d,%d]", &i1, &i2, &i3)) == 3)
00053                                 pile[i1] += ((IsBomb(i1)) ? 4 : 1) * i3;
00054                 t++;
00055         }
00056         if(FlyingT(mech))
00057                 for(i = 0; i < NUM_SECTIONS; i++)
00058                         for(j = 0; j < NUM_CRITICALS; j++) {
00059                                 if(IsBomb((k = GetPartType(mech, i, j))))
00060                                         pile[k]++;
00061                                 else if(IsSpecial(k))
00062                                         if(Special2I(k) == FUELTANK)
00063                                                 pile[I2Special(FUELTANK)]++;
00064                         }
00065         /* We've 'so-called' pile now */
00066         for(i = 0; i < NUM_ITEMS; i++)
00067                 if(pile[i]) {
00068                         sw = GetPartWeight(i);
00069                         weight += sw * pile[i];
00070                 }
00071         if(FlyingT(mech)) {
00072                 AeroFuelMax(mech) =
00073                         AeroFuelOrig(mech) + 2000 * pile[I2Special(FUELTANK)];
00074                 if(AeroFuel(mech) > AeroFuelOrig(mech))
00075                         weight += AeroFuel(mech) - AeroFuelOrig(mech);
00076         }
00077         SetCarriedCargo(mech, weight);
00078 }

static void stuff_change_sub ( dbref  player,
char *  buffer,
dbref  loc1,
dbref  loc2,
int  mod,
int  mort 
) [static]

Definition at line 247 of file econ_cmds.c.

References ADDSTORES_MAX, args, c, DOCHECK, econ_find_items(), find_matching_long_part(), find_matching_short_part(), find_matching_vlong_part(), GOD, Location, mech_parseattributes(), MIN, MY_ECON_MODIFY, notify_printf(), silly_search, and tprintf().

Referenced by mech_loadcargo(), mech_Raddstuff(), mech_Rremovestuff(), and mech_unloadcargo().

00249 {
00250         int i = -1, id, brand;
00251         int count = 0;
00252         int argc;
00253         char *args[2];
00254         char *c;
00255         int num;
00256         int (*sfun) (char *, int *i, int *id, int *brand) = NULL;
00257         int foo = 0;
00258 
00259         argc = mech_parseattributes(buffer, args, 2);
00260         DOCHECK(argc < 2, "Invalid number of arguments!");
00261 
00262         /* 
00263          * If we hit the max amount of parts addable at once, set quantity
00264          * to add to max.
00265          */
00266         num = atoi(args[1]);
00267         if(num > ADDSTORES_MAX) {
00268                 num = ADDSTORES_MAX;
00269         }
00270 
00271         DOCHECK(num <= 0, "Invalid amount!");
00272         silly_search(find_matching_short_part);
00273         silly_search(find_matching_vlong_part);
00274         silly_search(find_matching_long_part);
00275         DOCHECK(count == 0, tprintf("Nothing matches '%s'!", args[0]));
00276         DOCHECK(!mort && count > 20 &&
00277                         player != GOD,
00278                         tprintf
00279                         ("Wizards can't add more than 20 different objtypes at a time. ('%s' matches: %d)",
00280                          args[0], count));
00281         if(mort) {
00282                 DOCHECK(Location(player) != loc1, "You ain't in your 'mech!");
00283                 DOCHECK(Location(loc1) != loc2, "You ain't in hangar!");
00284         }
00285         i = -1;
00286 #define MY_ECON_MODIFY(loc,num) \
00287       econ_change_items(loc, id, brand, num); \
00288       SendEcon(tprintf("#%d %s %d %s %s #%d.", \
00289                             player, num>0 ? "added": "removed",  \
00290                             abs(num), (c=get_parts_long_name(id,brand)), \
00291                             num>0 ? "to": "from", \
00292                             loc))
00293         while (sfun(args[0], &i, &id, &brand)) {
00294                 if(mort) {
00295                         if(mod < 0)
00296                                 count = MIN(num, econ_find_items(loc1, id, brand));
00297                         else
00298                                 count = MIN(num, econ_find_items(loc2, id, brand));
00299                 } else
00300                         count = num;
00301                 foo += count;
00302                 if(!count)
00303                         continue;
00304                 MY_ECON_MODIFY(loc1, mod * count);
00305                 if(count)
00306                         switch (mort) {
00307                         case 0:
00308                                 notify_printf(player, "You %s %d %s%s.",
00309                                                           mod > 0 ? "add" : "remove", count, c,
00310                                                           count > 1 ? "s" : "");
00311                                 break;
00312                         case 1:
00313                                 MY_ECON_MODIFY(loc2, (0 - mod) * count);
00314                                 notify_printf(player, "You %s %d %s%s.",
00315                                                           mod > 0 ? "load" : "unload", count, c,
00316                                                           count > 1 ? "s" : "");
00317                                 break;
00318                         }
00319         }
00320         DOCHECK(!foo, "Nothing matching that criteria was found!");
00321 }


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