src/hcode/btech/mech.avail.c File Reference

#include <stdio.h>
#include "mech.h"
#include "mech.avail.h"
#include "coolmenu.h"
#include "mycool.h"
#include "p.template.h"
#include "p.mech.mechref_ident.h"

Include dependency graph for mech.avail.c:

Go to the source code of this file.

Defines

#define IsMech(i)   ((i) < NUM_MECHA)
#define IsAero(i)   ((i) >= NUM_MECHA && (i) < (NUM_MECHA + NUM_AEROS))
#define Table(id, fi)
#define Map(a, b)   case a: return Table(id,b); break;
#define STACK_SIZE   NUM_MECHA + NUM_AEROS
#define FUNCHECK(a, b)   if (a) { safe_tprintf_str(buff, bufc, b); return; }

Functions

static int find_score (int table, int id)
static void mech_list_maker (dbref player, int table, int types, int tons, int opt, int max, int mode, char *tbuf)
void debug_makemechs (dbref player, void *data, char *buffer)
void fun_btmakemechs (char *buff, char **bufc, dbref player, dbref cause, char *fargs[], int nfargs, char *cargs[], int ncargs)


Define Documentation

#define FUNCHECK ( a,
 )     if (a) { safe_tprintf_str(buff, bufc, b); return; }

Definition at line 177 of file mech.avail.c.

Referenced by fun_btaddstores(), fun_btarmorstatus(), fun_btarmorstatus_ref(), fun_btcritslot(), fun_btcritslot_ref(), fun_btcritstatus(), fun_btcritstatus_ref(), fun_btdamagemech(), fun_btdamages(), fun_btengrate(), fun_btengrate_ref(), fun_btfasabasecost_ref(), fun_btgetbv(), fun_btgetbv_ref(), fun_btgetcharvalue(), fun_btgetpartcost(), fun_btgetrange(), fun_btgetrealmaxspeed(), fun_btgetweight(), fun_btgetxcodevalue(), fun_btgetxcodevalue_ref(), fun_bthexemit(), fun_bthexinblz(), fun_bthexlos(), fun_btid2db(), fun_btlistblz(), fun_btloadmap(), fun_btloadmech(), fun_btlosm2m(), fun_btmakemechs(), fun_btmakepilotroll(), fun_btmapelev(), fun_btmapemit(), fun_btmapterr(), fun_btmapunits(), fun_btmechfreqs(), fun_btnumrepjobs(), fun_btpartmatch(), fun_btpartname(), fun_btparttype(), fun_btpayload_ref(), fun_btremovestores(), fun_btsetarmorstatus(), fun_btsetcharvalue(), fun_btsetmaxspeed(), fun_btsetpartcost(), fun_btsetxcodevalue(), fun_btsetxy(), fun_btshowcritstatus_ref(), fun_btshowstatus_ref(), fun_btshowwspecs_ref(), fun_btstores(), fun_bttechlist(), fun_bttechlist_ref(), fun_bttechstatus(), fun_btthreshold(), fun_btticweaps(), fun_btunderrepair(), fun_btunitfixable(), fun_btweaponstatus(), fun_btweaponstatus_ref(), and fun_btweapstat().

#define IsAero (  )     ((i) >= NUM_MECHA && (i) < (NUM_MECHA + NUM_AEROS))

Definition at line 27 of file mech.avail.c.

Referenced by mech_list_maker().

#define IsMech (  )     ((i) < NUM_MECHA)

Definition at line 26 of file mech.avail.c.

Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_astar_roam_event(), auto_com_event(), auto_dumbfollow_event(), auto_dumbgoto_event(), auto_enter_event(), auto_goto_event(), auto_gun_event(), auto_leave_event(), auto_reply_event(), auto_sensor_event(), auto_update_profile_event(), CheckEdgeOfMap(), debug_fixmap(), DestroyMech(), fun_btarmorstatus(), fun_btcritslot(), fun_btcritstatus(), fun_btdamagemech(), fun_btdamages(), fun_btengrate(), fun_btgetbv(), fun_btgetrange(), fun_btgetrealmaxspeed(), fun_bthexlos(), fun_btid2db(), fun_btlosm2m(), fun_btmakepilotroll(), fun_btnumrepjobs(), fun_btsetarmorstatus(), fun_btsetmaxspeed(), fun_bttechlist(), fun_bttechstatus(), fun_btticweaps(), fun_btunderrepair(), fun_btweaponstatus(), and mech_list_maker().

#define Map ( a,
 )     case a: return Table(id,b); break;

Referenced by find_score().

#define STACK_SIZE   NUM_MECHA + NUM_AEROS

Definition at line 57 of file mech.avail.c.

Referenced by mech_list_maker().

#define Table ( id,
fi   ) 

Value:

(IsMech(id) ? mech_availability[id].fi : \
 IsAero(id) ? aero_availability[id - NUM_MECHA].fi : 0)

Definition at line 29 of file mech.avail.c.

Referenced by mech_list_maker(), and real_int().


Function Documentation

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

Definition at line 148 of file mech.avail.c.

References args, compare_array(), DOCHECK, mech_list_maker(), mech_parseattributes(), Readnum, and side_names_short.

00149 {
00150         char *args[7];
00151         int argc;
00152         int table;
00153         int tons;
00154         int opt = 0;
00155         int max = 0;
00156         int types = 0xff;
00157 
00158         argc = mech_parseattributes(buffer, args, 6);
00159         DOCHECK(argc < 2, "Insufficient arguments!");
00160         DOCHECK(argc > 5, "Too many arguments!");
00161         DOCHECK((table =
00162                          compare_array(side_names_short, args[0])) < 0,
00163                         "Invalid faction name!");
00164         DOCHECK((tons = atoi(args[1])) < 20, "Invalid tonnage!");
00165         DOCHECK(tons > 4000, "Max of 4000 tons of mecha at once! Sowwy!");
00166         if(argc > 2) {
00167                 DOCHECK(Readnum(types, args[2]), "Invalid type bitvector!");
00168                 if(argc > 3) {
00169                         DOCHECK((opt = atoi(args[3])) < 20, "Invalid optTonnage!");
00170                         if(argc > 4)
00171                                 DOCHECK((max = atoi(args[4])) < 5, "Invalid MaxDifference!");
00172                 }
00173         }
00174         mech_list_maker(player, table, types, tons, opt, max, 0, NULL);
00175 }

static int find_score ( int  table,
int  id 
) [static]

Definition at line 33 of file mech.avail.c.

References FAC_CC, FAC_DC, FAC_FC, FAC_FS, FAC_FWL, FAC_LC, FAC_MERC, FAC_MISC, and Map.

Referenced by mech_list_maker().

00034 {
00035         switch (table) {
00036 #undef Map
00037 #define Map(a,b) case a: return Table(id,b); break;
00038                 Map(FAC_FS, FS);
00039                 Map(FAC_LC, LC);
00040                 Map(FAC_DC, DC);
00041                 Map(FAC_CC, CC);
00042                 Map(FAC_FWL, FWL);
00043                 Map(FAC_MISC, MISC);
00044                 Map(FAC_MERC, MERC);
00045         case FAC_FC:
00046                 return (find_score(FAC_FS, id) + find_score(FAC_LC, id)) / 2;
00047 #undef Map
00048         }
00049         return 0;
00050 }

void fun_btmakemechs ( char *  buff,
char **  bufc,
dbref  player,
dbref  cause,
char *  fargs[],
int  nfargs,
char *  cargs[],
int  ncargs 
)

Definition at line 180 of file mech.avail.c.

References compare_array(), FUNCHECK, LBUF_SIZE, mech_list_maker(), Readnum, safe_tprintf_str(), and side_names_short.

00182 {
00183         /* fargs[0] = faction 
00184            fargs[1] = numtons
00185            fargs[2] = types
00186            fargs[3] = opttons
00187            fargs[4] = maxvar 
00188          */
00189         int table;
00190         int tons;
00191         int opt = 0;
00192         int max = 0;
00193         char buf[LBUF_SIZE];
00194         int types = 0xff;
00195 
00196         FUNCHECK(nfargs < 2, "#-1 Insufficient arguments!");
00197         FUNCHECK(nfargs > 5, "#-1 Too many arguments!");
00198         FUNCHECK((table =
00199                           compare_array(side_names_short, fargs[0])) < 0,
00200                          "#-1 Invalid faction name!");
00201         FUNCHECK((tons = atoi(fargs[1])) < 20, "#-1 Invalid tonnage!");
00202         FUNCHECK(tons > 4000, "#-1 Max of 4000 tons of mecha at once! Sowwy!");
00203         if(nfargs > 2) {
00204                 FUNCHECK(Readnum(types, fargs[2]), "#-1 Invalid type bitvector!");
00205                 if(nfargs > 3) {
00206                         FUNCHECK((opt = atoi(fargs[3])) < 20, "#-1 Invalid optTonnage!");
00207                         if(nfargs > 4)
00208                                 FUNCHECK((max =
00209                                                   atoi(fargs[4])) < 5, "#-1 Invalid MaxDifference!");
00210                 }
00211         }
00212         mech_list_maker(player, table, types, tons, opt, max, 1, buf);
00213         safe_tprintf_str(buff, bufc, "%s", buf);
00214 }

static void mech_list_maker ( dbref  player,
int  table,
int  types,
int  tons,
int  opt,
int  max,
int  mode,
char *  tbuf 
) [static]

Definition at line 59 of file mech.avail.c.

References addline, c, CM_CENTER, CM_ONE, find_mechname_by_mechref(), find_score(), IsAero, IsMech, KillCoolMenu(), MAX, name, notify, Number, ShowCoolMenu(), side_names, sim, STACK_SIZE, Table, tprintf(), and vsi.

Referenced by debug_makemechs(), and fun_btmakemechs().

00061 {
00062         int mech_stack[STACK_SIZE][2];
00063         int i, j, k;
00064         int tp = 0;
00065         int dif;
00066         int count = 0, ftons = 0, otons = tons;
00067         coolmenu *c = NULL;
00068         const char *d;
00069 
00070         bzero(mech_stack, sizeof(mech_stack));
00071         for(i = 0; i < STACK_SIZE; i++) {
00072                 if(!(types & 1) && IsMech(i))
00073                         continue;
00074                 if(!(types & 2) && IsAero(i))
00075                         continue;
00076                 j = find_score(table, i);
00077                 if(opt) {
00078                         if((dif = abs(Table(i, tons) - opt)) > max && max)
00079                                 continue;
00080                         j = j * (100 - dif) * (100 - dif);
00081                 } else
00082                         j = j * 10000;
00083                 if(!j)
00084                         continue;
00085                 tp += j;
00086                 mech_stack[i][0] = j;
00087         }
00088         if(!tp) {
00089                 if(!mode)
00090                         notify(player, "No 'mechs matching that criteria!");
00091                 else
00092                         strcpy(tbuf, tprintf("#-1 ERROR: NO UNITS WITH FLAG %d FOUND",
00093                                                                  types));
00094                 return;
00095         }
00096         /* Ok.. We've made the table. Time to use it */
00097         while ((tons >= MAX(20, opt - max))) {
00098                 i = Number(1, tp);
00099                 for(j = 0; j < STACK_SIZE; j++) {
00100                         i -= mech_stack[j][0];
00101                         if(i <= 0)
00102                                 break;
00103                 }
00104                 if((k = Table(j, tons)) > tons)
00105                         continue;
00106                 mech_stack[j][1]++;
00107                 tons -= k;
00108                 count++;
00109                 ftons += k;
00110         }
00111         /* We've a mech list. Time to show it :> */
00112         if(mode == 0) {
00113                 addline();
00114                 sim(tprintf("Mechs/Aeros/Whatever made for %s (%d tons)",
00115                                         side_names[table], otons), CM_ONE | CM_CENTER);
00116                 addline();
00117                 if(!count)
00118                         vsi("No mechs created? (Too low tonnage?)");
00119                 else {
00120                         vsi(tprintf("%-4s %-10s %-20s %-6s %-s", "Tons", "Ref", "Name",
00121                                                 "Chance", "Count"));
00122                         for(i = 0; i < STACK_SIZE; i++)
00123                                 if(mech_stack[i][1]) {
00124                                         d = find_mechname_by_mechref(Table(i, name));
00125                                         vsi(tprintf("%4d %-10s %-20s %6.2f %d", Table(i, tons),
00126                                                                 Table(i, name), d ? d : "Unknown",
00127                                                                 (float) 100.0 * mech_stack[i][0] / tp,
00128                                                                 mech_stack[i][1]));
00129 
00130                                 }
00131                         addline();
00132                         vsi(tprintf("Avg weight: %.2f Total tons: %d",
00133                                                 (float) ftons / count, ftons));
00134                 }
00135                 addline();
00136                 ShowCoolMenu(player, c);
00137                 KillCoolMenu(c);
00138         } else {
00139                 *tbuf = 0;
00140                 for(i = 0; i < STACK_SIZE; i++)
00141                         for(j = 0; j < mech_stack[i][1]; j++)
00142                                 sprintf(tbuf + strlen(tbuf), "%s ", Table(i, name));
00143                 if(*tbuf)
00144                         tbuf[strlen(tbuf) - 1] = 0;
00145         }
00146 }


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