00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "mech.h"
00011 #include "muxevent.h"
00012 #include "mech.events.h"
00013 #include "mech.tech.h"
00014 #include "p.mech.utils.h"
00015 #include "p.btechstats.h"
00016 #include "p.mech.build.h"
00017 #include "p.mech.partnames.h"
00018
00019 int game_lag(void)
00020 {
00021 if(!muxevent_tick)
00022 return 0;
00023 return 100 * (mudstate.now - mudstate.restart_time) / muxevent_tick - 100;
00024 }
00025
00026 int game_lag_time(int i)
00027 {
00028 return (100 + game_lag()) * i / 100;
00029 }
00030
00031 int tech_roll(dbref player, MECH * mech, int diff)
00032 {
00033 int s;
00034 int succ;
00035 int r =
00036 (HasBoolAdvantage(player, "tech_aptitude") ? char_rollsaving() :
00037 Roll());
00038
00039 s = FindTechSkill(player, mech);
00040 s += diff;
00041 succ = r >= s;
00042 if(Wizard(player)) {
00043 notify_printf(player, "Tech - BTH: %d(Base:%d, Mod:%d) Roll: %d",
00044 s, s - diff, diff, r);
00045 } else {
00046 notify_printf(player, "BTH: %d Roll: %d", s, r);
00047 }
00048 if(succ && In_Character(mech->mynum))
00049 AccumulateTechXP(player, mech, BOUNDED(1, s - 7, MAX(2, 1 + diff)));
00050 return (r - s);
00051 }
00052
00053 int tech_weapon_roll(dbref player, MECH * mech, int diff)
00054 {
00055 int s;
00056 int succ;
00057 int r =
00058 (HasBoolAdvantage(player, "tech_aptitude") ? char_rollsaving() :
00059 Roll());
00060
00061 s = char_getskilltarget(player, "technician-weapons", 0);
00062 s += diff;
00063 succ = r >= s;
00064 if(Wizard(player)) {
00065 notify_printf(player,
00066 "Tech-W - BTH: %d(Base:%d, Mod:%d) Roll: %d", s,
00067 s - diff, diff, r);
00068 } else {
00069 notify_printf(player, "BTH: %d Roll: %d", s, r);
00070 }
00071 if(succ && In_Character(mech->mynum))
00072 AccumulateTechWeaponsXP(player, mech, BOUNDED(1, s - 7, MAX(2,
00073 1 +
00074 diff)));
00075 return (r - s);
00076 }
00077
00078
00079
00080
00081 void tech_status(dbref player, time_t dat)
00082 {
00083 char buf[MBUF_SIZE];
00084 char *olds;
00085 int un;
00086
00087 if(dat <= 0) {
00088 olds = silly_atr_get(player, A_TECHTIME);
00089 if(olds) {
00090 dat = (time_t) atoi(olds);
00091 if(dat < mudstate.now)
00092 dat = mudstate.now;
00093 } else
00094 dat = mudstate.now;
00095 }
00096 if(dat <= mudstate.now)
00097 notify(player, "You have no jobs pending!");
00098 else {
00099 un = (dat - mudstate.now) / TECH_TICK;
00100 sprintf(buf, "You have %d %s%s of repairs pending", un, TECH_UNIT,
00101 un != 1 ? "s" : "");
00102 if(un >= MAX_TECHTIME)
00103 sprintf(buf + strlen(buf),
00104 " and you're too tired to do more efficiently.");
00105 else {
00106 un = MAX_TECHTIME - un;
00107 sprintf(buf + strlen(buf),
00108 " and you're ready to do at least %d more %s%s of work.",
00109 un, TECH_UNIT, un == 1 ? "" : "s");
00110 }
00111 notify(player, buf);
00112 }
00113 }
00114
00115 int tech_addtechtime(dbref player, int time)
00116 {
00117 time_t old;
00118 char *olds = silly_atr_get(player, A_TECHTIME);
00119
00120 if(olds) {
00121 old = (time_t) atoi(olds);
00122 if(old < mudstate.now)
00123 old = mudstate.now;
00124 } else
00125 old = mudstate.now;
00126 old += time * TECH_TICK;
00127 silly_atr_set(player, A_TECHTIME, tprintf("%u", old));
00128 tech_status(player, old);
00129 return (old - mudstate.now);
00130 }
00131
00132 int tech_parsepart_advanced(MECH * mech, char *buffer, int *loc, int *pos,
00133 int *extra, int allowrear)
00134 {
00135 char *args[5];
00136 int l, argc, isrear = 0;
00137
00138 if(!(argc = mech_parseattributes(buffer, args, 4)))
00139 return -1;
00140 if(argc > (2 + (extra != NULL)))
00141 return -1;
00142 if(!allowrear) {
00143 if((!extra && argc != (1 + (pos != NULL))) || (extra &&
00144 (argc <
00145 (1 + (pos != NULL))
00146 || argc >
00147 (2 + (pos != NULL)))))
00148 return -1;
00149 } else {
00150 if(argc == 2) {
00151 if(toupper(args[1][0]) != 'R')
00152 return -1;
00153 isrear = 8;
00154 }
00155 }
00156 if((*loc =
00157 ArmorSectionFromString(MechType(mech), MechMove(mech), args[0])) < 0)
00158 return -1;
00159 if(allowrear)
00160 *loc += isrear;
00161 if(pos) {
00162 l = atoi(args[1]) - 1;
00163 if(l < 0 || l >= CritsInLoc(mech, *loc))
00164 return -2;
00165 *pos = l;
00166 }
00167 if(extra) {
00168 if(argc > 2)
00169 *extra = args[2][0];
00170 else
00171 *extra = 0;
00172 }
00173 return 0;
00174 }
00175
00176 int tech_parsepart(MECH * mech, char *buffer, int *loc, int *pos, int *extra)
00177 {
00178 return tech_parsepart_advanced(mech, buffer, loc, pos, extra, 0);
00179 }
00180
00181 int tech_parsegun(MECH * mech, char *buffer, int *loc, int *pos, int *brand)
00182 {
00183 char *args[3];
00184 int l, argc, t, c = 0, pi, pb;
00185
00186 argc = mech_parseattributes(buffer, args, 3);
00187 if(argc < 1 || argc > (2 + (brand != NULL)))
00188 return -1;
00189 if(argc == (2 + (brand != NULL)) || (brand && argc == 2 && atoi(args[1]))) {
00190 if((*loc =
00191 ArmorSectionFromString(MechType(mech), MechMove(mech),
00192 args[0])) < 0)
00193 return -1;
00194 l = atoi(args[1]);
00195 if(l <= 0 || l > CritsInLoc(mech, *loc))
00196 return -4;
00197 *pos = l - 1;
00198 } else {
00199
00200 if(args[0][0] < '0' || args[0][0] > '9')
00201 return -1;
00202 l = atoi(args[0]);
00203 if(l < 0)
00204 return -1;
00205 if((t = FindWeaponNumberOnMech(mech, l, loc, pos)) == -1)
00206 return -1;
00207 }
00208 t = GetPartType(mech, *loc, *pos);
00209 if(brand != NULL && argc > 1 && !atoi(args[argc - 1])) {
00210 if(!find_matching_long_part(args[argc - 1], &c, &pi, &pb))
00211 return -2;
00212 if(pi != t)
00213 return -3;
00214 *brand = pb;
00215 } else if(brand != NULL)
00216 *brand = GetPartBrand(mech, *loc, *pos);
00217 return 0;
00218 }
00219
00220 int cheated_last = 0;
00221
00222 static void cheat_find_last(MUXEVENT * e)
00223 {
00224 int ofs = e->tick - muxevent_tick;
00225 int amount = (((int) e->data2) % PLAYERPOS) / 16 - 1;
00226
00227 switch (e->type) {
00228 case EVENT_REPAIR_FIXI:
00229 ofs += amount * FIXINTERNAL_TIME * TECH_TICK;
00230 break;
00231 case EVENT_REPAIR_FIX:
00232 ofs += amount * FIXARMOR_TIME * TECH_TICK;
00233 break;
00234 }
00235 if(ofs > cheated_last)
00236 cheated_last = ofs;
00237 }
00238
00239 int figure_latest_tech_event(MECH * mech)
00240 {
00241 int i;
00242
00243 cheated_last = 0;
00244 for(i = FIRST_TECH_EVENT; i <= LAST_TECH_EVENT; i++)
00245 muxevent_gothru_type_data(i, (void *) mech, cheat_find_last);
00246 return cheated_last;
00247 }