src/hcode/btech/mech.tech.events.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 "config.h"
00011 
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.econ.h"
00018 #include "p.mech.utils.h"
00019 #include "p.mech.tech.do.h"
00020 #include "p.mech.status.h"
00021 
00022 #define VERBOSE_ENDS
00023 
00024 static int completely_intact_int(MECH * mech)
00025 {
00026         int i;
00027 
00028         for(i = 0; i < NUM_SECTIONS; i++)
00029                 if(!GetSectInt(mech, i) && GetSectOInt(mech, i))
00030                         return 0;
00031         return 1;
00032 }
00033 
00034 void muxevent_tickmech_removesection(MUXEVENT * e)
00035 {
00036         MECH *mech = (MECH *) e->data;
00037         int earg = (int) (e->data2) % PLAYERPOS;
00038         char buf[MBUF_SIZE];
00039         int loc, pos, extra;
00040 
00041         /* changed Special2I to Special on AddPartsM statements */
00042         UNPACK_LOCPOS_E(earg, loc, pos, extra);
00043 #ifndef BT_COMPLEXREPAIRS
00044         AddPartsM(mech, ProperInternal(mech), 0, (2 * GetSectInt(mech,
00045                                                                                                                          loc)) / extra);
00046         AddPartsM(mech, ProperArmor(mech), 0, (2 * GetSectArmor(mech,
00047                                                                                                                         loc)) / extra);
00048         AddPartsM(mech, Cargo(S_ELECTRONIC), 0, (GetSectInt(mech, loc)) / extra);
00049 #else
00050         AddPartsM(mech, loc, ProperInternal(mech), 0, (2 * GetSectInt(mech,
00051                                                                                                                                   loc)) /
00052                           extra);
00053         AddPartsM(mech, loc, ProperArmor(mech), 0,
00054                           (2 * GetSectArmor(mech, loc)) / extra);
00055         AddPartsM(mech, loc, Cargo(S_ELECTRONIC), 0,
00056                           (GetSectInt(mech, loc)) / extra);
00057 #endif
00058         mech_Detach(mech, loc);
00059         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00060         do {
00061                 int i = 0;
00062 
00063                 if(Destroyed(mech))
00064                         i = 1;
00065                 MechStatus(mech) &= ~DESTROYED;
00066                 mech_printf(mech, MECHALL, "%s has been removed.", buf);
00067                 if(i)
00068                         MechStatus(mech) |= DESTROYED;
00069         } while (0);
00070 }
00071 
00072 void muxevent_tickmech_removegun(MUXEVENT * e)
00073 {
00074         MECH *mech = (MECH *) e->data;
00075         int earg = (int) (e->data2) % PLAYERPOS;
00076         int loc, pos, i, extra;
00077         char buf[MBUF_SIZE];
00078 
00079         UNPACK_LOCPOS_E(earg, loc, pos, extra);
00080         for(i = pos;
00081                 i < (pos + GetWeaponCrits(mech, Weapon2I(GetPartType(mech, loc,
00082                                                                                                                          pos)))); i++)
00083                 DestroyPart(mech, loc, i);
00084         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00085         if(extra == 2 && (e->function != very_fake_func)) {
00086 #ifndef BT_COMPLEXREPAIRS
00087                 AddPartsM(mech, FindAmmoType(mech, loc, pos), GetPartBrand(mech,
00088                                                                                                                                    loc, pos),
00089                                   1);
00090 #else
00091                 AddPartsM(mech, loc, FindAmmoType(mech, loc, pos), GetPartBrand(mech,
00092                                                                                                                                                 loc,
00093                                                                                                                                                 pos),
00094                                   1);
00095 #endif
00096                 do {
00097                         int i = 0;
00098 
00099                         if(Destroyed(mech))
00100                                 i = 1;
00101                         MechStatus(mech) &= ~DESTROYED;
00102                         mech_printf(mech, MECHALL,
00103                                                 "%s from %s has been removed.", pos_part_name(mech,
00104                                                                                                                                           loc,
00105                                                                                                                                           pos),
00106                                                 buf);
00107                         if(i)
00108                                 MechStatus(mech) |= DESTROYED;
00109                 } while (0);
00110         } else {
00111                 do {
00112                         int i = 0;
00113 
00114                         if(Destroyed(mech))
00115                                 i = 1;
00116                         MechStatus(mech) &= ~DESTROYED;
00117                         mech_printf(mech, MECHALL,
00118                                                 "%s from %s has been removed and scrapped.",
00119                                                 pos_part_name(mech, loc, pos), buf);
00120                         if(i)
00121                                 MechStatus(mech) |= DESTROYED;
00122                 } while (0);
00123         }
00124 }
00125 
00126 void muxevent_tickmech_removepart(MUXEVENT * e)
00127 {
00128         MECH *mech = (MECH *) e->data;
00129         int earg = (int) (e->data2) % PLAYERPOS;
00130         int loc, pos, extra;
00131         char buf[MBUF_SIZE];
00132 
00133         UNPACK_LOCPOS_E(earg, loc, pos, extra);
00134         DestroyPart(mech, loc, pos);
00135         if(MechType(mech) == CLASS_MECH)
00136                 do_magic(mech);
00137         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00138         if(extra == 2 && (e->function != very_fake_func)) {
00139 #ifndef BT_COMPLEXREPAIRS
00140                 AddPartsM(mech, FindAmmoType(mech, loc, pos), GetPartBrand(mech,
00141                                                                                                                                    loc, pos),
00142                                   1);
00143 #else
00144                 AddPartsM(mech, loc, FindAmmoType(mech, loc, pos), GetPartBrand(mech,
00145                                                                                                                                                 loc,
00146                                                                                                                                                 pos),
00147                                   1);
00148 #endif
00149                 do {
00150                         int i = 0;
00151 
00152                         if(Destroyed(mech))
00153                                 i = 1;
00154                         MechStatus(mech) &= ~DESTROYED;
00155                         mech_printf(mech, MECHALL,
00156                                                 "%s from %s has been removed.", pos_part_name(mech,
00157                                                                                                                                           loc,
00158                                                                                                                                           pos),
00159                                                 buf);
00160                         if(i)
00161                                 MechStatus(mech) |= DESTROYED;
00162                 } while (0);
00163         } else {
00164                 do {
00165                         int i = 0;
00166 
00167                         if(Destroyed(mech))
00168                                 i = 1;
00169                         MechStatus(mech) &= ~DESTROYED;
00170                         mech_printf(mech, MECHALL,
00171                                                 "%s from %s has been removed and scrapped.",
00172                                                 pos_part_name(mech, loc, pos), buf);
00173                         if(i)
00174                                 MechStatus(mech) |= DESTROYED;
00175                 } while (0);
00176         }
00177 }
00178 
00179 void muxevent_tickmech_repairarmor(MUXEVENT * e)
00180 {
00181         MECH *mech = (MECH *) e->data;
00182         int earg = (int) (e->data2) % PLAYERPOS;
00183         int loc = earg % 16;
00184         int amount = (earg / 16) % 256;
00185         int player = ((int) e->data2) / PLAYERPOS;
00186         char buf[MBUF_SIZE];
00187 
00188         if(loc >= 8) {
00189                 SetSectRArmor(mech, loc % 8, MIN(GetSectRArmor(mech, loc % 8) + 1,
00190                                                                                  GetSectORArmor(mech, loc % 8)));
00191         } else {
00192                 SetSectArmor(mech, loc, MIN(GetSectArmor(mech, loc) + 1,
00193                                                                         GetSectOArmor(mech, loc)));
00194         }
00195         amount--;
00196         if(amount < 0)
00197                 return;
00198         if(amount <= 0) {
00199                 ArmorStringFromIndex(loc % 8, buf, MechType(mech), MechMove(mech));
00200                 if(loc >= 8) {
00201                         do {
00202                                 int i = 0;
00203 
00204                                 if(Destroyed(mech))
00205                                         i = 1;
00206                                 MechStatus(mech) &= ~DESTROYED;
00207                                 mech_printf(mech, MECHALL,
00208                                                         "%s's rear armor repairs have been finished.",
00209                                                         buf);
00210                                 if(i)
00211                                         MechStatus(mech) |= DESTROYED;
00212                         } while (0);
00213                 } else {
00214                         do {
00215                                 int i = 0;
00216 
00217                                 if(Destroyed(mech))
00218                                         i = 1;
00219                                 MechStatus(mech) &= ~DESTROYED;
00220                                 mech_printf(mech, MECHALL,
00221                                                         "%s's armor repairs have been finished.", buf);
00222                                 if(i)
00223                                         MechStatus(mech) |= DESTROYED;
00224                         } while (0);
00225                 }
00226 
00227                 if(MechType(mech) != CLASS_MECH && completely_intact_int(mech))
00228                         do_magic(mech);
00229                 return;
00230         }
00231         REPAIREVENT(FIXARMOR_TIME, mech, (amount * 16 + loc),
00232                                 muxevent_tickmech_repairarmor, EVENT_REPAIR_FIX);
00233 }
00234 
00235 void muxevent_tickmech_repairinternal(MUXEVENT * e)
00236 {
00237         MECH *mech = (MECH *) e->data;
00238         int earg = (int) (e->data2) % PLAYERPOS;
00239         int loc = earg % 16;
00240         int amount = (earg / 16) % 256;
00241         int player = ((int) e->data2) / PLAYERPOS;
00242         char buf[MBUF_SIZE];
00243 
00244         SetSectInt(mech, loc, GetSectInt(mech, loc) + 1);
00245         if(GetSectInt(mech, loc) > GetSectOInt(mech, loc))
00246                 SetSectInt(mech, loc, GetSectOInt(mech, loc));
00247         amount--;
00248         if(amount < 0)
00249                 return;
00250         if(amount <= 0) {
00251                 ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00252                 do {
00253                         int i = 0;
00254 
00255                         if(Destroyed(mech))
00256                                 i = 1;
00257                         MechStatus(mech) &= ~DESTROYED;
00258                         mech_printf(mech, MECHALL,
00259                                                 "%s's internal repairs have been finished.", buf);
00260                         if(i)
00261                                 MechStatus(mech) |= DESTROYED;
00262                 } while (0);
00263                 if(MechType(mech) != CLASS_MECH && completely_intact_int(mech))
00264                         do_magic(mech);
00265                 return;
00266         }
00267         REPAIREVENT(FIXINTERNAL_TIME, mech, (amount * 16 + loc),
00268                                 muxevent_tickmech_repairinternal, EVENT_REPAIR_FIXI);
00269 }
00270 
00271 void muxevent_tickmech_reattach(MUXEVENT * e)
00272 {
00273         MECH *mech = (MECH *) e->data;
00274         int earg = (int) (e->data2) % PLAYERPOS;
00275         char buf[MBUF_SIZE];
00276 
00277         /* Basically: Unset the limb destroyed, without doing a thing to
00278            damaged parts */
00279         mech_ReAttach(mech, earg);
00280         ArmorStringFromIndex(earg, buf, MechType(mech), MechMove(mech));
00281         if(completely_intact_int(mech))
00282                 do_magic(mech);
00283         do {
00284                 int i = 0;
00285 
00286                 if(Destroyed(mech))
00287                         i = 1;
00288                 MechStatus(mech) &= ~DESTROYED;
00289                 mech_printf(mech, MECHALL, "%s has been reattached.", buf);
00290                 if(i)
00291                         MechStatus(mech) |= DESTROYED;
00292         } while (0);
00293 }
00294 
00295 void muxevent_tickmech_replacesuit(MUXEVENT * e)
00296 {
00297         MECH *mech = (MECH *) e->data;
00298         int earg = (int) (e->data2) % PLAYERPOS;
00299         char buf[MBUF_SIZE];
00300 
00301         ArmorStringFromIndex(earg, buf, MechType(mech), MechMove(mech));
00302         mech_ReplaceSuit(mech, earg);
00303         do_magic(mech);
00304 
00305         mech_printf(mech, MECHALL, "%s has been replaced.", buf);
00306 }
00307 
00308 /*
00309  * Added for new flood code by Kipsta
00310  * 8/4/99
00311  */
00312 
00313 void muxevent_tickmech_reseal(MUXEVENT * e)
00314 {
00315         MECH *mech = (MECH *) e->data;
00316         int earg = (int) (e->data2) % PLAYERPOS;
00317         char buf[MBUF_SIZE];
00318 
00319         mech_ReSeal(mech, earg);
00320         ArmorStringFromIndex(earg, buf, MechType(mech), MechMove(mech));
00321         mech_printf(mech, MECHALL, "%s has been resealed.", buf);
00322 }
00323 
00324 void muxevent_tickmech_replacegun(MUXEVENT * e)
00325 {
00326         MECH *mech = (MECH *) e->data;
00327         int earg = (int) (e->data2) % PLAYERPOS;
00328         int loc, pos, i, brand;
00329         char buf[MBUF_SIZE];
00330 
00331         UNPACK_LOCPOS_E(earg, loc, pos, brand);
00332         for(i = pos;
00333                 i < (pos + GetWeaponCrits(mech, Weapon2I(GetPartType(mech, loc,
00334                                                                                                                          pos)))); i++) {
00335                 mech_RepairPart(mech, loc, i);
00336                 ClearTempNuke(mech, loc, i);
00337                 if(brand) {
00338                         SetPartBrand(mech, loc, i, brand);
00339                 }
00340         }
00341         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00342         do {
00343                 int i = 0;
00344 
00345                 if(Destroyed(mech))
00346                         i = 1;
00347                 MechStatus(mech) &= ~(DESTROYED);
00348                 mech_printf(mech, MECHALL, "%s on %s has been replaced.",
00349                                         pos_part_name(mech, loc, pos), buf);
00350                 if(i)
00351                         MechStatus(mech) |= DESTROYED;
00352         } while (0);
00353 }
00354 
00355 void muxevent_tickmech_repairgun(MUXEVENT * e)
00356 {
00357         MECH *mech = (MECH *) e->data;
00358         int earg = (int) (e->data2) % PLAYERPOS;
00359         int loc, pos, i;
00360         char buf[MBUF_SIZE];
00361 
00362         UNPACK_LOCPOS(earg, loc, pos);
00363         for(i = pos;
00364                 i < (pos + GetWeaponCrits(mech, Weapon2I(GetPartType(mech, loc,
00365                                                                                                                          pos)))); i++) {
00366                 mech_RepairPart(mech, loc, i);
00367                 ClearTempNuke(mech, loc, i);
00368         }
00369         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00370         do {
00371                 int i = 0;
00372 
00373                 if(Destroyed(mech))
00374                         i = 1;
00375                 MechStatus(mech) &= ~DESTROYED;
00376                 mech_printf(mech, MECHALL, "%s on %s has been repaired.",
00377                                         pos_part_name(mech, loc, pos), buf);
00378                 if(i)
00379                         MechStatus(mech) |= DESTROYED;
00380         } while (0);
00381 }
00382 
00383 void muxevent_tickmech_repairenhcrit(MUXEVENT * e)
00384 {
00385         MECH *mech = (MECH *) e->data;
00386         int earg = (int) (e->data2) % PLAYERPOS;
00387         int loc, pos;
00388         char buf[MBUF_SIZE];
00389         int wCritType, wWeapSize, wFirstCrit;
00390 
00391         UNPACK_LOCPOS(earg, loc, pos);
00392         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00393         mech_printf(mech, MECHALL, "%s on %s has been repaired.",
00394                                 pos_part_name(mech, loc, pos), buf);
00395         UnDamagePart(mech, loc, pos);
00396 
00397         /* Get the crit type */
00398         wCritType = GetPartType(mech, loc, pos);
00399 
00400         /* Get the max number of crits for this weapon */
00401         wWeapSize = GetWeaponCrits(mech, Weapon2I(wCritType));
00402 
00403         /* Find the first crit */
00404         wFirstCrit = FindFirstWeaponCrit(mech, loc, pos, 0, wCritType, wWeapSize);
00405 
00406         SetPartTempNuke(mech, loc, wFirstCrit, 0);
00407 }
00408 
00409 void muxevent_tickmech_repairpart(MUXEVENT * e)
00410 {
00411         MECH *mech = (MECH *) e->data;
00412         int earg = (int) (e->data2) % PLAYERPOS;
00413         int loc, pos;
00414         char buf[MBUF_SIZE];
00415 
00416         UNPACK_LOCPOS(earg, loc, pos);
00417         mech_RepairPart(mech, loc, pos);
00418         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00419         do {
00420                 int i = 0;
00421 
00422                 if(Destroyed(mech))
00423                         i = 1;
00424                 MechStatus(mech) &= ~DESTROYED;
00425                 mech_printf(mech, MECHALL, "%s on %s has been repaired.",
00426                                         pos_part_name(mech, loc, pos), buf);
00427                 if(i)
00428                         MechStatus(mech) |= DESTROYED;
00429         } while (0);
00430 }
00431 
00432 void muxevent_tickmech_reload(MUXEVENT * e)
00433 {
00434         MECH *mech = (MECH *) e->data;
00435         int earg = (int) (e->data2) % PLAYERPOS;
00436         int loc, pos, extra;
00437         char buf[MBUF_SIZE];
00438 
00439         UNPACK_LOCPOS_E(earg, loc, pos, extra);
00440         if(extra) {
00441                 SetPartData(mech, loc, pos, 0);
00442                 if(extra > 1)
00443 #ifndef BT_COMPLEXREPAIRS
00444                         AddPartsM(mech, FindAmmoType(mech, loc, pos),
00445                                           GetPartBrand(mech, loc, pos), 1);
00446 #else
00447                         AddPartsM(mech, loc, FindAmmoType(mech, loc, pos),
00448                                           GetPartBrand(mech, loc, pos), 1);
00449 #endif
00450         } else
00451                 mech_FillPartAmmo(mech, loc, pos);
00452         ArmorStringFromIndex(loc, buf, MechType(mech), MechMove(mech));
00453         do {
00454                 int i = 0;
00455 
00456                 if(Destroyed(mech))
00457                         i = 1;
00458                 MechStatus(mech) &= ~DESTROYED;
00459                 mech_printf(mech, MECHALL, "%s on %s has been %sloaded.",
00460                                         pos_part_name(mech, loc, pos), buf, extra ? "un" : "re");
00461                 if(i)
00462                         MechStatus(mech) |= DESTROYED;
00463         } while (0);
00464 }
00465 
00466 void muxevent_tickmech_mountbomb(MUXEVENT * e)
00467 {
00468 
00469 /*    MECH *mech = (MECH *) e->data; */
00470 
00471 /*    int earg = (int) (e->data2) % PLAYERPOS; */
00472 }
00473 
00474 void muxevent_tickmech_umountbomb(MUXEVENT * e)
00475 {
00476 
00477 /*    MECH *mech = (MECH *) e->data; */
00478 
00479 /*    int earg = (int) (e->data2) % PLAYERPOS; */
00480 }

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