00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdio.h>
00018
00019 #include "mech.h"
00020 #include "mech.avail.h"
00021 #include "coolmenu.h"
00022 #include "mycool.h"
00023 #include "p.template.h"
00024 #include "p.mech.mechref_ident.h"
00025
00026 #define IsMech(i) ((i) < NUM_MECHA)
00027 #define IsAero(i) ((i) >= NUM_MECHA && (i) < (NUM_MECHA + NUM_AEROS))
00028
00029 #define Table(id,fi) \
00030 (IsMech(id) ? mech_availability[id].fi : \
00031 IsAero(id) ? aero_availability[id - NUM_MECHA].fi : 0)
00032
00033 static int find_score(int table, int id)
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 }
00051
00052
00053
00054
00055
00056
00057 #define STACK_SIZE NUM_MECHA + NUM_AEROS
00058
00059 static void mech_list_maker(dbref player, int table, int types, int tons,
00060 int opt, int max, int mode, char *tbuf)
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
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
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 }
00147
00148 void debug_makemechs(dbref player, void *data, char *buffer)
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 }
00176
00177 #define FUNCHECK(a,b) \
00178 if (a) { safe_tprintf_str(buff, bufc, b); return; }
00179
00180 void fun_btmakemechs(char *buff, char **bufc, dbref player, dbref cause,
00181 char *fargs[], int nfargs, char *cargs[], int ncargs)
00182 {
00183
00184
00185
00186
00187
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 }