src/hcode/btech/mech.tech.commands.c

Go to the documentation of this file.
00001 /*
00002  * Author: Markus Stenberg <fingon@iki.fi>
00003  *
00004  *  Copyright (c) 1996 Markus Stenberg
00005  *  Copyright (c) 1998-2002 Thomas Wouters
00006  *  Copyright (c) 2000-2002 Cord Awtry
00007  *       All rights reserved
00008  */
00009 
00010 #include <math.h>
00011 #include <string.h>
00012 #include "mech.h"
00013 #include "muxevent.h"
00014 #include "mech.events.h"
00015 #include "mech.tech.h"
00016 #include "failures.h"
00017 #include "p.mech.utils.h"
00018 #include "p.mech.tech.h"
00019 #include "p.mech.consistency.h"
00020 #include "p.mech.tech.do.h"
00021 #include "p.bsuit.h"
00022 
00023 #define my_parsepart(loc,part) \
00024 switch (tech_parsepart(mech, buffer, loc, part,NULL)) \
00025 { case -1: notify(player, "Invalid section!");return; \
00026 case -2: notify(player, "Invalid part!");return; }
00027 
00028 #define my_parsepart2(loc,part,brand) \
00029 switch (tech_parsepart(mech, buffer, loc, part,brand)) \
00030 { case -1: notify(player, "Invalid section!");return; \
00031 case -2: notify(player, "Invalid part!");return; }
00032 
00033 #define my_parsegun(loc,part,brand) \
00034 switch (tech_parsegun(mech, buffer, loc, part, brand)) \
00035 { case -1: notify(player, "Invalid gun #!");return; \
00036   case -2: notify(player, "Invalid object to replace with!");return; \
00037   case -3: notify(player, "Invalid object type - not matching with original.");return; \
00038   case -4: notify(player, "Invalid gun location - subscript out of range.");return; }
00039 
00040 #define ClanMod(num) \
00041   MAX(1, (((num) / ((MechSpecials(mech) & CLAN_TECH) ? 2 : 1))))
00042 
00043 static int tmp_flag = 0;
00044 static int tmp_loc;
00045 static int tmp_part;
00046 
00047 static void tech_check_locpart(MUXEVENT * e)
00048 {
00049         int loc, pos;
00050         int l = (int) e->data2;
00051 
00052         UNPACK_LOCPOS(l, loc, pos);
00053         if(loc == tmp_loc && pos == tmp_part)
00054                 tmp_flag++;
00055 }
00056 
00057 static void tech_check_loc(MUXEVENT * e)
00058 {
00059         int loc;
00060 
00061         loc = (((int) e->data2) % 16);
00062         if(loc == tmp_loc)
00063                 tmp_flag++;
00064 }
00065 
00066 #define CHECK(t,fun) \
00067   tmp_flag=0;tmp_loc=loc;tmp_part = part; \
00068   muxevent_gothru_type_data(t, (void *) mech, fun); \
00069   return tmp_flag
00070 
00071 #define CHECKL(t,fun) \
00072   tmp_flag=0;tmp_loc=loc; \
00073   muxevent_gothru_type_data(t, (void *) mech, fun); \
00074   return tmp_flag
00075 
00076 #define CHECK2(t,t2,fun) \
00077   tmp_flag=0;tmp_loc=loc;tmp_part = part; \
00078   muxevent_gothru_type_data(t, (void *) mech, fun); \
00079   muxevent_gothru_type_data(t2, (void *) mech, fun); \
00080   return tmp_flag
00081 
00082 /* Replace/reload */
00083 int SomeoneRepairing_s(MECH * mech, int loc, int part, int t)
00084 {
00085         CHECK(t, tech_check_locpart);
00086 }
00087 
00088 #define DAT(t) \
00089 if (SomeoneRepairing_s(mech, loc, part, t)) return 1
00090 
00091 int SomeoneRepairing(MECH * mech, int loc, int part)
00092 {
00093         DAT(EVENT_REPAIR_RELO);
00094         DAT(EVENT_REPAIR_REPL);
00095         DAT(EVENT_REPAIR_REPLG);
00096         DAT(EVENT_REPAIR_REPAP);
00097         DAT(EVENT_REPAIR_REPAG);
00098         DAT(EVENT_REPAIR_MOB);
00099         DAT(EVENT_REPAIR_REPENHCRIT);
00100         return 0;
00101 }
00102 
00103 /* Fixinternal/armor */
00104 int SomeoneFixingA(MECH * mech, int loc)
00105 {
00106         CHECKL(EVENT_REPAIR_FIX, tech_check_loc);
00107 }
00108 
00109 int SomeoneFixingI(MECH * mech, int loc)
00110 {
00111         CHECKL(EVENT_REPAIR_FIXI, tech_check_loc);
00112 }
00113 
00114 int SomeoneFixing(MECH * mech, int loc)
00115 {
00116         return SomeoneFixingA(mech, loc) || SomeoneFixingI(mech, loc);
00117 }
00118 
00119 /* Reattach */
00120 int SomeoneAttaching(MECH * mech, int loc)
00121 {
00122         CHECKL(EVENT_REPAIR_REAT, tech_check_loc);
00123 }
00124 
00125 int SomeoneReplacingSuit(MECH * mech, int loc)
00126 {
00127         CHECKL(EVENT_REPAIR_REPSUIT, tech_check_loc);
00128 }
00129 
00130 /* Reseal
00131  *
00132  * Added by Kipsta
00133  * 8/4/99
00134  */
00135 
00136 int SomeoneResealing(MECH * mech, int loc)
00137 {
00138         CHECKL(EVENT_REPAIR_RESE, tech_check_loc);
00139 }
00140 
00141 int SomeoneScrappingLoc(MECH * mech, int loc)
00142 {
00143         CHECKL(EVENT_REPAIR_SCRL, tech_check_loc);
00144 }
00145 
00146 int SomeoneScrappingPart(MECH * mech, int loc, int part)
00147 {
00148         DAT(EVENT_REPAIR_SCRP);
00149         DAT(EVENT_REPAIR_SCRG);
00150         DAT(EVENT_REPAIR_UMOB);
00151         return 0;
00152 }
00153 
00154 #undef CHECK
00155 #undef CHECK2
00156 #undef DAT
00157 
00158 int CanScrapLoc(MECH * mech, int loc)
00159 {
00160         tmp_flag = 0;
00161         tmp_loc = loc % 8;
00162         muxevent_gothru_type_data(EVENT_REPAIR_REPL, (void *) mech,
00163                                                           tech_check_loc);
00164         muxevent_gothru_type_data(EVENT_REPAIR_RELO, (void *) mech,
00165                                                           tech_check_loc);
00166         return !tmp_flag && !SomeoneFixing(mech, loc);
00167 }
00168 
00169 int CanScrapPart(MECH * mech, int loc, int part)
00170 {
00171         return !(SomeoneRepairing(mech, loc, part));
00172 }
00173 
00174 #define tech_gun_is_ok(a,b,c) !PartIsNonfunctional(a,b,c)
00175 
00176 extern char *silly_get_uptime_to_string(int);
00177 
00178 int ValidGunPos(MECH * mech, int loc, int pos)
00179 {
00180         unsigned char weaparray_f[MAX_WEAPS_SECTION];
00181         unsigned char weapdata_f[MAX_WEAPS_SECTION];
00182         int critical_f[MAX_WEAPS_SECTION];
00183         int i, num_weaps_f;
00184 
00185         if((num_weaps_f =
00186                 FindWeapons_Advanced(mech, loc, weaparray_f, weapdata_f,
00187                                                          critical_f, 1)) < 0)
00188                 return 0;
00189         for(i = 0; i < num_weaps_f; i++)
00190                 if(critical_f[i] == pos)
00191                         return 1;
00192         return 0;
00193 }
00194 
00195 void tech_checkstatus(dbref player, void *data, char *buffer)
00196 {
00197         MECH *mech = (MECH *) data;
00198         int i = figure_latest_tech_event(mech);
00199         char *ms;
00200 
00201         DOCHECK(!i, "The mech's ready to rock!");
00202         ms = silly_get_uptime_to_string(game_lag_time(i));
00203         notify_printf(player, "The 'mech has approximately %s until done.", ms);
00204 }
00205 
00206 TECHCOMMANDH(tech_removegun)
00207 {
00208         TECHCOMMANDB;
00209         TECHCOMMANDC;
00210         my_parsegun(&loc, &part, NULL);
00211         DOCHECK(SectIsDestroyed(mech, loc),
00212                         "That part's blown off! You can assume the gun's gone too!");
00213         DOCHECK(!IsWeapon(GetPartType(mech, loc, part)), "That's no gun!");
00214         DOCHECK(PartIsDestroyed(mech, loc, part), "That gun's gone already!");
00215         DOCHECK(!ValidGunPos(mech, loc, part),
00216                         "You can't remove middle of a gun!");
00217         DOCHECK(SomeoneScrappingPart(mech, loc, part),
00218                         "Someone's scrapping it already!");
00219         DOCHECK(!CanScrapPart(mech, loc, part),
00220                         "Someone's tinkering with it already!");
00221         DOCHECK(SomeoneScrappingLoc(mech, loc),
00222                         "Someone's scrapping that section - no additional removals are possible!");
00223         /* Ok.. Everything's valid (we hope). */
00224         if(tech_weapon_roll(player, mech, REMOVEG_DIFFICULTY) < 0) {
00225                 START
00226                         ("Ack! Your attempt is far from perfect, you try to recover the gun..");
00227                 if(tech_weapon_roll(player, mech, REMOVEG_DIFFICULTY) < 0) {
00228                         START("No good. Consider the part gone.");
00229                         FAKEREPAIR(REMOVEG_TIME * ClanMod(GetWeaponCrits(mech,
00230                                                                                                                          Weapon2I
00231                                                                                                                          (GetPartType
00232                                                                                                                           (mech, loc,
00233                                                                                                                            part)))),
00234                                            EVENT_REPAIR_SCRG, mech, PACK_LOCPOS_E(loc, part,
00235                                                                                                                           mod));
00236                         mod = 3;
00237                         return;
00238                 }
00239         }
00240         START("You start removing the gun..");
00241         STARTREPAIR(REMOVEG_TIME * ClanMod(GetWeaponCrits(mech,
00242                                                                                                           Weapon2I(GetPartType
00243                                                                                                                            (mech, loc,
00244                                                                                                                                 part)))),
00245                                 mech, PACK_LOCPOS_E(loc, part, mod),
00246                                 muxevent_tickmech_removegun, EVENT_REPAIR_SCRG);
00247 }
00248 
00249 TECHCOMMANDH(tech_removepart)
00250 {
00251         TECHCOMMANDB;
00252         TECHCOMMANDC;
00253         my_parsepart(&loc, &part);
00254         DOCHECK((t =
00255                          GetPartType(mech, loc, part)) == EMPTY,
00256                         "That location is empty!");
00257         DOCHECK(SectIsDestroyed(mech, loc),
00258                         "That part's blown off! You can assume the part's gone too!");
00259         DOCHECK(IsWeapon(t), "That's a gun - use removegun instead!");
00260         DOCHECK(PartIsDestroyed(mech, loc, part), "That part's gone already!");
00261         DOCHECK(IsCrap(GetPartType(mech, loc, part)),
00262                         "That type isn't scrappable!");
00263         DOCHECK(t == Special(ENDO_STEEL) ||
00264                         t == Special(FERRO_FIBROUS) || t == Special(STEALTH_ARMOR) ||
00265                         t == Special(HVY_FERRO_FIBROUS) || t == Special(LT_FERRO_FIBROUS),
00266                         "That type of item can't be removed!");
00267         DOCHECK(SomeoneScrappingPart(mech, loc, part),
00268                         "Someone's scrapping it already!");
00269         DOCHECK(SomeoneScrappingLoc(mech, loc),
00270                         "Someone's scrapping that section - no additional removals are possible!");
00271         DOCHECK(!CanScrapPart(mech, loc, part),
00272                         "Someone's tinkering with it already!");
00273         /* Ok.. Everything's valid (we hope). */
00274         START("You start removing the part..");
00275         if(tech_roll(player, mech, REMOVEP_DIFFICULTY) < 0) {
00276                 START
00277                         ("Ack! Your attempt is far from perfect, you try to recover the part..");
00278                 if(tech_roll(player, mech, REMOVEP_DIFFICULTY) < 0) {
00279                         START("No good. Consider the part gone.");
00280                         mod = 3;
00281                         FAKEREPAIR(REMOVEP_TIME, EVENT_REPAIR_SCRP, mech,
00282                                            PACK_LOCPOS_E(loc, part, mod));
00283                         return;
00284                 }
00285         }
00286         STARTREPAIR(REMOVEP_TIME, mech, PACK_LOCPOS_E(loc, part, mod),
00287                                 muxevent_tickmech_removepart, EVENT_REPAIR_SCRP);
00288 }
00289 
00290 #define CHECK_S(nloc) \
00291 if (!SectIsDestroyed(mech,nloc)) return 1; \
00292 if (Invalid_Scrap_Path(mech,nloc)) return 1
00293 
00294 #define CHECK(tloc,nloc) \
00295 case tloc: CHECK_S(nloc)
00296 
00297 int Invalid_Scrap_Path(MECH * mech, int loc)
00298 {
00299         if(loc < 0)
00300                 return 0;
00301         if(MechType(mech) != CLASS_MECH)
00302                 return 0;
00303         switch (loc) {
00304                 CHECK(CTORSO, HEAD);
00305                 CHECK_S(LTORSO);
00306                 CHECK_S(RTORSO);
00307                 break;
00308                 CHECK(LTORSO, LARM);
00309                 break;
00310                 CHECK(RTORSO, RARM);
00311                 break;
00312         }
00313         return 0;
00314 }
00315 
00316 #undef CHECK
00317 #undef CHECK_S
00318 
00319 TECHCOMMANDH(tech_removesection)
00320 {
00321         TECHCOMMANDB;
00322         TECHCOMMANDC;
00323         my_parsepart(&loc, NULL);
00324         DOCHECK(SectIsDestroyed(mech, loc), "That section's gone already!");
00325         DOCHECK(Invalid_Scrap_Path(mech, loc),
00326                         "You need to remove the outer sections first!");
00327         DOCHECK(SomeoneScrappingLoc(mech, loc),
00328                         "Someone's scrapping it already!");
00329         DOCHECK(!CanScrapLoc(mech, loc), "Someone's tinkering with it already!");
00330         /* Ok.. Everything's valid (we hope). */
00331         if(tech_roll(player, mech, REMOVES_DIFFICULTY) < 0)
00332                 mod = 3;
00333         START("You start removing the section..");
00334         STARTREPAIR(REMOVES_TIME, mech, PACK_LOCPOS_E(loc, 0, mod),
00335                                 muxevent_tickmech_removesection, EVENT_REPAIR_SCRL);
00336 }
00337 
00338 TECHCOMMANDH(tech_replacegun)
00339 {
00340         int brand = 0, ob = 0;
00341 
00342         TECHCOMMANDB;
00343         TECHCOMMANDC;
00344         my_parsegun(&loc, &part, &brand);
00345         DOCHECK(SectIsDestroyed(mech, loc),
00346                         "That part's blown off! Use reattach first!");
00347         DOCHECK(SectIsFlooded(mech, loc),
00348                         "That location has been flooded! Use reseal first!");
00349         DOCHECK(SomeoneRepairing(mech, loc, part),
00350                         "Someone's repairing that part already!");
00351         DOCHECK(!IsWeapon(GetPartType(mech, loc, part)), "That's no gun!");
00352         DOCHECK(!ValidGunPos(mech, loc, part),
00353                         "You can't replace middle of a gun!");
00354         DOCHECK(!PartIsNonfunctional(mech, loc, part), "That gun isn't hurtin'!");
00355         DOCHECK(SomeoneScrappingLoc(mech, loc),
00356                         "Someone's scrapping that section - no repairs are possible!");
00357         if(brand) {
00358                 ob = GetPartBrand(mech, loc, part);
00359                 SetPartBrand(mech, loc, part, brand);
00360         }
00361         DOTECH_LOCPOS(REPLACE_DIFFICULTY +
00362                                   WEAPTYPE_DIFFICULTY(GetPartType(mech, loc, part)),
00363                                   replaceg_fail, replaceg_succ, replace_econ,
00364                                   REPLACEGUN_TIME *
00365                                   ClanMod(GetWeaponCrits
00366                                                   (mech, Weapon2I(GetPartType(mech, loc, part)))),
00367                                   mech, PACK_LOCPOS_E(loc, part, brand),
00368                                   muxevent_tickmech_replacegun, EVENT_REPAIR_REPLG,
00369                                   "You start replacing the gun..", 1);
00370         if(brand)
00371                 SetPartBrand(mech, loc, part, ob);
00372 }
00373 
00374 TECHCOMMANDH(tech_repairgun)
00375 {
00376         int extra_hard = 0;
00377 
00378         TECHCOMMANDB;
00379         TECHCOMMANDC;
00380         /* Find the gun for us */
00381         my_parsegun(&loc, &part, NULL);
00382         DOCHECK(SectIsDestroyed(mech, loc),
00383                         "That part's blown off! Use reattach first!");
00384         DOCHECK(SectIsFlooded(mech, loc),
00385                         "That location has been flooded! Use reseal first!");
00386         DOCHECK(SomeoneRepairing(mech, loc, part),
00387                         "Someone's repairing that part already!");
00388         DOCHECK(!IsWeapon(GetPartType(mech, loc, part)), "That's no gun!");
00389         DOCHECK(!ValidGunPos(mech, loc, part),
00390                         "You can't repair middle of a gun!");
00391         DOCHECK(SomeoneScrappingPart(mech, loc, part),
00392                         "Someone's scrapping it already!");
00393         DOCHECK(SomeoneScrappingLoc(mech, loc),
00394                         "Someone's scrapping that section - no repairs are possible!");
00395         DOCHECK(PartIsDisabled(mech, loc, part), "That gun can't be fixed yet!");
00396 
00397         if(PartIsDestroyed(mech, loc, part)) {
00398                 if(GetWeaponCrits(mech, Weapon2I(GetPartType(mech, loc,
00399                                                                                                          part))) < 5 ||
00400                    PartIsDestroyed(mech, loc, part + 1)) {
00401                         notify(player, "That gun is gone for good!");
00402                         return;
00403                 }
00404                 extra_hard = 1;
00405         } else if(!PartTempNuke(mech, loc, part)) {
00406                 notify(player, "That gun isn't hurtin'!");
00407                 return;
00408         }
00409 
00410         DOTECH_LOCPOS(REPAIR_DIFFICULTY + WEAPTYPE_DIFFICULTY(GetPartType(mech,
00411                                                                                                                                           loc,
00412                                                                                                                                           part)) +
00413                                   extra_hard, repairg_fail, repairg_succ, repair_econ,
00414                                   REPAIRGUN_TIME, mech, PACK_LOCPOS(loc, part),
00415                                   muxevent_tickmech_repairgun, EVENT_REPAIR_REPAP,
00416                                   "You start repairing the weapon..", 1);
00417 }
00418 
00419 TECHCOMMANDH(tech_fixenhcrit)
00420 {
00421         int extra_hard = 0;
00422 
00423         TECHCOMMANDB;
00424         TECHCOMMANDC;
00425         /* Find the gun for us */
00426         my_parsegun(&loc, &part, NULL);
00427         DOCHECK(SectIsDestroyed(mech, loc),
00428                         "That part's blown off! Use reattach first!");
00429         DOCHECK(SectIsFlooded(mech, loc),
00430                         "That location has been flooded! Use reseal first!");
00431         DOCHECK(SomeoneRepairing(mech, loc, part),
00432                         "Someone's repairing that part already!");
00433         DOCHECK(!IsWeapon(GetPartType(mech, loc, part)), "That's no gun!");
00434         DOCHECK(SomeoneScrappingPart(mech, loc, part),
00435                         "Someone's scrapping it already!");
00436         DOCHECK(SomeoneScrappingLoc(mech, loc),
00437                         "Someone's scrapping that section - no repairs are possible!");
00438         DOCHECK(PartIsDisabled(mech, loc, part), "That gun can't be fixed yet!");
00439 
00440         if(!PartIsDamaged(mech, loc, part)) {
00441                 notify(player, "That gun isn't damaged!");
00442                 return;
00443         }
00444 
00445         DOTECH_LOCPOS(ENHCRIT_DIFFICULTY,
00446                                   repairenhcrit_fail,
00447                                   repairenhcrit_succ,
00448                                   repairenhcrit_econ,
00449                                   REPAIRENHCRIT_TIME,
00450                                   mech,
00451                                   PACK_LOCPOS(loc, part),
00452                                   muxevent_tickmech_repairenhcrit,
00453                                   EVENT_REPAIR_REPENHCRIT,
00454                                   "You start repairing the weapon...", 1);
00455 }
00456 
00457 TECHCOMMANDH(tech_replacepart)
00458 {
00459         TECHCOMMANDB;
00460 
00461         TECHCOMMANDC;
00462         my_parsepart(&loc, &part);
00463         DOCHECK((t =
00464                          GetPartType(mech, loc, part)) == EMPTY,
00465                         "That location is empty!");
00466         DOCHECK(!PartIsNonfunctional(mech, loc, part),
00467                         "That part looks ok to me..");
00468         DOCHECK(IsCrap(GetPartType(mech, loc, part)), "That part isn't hurtin'!");
00469         DOCHECK(IsWeapon(t), "That's a weapon! Use replacegun instead.");
00470         DOCHECK(SectIsDestroyed(mech, loc),
00471                         "That part's blown off! Use reattach first!");
00472         DOCHECK(SectIsFlooded(mech, loc),
00473                         "That location has been flooded! Use reseal first!");
00474         DOCHECK(SomeoneRepairing(mech, loc, part),
00475                         "Someone's repairing that part already!");
00476         DOCHECK(SomeoneScrappingLoc(mech, loc),
00477                         "Someone's scrapping that section - no repairs are possible!");
00478         DOTECH_LOCPOS(REPLACE_DIFFICULTY +
00479                                   PARTTYPE_DIFFICULTY(GetPartType(mech, loc, part)),
00480                                   replacep_fail, replacep_succ, replace_econ,
00481                                   REPLACEPART_TIME, mech, PACK_LOCPOS(loc, part),
00482                                   muxevent_tickmech_repairpart, EVENT_REPAIR_REPL,
00483                                   "You start replacing the part..", 0);
00484 }
00485 
00486 TECHCOMMANDH(tech_repairpart)
00487 {
00488         TECHCOMMANDB;
00489 
00490         TECHCOMMANDC;
00491         my_parsepart(&loc, &part);
00492         DOCHECK((t =
00493                          GetPartType(mech, loc, part)) == EMPTY,
00494                         "That location is empty!");
00495         DOCHECK(PartIsDestroyed(mech, loc, part), "That part is gone for good!");
00496         DOCHECK(PartIsDisabled(mech, loc, part),
00497                         "That part can't be repaired yet!");
00498         DOCHECK(!PartTempNuke(mech, loc, part), "That part isn't hurtin'!");
00499         DOCHECK(IsCrap(GetPartType(mech, loc, part)), "That part isn't hurtin'!");
00500         DOCHECK(IsWeapon(t), "That's a weapon! Use repairgun instead.");
00501         DOCHECK(SectIsDestroyed(mech, loc),
00502                         "That part's blown off! Use reattach first!");
00503         DOCHECK(SectIsFlooded(mech, loc),
00504                         "That location has been flooded! Use reseal first!");
00505         DOCHECK(SomeoneRepairing(mech, loc, part),
00506                         "Someone's repairing that part already!");
00507         DOCHECK(SomeoneScrappingLoc(mech, loc),
00508                         "Someone's scrapping that section - no repairs are possible!");
00509         DOTECH_LOCPOS(REPAIR_DIFFICULTY + PARTTYPE_DIFFICULTY(GetPartType(mech,
00510                                                                                                                                           loc,
00511                                                                                                                                           part)),
00512                                   repairp_fail, repairp_succ, repair_econ, REPAIRPART_TIME,
00513                                   mech, PACK_LOCPOS(loc, part), muxevent_tickmech_repairpart,
00514                                   EVENT_REPAIR_REPAP, "You start repairing the part..", 0);
00515 }
00516 
00517 TECHCOMMANDH(tech_toggletype)
00518 {
00519         int atype;
00520 
00521         TECHCOMMANDB;
00522 
00523         DOCHECK((!Wizard(player)) && In_Character(mech->mynum),
00524                         "This command only works in simpods!");
00525         my_parsepart2(&loc, &part, &atype);
00526         DOCHECK(!IsAmmo((t = GetPartType(mech, loc, part))), "That's no ammo!");
00527         DOCHECK(PartIsNonfunctional(mech, loc, part) ||
00528                         PartIsDisabled(mech, loc, part),
00529                         "The ammo compartment is nonfunctional!");
00530         DOCHECK(!atype,
00531                         "You need to give a type to toggle to (use - for normal)");
00532         DOCHECK((t =
00533                          (valid_ammo_mode(mech, loc, part, atype))) < 0,
00534                         "That is invalid ammo type for this weapon!");
00535         GetPartAmmoMode(mech, loc, part) &= ~(AMMO_MODES);
00536         GetPartAmmoMode(mech, loc, part) |= t;
00537         SetPartData(mech, loc, part, FullAmmo(mech, loc, part));
00538         mech_notify(mech, MECHALL, "Ammo toggled.");
00539 }
00540 
00541 TECHCOMMANDH(tech_reload)
00542 {
00543         int atype;
00544 
00545         TECHCOMMANDB;
00546         TECHCOMMANDD;
00547         my_parsepart2(&loc, &part, &atype);
00548         DOCHECK(!IsAmmo((t = GetPartType(mech, loc, part))), "That's no ammo!");
00549         DOCHECK(PartIsNonfunctional(mech, loc, part),
00550                         "The ammo compartment is destroyed ; repair/replacepart it first.");
00551         DOCHECK(PartIsDisabled(mech, loc, part),
00552                         "The ammo compartment is disabled ; repair/replacepart it first.");
00553         DOCHECK((now = GetPartData(mech, loc, part)) == (full =
00554                                                                                                          FullAmmo(mech, loc,
00555                                                                                                                           part)),
00556                         "That particular ammo compartment doesn't need reloading.");
00557         DOCHECK(SomeoneRepairing(mech, loc, part),
00558                         "Someone's playing with that part already!");
00559         DOCHECK(SectIsDestroyed(mech, loc),
00560                         "That part's blown off! Use reattach first!");
00561         DOCHECK(SectIsFlooded(mech, loc),
00562                         "That location has been flooded! Use reseal first!");
00563         DOCHECK(SomeoneScrappingLoc(mech, loc),
00564                         "Someone's scrapping that section - no repairs are possible!");
00565         if(atype) {
00566                 DOCHECK((t =
00567                                  (valid_ammo_mode(mech, loc, part, atype))) < 0,
00568                                 "That is invalid ammo type for this weapon!");
00569                 SetPartData(mech, loc, part, 0);
00570                 GetPartAmmoMode(mech, loc, part) &= ~(AMMO_MODES);
00571                 GetPartAmmoMode(mech, loc, part) |= t;
00572         }
00573         change = 0;
00574         DOTECH_LOCPOS_VAL(RELOAD_DIFFICULTY, reload_fail, reload_succ,
00575                                           reload_econ, &change, RELOAD_TIME, mech,
00576                                           PACK_LOCPOS_E(loc, part, change),
00577                                           muxevent_tickmech_reload, EVENT_REPAIR_RELO,
00578                                           "You start reloading the ammo compartment..");
00579 }
00580 
00581 TECHCOMMANDH(tech_unload)
00582 {
00583         TECHCOMMANDB;
00584 
00585         TECHCOMMANDD;
00586         my_parsepart(&loc, &part);
00587         DOCHECK(!IsAmmo((t = GetPartType(mech, loc, part))), "That's no ammo!");
00588         DOCHECK(PartIsNonfunctional(mech, loc, part),
00589                         "The ammo compartment is destroyed ; repair/replacepart it first.");
00590         DOCHECK(PartIsDisabled(mech, loc, part),
00591                         "The ammo compartment is disabled ; repair/replacepart it first.");
00592         DOCHECK(!(now =
00593                           GetPartData(mech, loc, part)),
00594                         "That particular ammo compartment is empty already.");
00595         DOCHECK(SomeoneRepairing(mech, loc, part),
00596                         "Someone's playing with that part already!");
00597         DOCHECK(SectIsDestroyed(mech, loc),
00598                         "That part's blown off! Use reattach first!");
00599         DOCHECK(SectIsFlooded(mech, loc),
00600                         "That location has been flooded! Use reseal first!");
00601         DOCHECK(SomeoneScrappingLoc(mech, loc),
00602                         "Someone's scrapping that section - no repairs are possible!");
00603         if((full = FullAmmo(mech, loc, part)) == now)
00604                 change = 2;
00605         else
00606                 change = 1;
00607         if(tech_roll(player, mech, REMOVES_DIFFICULTY) < 0)
00608                 mod = 3;
00609         START("You start unloading the ammo compartment..");
00610         STARTREPAIR(RELOAD_TIME, mech, PACK_LOCPOS_E(loc, part, change),
00611                                 muxevent_tickmech_reload, EVENT_REPAIR_RELO);
00612 }
00613 
00614 TECHCOMMANDH(tech_fixarmor)
00615 {
00616         int ochange;
00617 
00618         TECHCOMMANDB;
00619 
00620         TECHCOMMANDD;
00621         DOCHECK(tech_parsepart_advanced(mech, buffer, &loc, NULL, NULL, 1) < 0,
00622                         "Invalid section!");
00623         if(loc >= 8) {
00624                 from = GetSectRArmor(mech, loc % 8);
00625                 to = GetSectORArmor(mech, loc % 8);
00626         } else {
00627                 from = GetSectArmor(mech, loc);
00628                 to = GetSectOArmor(mech, loc);
00629         }
00630         DOCHECK(SectIsDestroyed(mech, loc % 8),
00631                         "That part's blown off! Use reattach first!");
00632         DOCHECK(SectIsFlooded(mech, loc % 8),
00633                         "That location has been flooded! Use reseal first!");
00634         DOCHECK(SomeoneFixingA(mech, loc) ||
00635                         SomeoneFixingI(mech, loc % 8),
00636                         "Someone's repairing that section already!");
00637         DOCHECK(GetSectInt(mech, loc % 8) != GetSectOInt(mech, loc % 8),
00638                         "The internals need to be fixed first!");
00639         DOCHECK(SomeoneScrappingLoc(mech, loc),
00640                         "Someone's scrapping that section - no repairs are possible!");
00641         from = MIN(to, from);
00642         DOCHECK(from == to, "The location doesn't need armor repair!");
00643         change = to - from;
00644         ochange = change;
00645         DOTECH_LOC_VAL_S(FIXARMOR_DIFFICULTY, fixarmor_fail, fixarmor_succ,
00646                                          fixarmor_econ, &change, FIXARMOR_TIME * ochange, loc,
00647                                          EVENT_REPAIR_FIX, mech, "You start fixing the armor..");
00648         STARTIREPAIR(FIXARMOR_TIME * change, mech, (change * 16 + loc),
00649                                  muxevent_tickmech_repairarmor, EVENT_REPAIR_FIX, change);
00650 }
00651 
00652 TECHCOMMANDH(tech_fixinternal)
00653 {
00654         TECHCOMMANDB int ochange;
00655 
00656         TECHCOMMANDC;
00657         my_parsepart(&loc, NULL);
00658         from = GetSectInt(mech, loc);
00659         to = GetSectOInt(mech, loc);
00660         DOCHECK(from == to, "The location doesn't need internals' repair!");
00661         change = to - from;
00662         DOCHECK(SectIsDestroyed(mech, loc),
00663                         "That part's blown off! Use reattach first!");
00664         DOCHECK(SectIsFlooded(mech, loc),
00665                         "That location has been flooded! Use reseal first!");
00666         DOCHECK(SomeoneFixing(mech, loc),
00667                         "Someone's repairing that section already!");
00668         DOCHECK(SomeoneScrappingLoc(mech, loc),
00669                         "Someone's scrapping that section - no repairs are possible!");
00670         ochange = change;
00671         DOTECH_LOC_VAL_S(FIXINTERNAL_DIFFICULTY, fixinternal_fail,
00672                                          fixinternal_succ, fixinternal_econ, &change,
00673                                          FIXINTERNAL_TIME * ochange, loc, EVENT_REPAIR_FIX, mech,
00674                                          "You start fixing the internals..");
00675         STARTIREPAIR(FIXINTERNAL_TIME * change, mech, (change * 16 + loc),
00676                                  muxevent_tickmech_repairinternal, EVENT_REPAIR_FIXI, change);
00677 }
00678 
00679 #define CHECK(tloc,nloc) \
00680 case tloc:if (SectIsDestroyed(mech,nloc))return 1;break;
00681 
00682 int Invalid_Repair_Path(MECH * mech, int loc)
00683 {
00684         if(MechType(mech) != CLASS_MECH)
00685                 return 0;
00686         switch (loc) {
00687                 CHECK(HEAD, CTORSO);
00688                 CHECK(LTORSO, CTORSO);
00689                 CHECK(RTORSO, CTORSO);
00690                 CHECK(LARM, LTORSO);
00691                 CHECK(RARM, RTORSO);
00692                 CHECK(LLEG, CTORSO);
00693                 CHECK(RLEG, CTORSO);
00694         }
00695         return 0;
00696 }
00697 
00698 int unit_is_fixable(MECH * mech)
00699 {
00700         int i;
00701 
00702         for(i = 0; i < NUM_SECTIONS; i++) {
00703                 if(!GetSectOInt(mech, i))
00704                         continue;
00705                 if(!SectIsDestroyed(mech, i))
00706                         continue;
00707                 if(MechType(mech) == CLASS_MECH)
00708                         if(i == CTORSO)
00709                                 return 0;
00710                 if(MechType(mech) == CLASS_VTOL)
00711                         if(i != ROTOR)
00712                                 return 0;
00713                 if(MechType(mech) == CLASS_VEH_GROUND)
00714                         if(i != TURRET)
00715                                 return 0;
00716         }
00717         return 1;
00718 };
00719 
00720 TECHCOMMANDH(tech_reattach)
00721 {
00722         TECHCOMMANDB;
00723 
00724         TECHCOMMANDC;
00725         my_parsepart(&loc, NULL);
00726         DOCHECK(MechType(mech) == CLASS_BSUIT,
00727                         "You can't reattach a Battlesuit! Use 'replacesuit'!");
00728         DOCHECK(!SectIsDestroyed(mech, loc), "That section isn't destroyed!");
00729         DOCHECK(Invalid_Repair_Path(mech, loc),
00730                         "You need to reattach adjacent locations first!");
00731         DOCHECK(SomeoneAttaching(mech, loc),
00732                         "Someone's attaching that section already!");
00733         DOCHECK(!unit_is_fixable(mech),
00734                         "You see nothing to reattach it to (read:unit is cored).");
00735         DOTECH_LOC(REATTACH_DIFFICULTY, reattach_fail, reattach_succ,
00736                            reattach_econ, REATTACH_TIME, mech, loc,
00737                            muxevent_tickmech_reattach, EVENT_REPAIR_REAT,
00738                            "You start replacing the section..");
00739 }
00740 
00741 TECHCOMMANDH(tech_replacesuit)
00742 {
00743         int wSuits = 0;
00744 
00745         TECHCOMMANDB;
00746 
00747         TECHCOMMANDC;
00748         my_parsepart(&loc, NULL);
00749         DOCHECK(MechType(mech) != CLASS_BSUIT,
00750                         "You can only use 'replacesuit' on a battlesuit unit!");
00751 
00752         wSuits = CountBSuitMembers(mech);
00753 
00754         DOCHECK(MechMaxSuits(mech) <= wSuits,
00755                         tprintf
00756                         ("This %s is already full! This %s only consists of %d suits!",
00757                          GetLCaseBSuitName(mech), GetLCaseBSuitName(mech),
00758                          MechMaxSuits(mech)));
00759         DOCHECK((loc >= MechMaxSuits(mech)) ||
00760                         (loc < 0),
00761                         tprintf("Invalid suit! This %s only consists of %d suits!",
00762                                         GetLCaseBSuitName(mech), MechMaxSuits(mech)));
00763 
00764         DOCHECK(!SectIsDestroyed(mech, loc), "That suit isn't destroyed!");
00765 
00766         DOCHECK(SomeoneReplacingSuit(mech, loc),
00767                         "Someone's already rebuilding that suit!");
00768         DOCHECK(wSuits <= 0,
00769                         "You are unable to replace the suits here! None of the buggers are still alive!");
00770         DOTECH_LOC(REPLACESUIT_DIFFICULTY, replacesuit_fail, replacesuit_succ,
00771                            replacesuit_econ, REPLACESUIT_TIME, mech, loc,
00772                            muxevent_tickmech_replacesuit, EVENT_REPAIR_REPSUIT,
00773                            "You start replacing the missing suit.");
00774 }
00775 
00776 /*
00777  * Reseal
00778  * Added by Kipsta
00779  * 8/4/99
00780  */
00781 
00782 TECHCOMMANDH(tech_reseal)
00783 {
00784         TECHCOMMANDB;
00785 
00786         TECHCOMMANDC;
00787         my_parsepart(&loc, NULL);
00788         DOCHECK(SectIsDestroyed(mech, loc), "That section is destroyed!");
00789         DOCHECK(!SectIsFlooded(mech, loc), "That has not been flooded!");
00790         DOCHECK(Invalid_Repair_Path(mech, loc),
00791                         "You need to reattach adjacent locations first!");
00792         DOCHECK(SomeoneResealing(mech, loc),
00793                         "Someone's sealing that section already!");
00794         DOTECH_LOC(RESEAL_DIFFICULTY, reseal_fail, reseal_succ, reseal_econ,
00795                            RESEAL_TIME, mech, loc, muxevent_tickmech_reseal,
00796                            EVENT_REPAIR_RESE, "You start resealing the section.");
00797 }
00798 
00799 TECHCOMMANDH(tech_magic)
00800 {
00801         TECHCOMMANDB;
00802 
00803         TECHCOMMANDC;
00804         notify(player, "Doing the magic..");
00805         do_magic(mech);
00806         mech_int_check(mech, 1);
00807         notify(player, "Done!");
00808 }

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