src/hcode/btech/mech.tic.c

Go to the documentation of this file.
00001 /*
00002  * Author: Markus Stenberg <fingon@iki.fi>
00003  *
00004  *  Copyright (c) 1997 Markus Stenberg
00005  *  Copyright (c) 1998-2002 Thomas Wouters
00006  *  Copyright (c) 2000-2002 Cord Awtry 
00007  *       All rights reserved
00008  */
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <math.h>
00013 #include <sys/file.h>
00014 
00015 #include "mech.h"
00016 #include "coolmenu.h"
00017 #include "p.mech.utils.h"
00018 #include "p.mech.combat.h"
00019 #include "p.mech.build.h"
00020 #include "mech.events.h"
00021 
00022 int ftflag = 0;
00023 
00024 /*****************************************************************************/
00025 
00026 /* TIC Routines                                                              */
00027 
00028 /*****************************************************************************/
00029 
00030 int cleartic_sub_func(MECH * mech, dbref player, int low, int high)
00031 {
00032         int i, j;
00033 
00034         for(i = low; i <= high; i++) {
00035                 for(j = 0; j < TICLONGS; j++)
00036                         mech->tic[i][j] = 0;
00037                 notify_printf(player, "TIC #%d cleared!", i);
00038         }
00039         return 0;
00040 }
00041 
00042 void cleartic_sub(dbref player, MECH * mech, char *buffer)
00043 {
00044         int argc;
00045         char *args[3];
00046 
00047         DOCHECK((argc =
00048                          mech_parseattributes(buffer, args, 3)) != 1,
00049                         "Invalid number of arguments to function");
00050         multi_weap_sel(mech, player, args[0], 2, cleartic_sub_func);
00051 }
00052 
00053 static int present_tic;
00054 
00055 int addtic_sub_func(MECH * mech, dbref player, int low, int high)
00056 {
00057         int i, j;
00058 
00059         for(i = low; i <= high; i++) {
00060                 j = i / SINGLE_TICLONG_SIZE;
00061                 mech->tic[present_tic][j] |= 1 << (i % SINGLE_TICLONG_SIZE);
00062         }
00063         if(low != high)
00064                 notify_printf(player, "Weapons #%d - #%d added to TIC %d!", low,
00065                                           high, present_tic);
00066         else
00067                 notify_printf(player, "Weapon #%d added to TIC %d!", low,
00068                                           present_tic);
00069         return 0;
00070 }
00071 
00072 void addtic_sub(dbref player, MECH * mech, char *buffer)
00073 {
00074         int ticnum, argc;
00075         char *args[3];
00076 
00077         DOCHECK((argc =
00078                          mech_parseattributes(buffer, args, 3)) != 2,
00079                         "Invalid number of arguments to function!");
00080         ticnum = atoi(args[0]);
00081         DOCHECK(!(ticnum >= 0 && ticnum < NUM_TICS), "Invalid tic number!");
00082         present_tic = ticnum;
00083         multi_weap_sel(mech, player, args[1], 0, addtic_sub_func);
00084 }
00085 
00086 int deltic_sub_func(MECH * mech, dbref player, int low, int high)
00087 {
00088         int i, j;
00089 
00090         for(i = low; i <= high; i++) {
00091                 j = i / SINGLE_TICLONG_SIZE;
00092                 mech->tic[present_tic][j] &= ~(1 << (i % SINGLE_TICLONG_SIZE));
00093         }
00094         if(low != high)
00095                 notify_printf(player, "Weapons #%d - #%d removed from TIC %d!",
00096                                           low, high, present_tic);
00097         else
00098                 notify_printf(player, "Weapon #%d removed from TIC %d!", low,
00099                                           present_tic);
00100         return 0;
00101 }
00102 
00103 void deltic_sub(dbref player, MECH * mech, char *buffer)
00104 {
00105         int ticnum, argc;
00106         char *args[3];
00107 
00108         argc = mech_parseattributes(buffer, args, 3);
00109         DOCHECK(argc < 1 ||
00110                         argc > 2, "Invalid number of arguments to the function!");
00111         if(argc == 1) {
00112                 cleartic_sub(player, mech, buffer);
00113                 return;
00114         }
00115         ticnum = atoi(args[0]);
00116         DOCHECK(!(ticnum >= 0 && ticnum < NUM_TICS), "Invalid tic number!");
00117         present_tic = ticnum;
00118         multi_weap_sel(mech, player, args[1], 0, deltic_sub_func);
00119 }
00120 
00121 static char **temp_args;
00122 static int temp_argc;
00123 
00124 int firetic_sub_func(MECH * mech, dbref player, int low, int high)
00125 {
00126         int i, j, k, count, weapnum;
00127         MAP *mech_map = FindObjectsData(mech->mapindex);
00128         int f = Fallen(mech);
00129 
00130         for(i = low; i <= high; i++) {
00131                 notify_printf(player, "Firing weapons in tic #%d!", i);
00132                 count = 0;
00133                 for(k = 0; k < TICLONGS; k++)
00134                         if(mech->tic[i][k])
00135                                 for(j = 0; j < SINGLE_TICLONG_SIZE; j++)
00136                                         if(mech->tic[i][k] & (1 << j)) {
00137                                                 weapnum = k * SINGLE_TICLONG_SIZE + j;
00138                                                 FireWeaponNumber(player, mech, mech_map, weapnum,
00139                                                                                  temp_argc, temp_args, 0);
00140                                                 if(f != (Fallen(mech))) {
00141                                                         if(Started(mech))
00142                                                                 mech_notify(mech, MECHALL,
00143                                                                                         "That fall causes you to stop your fire!");
00144                                                         return 1;
00145                                                 } else if(!Started(mech))
00146                                                         return 1;
00147                                                 count++;
00148                                         }
00149                 if(!count)
00150                         notify_printf(player, "*Click* (the tic contained no weapons)");
00151         }
00152         return 0;
00153 }
00154 
00155 void firetic_sub(dbref player, MECH * mech, char *buffer)
00156 {
00157         MAP *mech_map;
00158         int ticnum, argc;
00159         char *args[5];
00160         unsigned long weaps;
00161 
00162         DOCHECK((argc =
00163                          mech_parseattributes(buffer, args, 5)) < 1,
00164                         "Not enough arguments to function");
00165         mech_map = getMap(mech->mapindex);
00166         ticnum = atoi(args[0]);
00167         DOCHECK(!(ticnum >= 0 && ticnum < NUM_TICS), "TIC out of range!");
00168 
00169 /*   notify (player, tprintf ("Firing all weapons in TIC #%d at default target!", ticnum)); */
00170         weaps = 1;
00171         ftflag = 1;
00172         temp_args = args;
00173         temp_argc = argc;       
00174         multi_weap_sel(mech, player, args[0], 2, firetic_sub_func);
00175         ftflag = 0;
00176 }
00177 
00178 static MECH *present_mech;
00179 static int present_count;
00180 
00181 static char *listtic_fun(int i)
00182 {
00183         int j, k, l, section, critical;
00184         static char buf[MBUF_SIZE];
00185         int count = 0;
00186         MECH *mech = present_mech;
00187         int rtar;
00188 
00189         if(!present_count) {
00190                 strcpy(buf, "No weapons in tic.");
00191                 return buf;
00192         }
00193         rtar = i / 2 + (i % 2 ? ((present_count + 1) / 2) : 0);
00194         for(j = 0; j < MAX_WEAPONS_PER_MECH; j++) {
00195                 k = j / SINGLE_TICLONG_SIZE;
00196                 l = j % SINGLE_TICLONG_SIZE;
00197                 if(mech->tic[present_tic][k] & (1 << l)) {
00198                         if(count == rtar) {
00199                                 if((FindWeaponNumberOnMech(mech, j, &section, &critical))
00200                                    == -1) {
00201                                         mech->tic[present_tic][k] &= ~(1 << l);
00202                                         j = MAX_WEAPONS_PER_MECH;
00203                                         continue;
00204                                 }
00205                                 sprintf(buf, "#%2d %3s %-16s %s", j,
00206                                                 ShortArmorSectionString(MechType(mech),
00207                                                                                                 MechMove(mech), section),
00208                                                 &MechWeapons[Weapon2I
00209                                                                          (GetPartType(mech, section, critical))].
00210                                                 name[3], PartIsNonfunctional(mech, section,
00211                                                                                                          critical) ? "(*)" : "");
00212                                 return buf;
00213                         }
00214                         count++;
00215                 }
00216         }
00217         strcpy(buf, "Unknown - error of some sort occured");
00218         return buf;
00219 }
00220 
00221 void listtic_sub(dbref player, MECH * mech, char *buffer)
00222 {
00223         int ticnum, argc;
00224         char *args[2];
00225         int i, j, k, count = 0;
00226         coolmenu *c;
00227 
00228         DOCHECK((argc =
00229                          mech_parseattributes(buffer, args, 2)) != 1,
00230                         "Invalid number of arguments!");
00231         ticnum = atoi(args[0]);
00232         DOCHECK(!(ticnum >= 0 && ticnum < NUM_TICS), "TIC out of range!");
00233         present_mech = mech;
00234         present_tic = ticnum;
00235         for(i = 0; i < MAX_WEAPONS_PER_MECH; i++) {
00236                 j = i / SINGLE_TICLONG_SIZE;
00237                 k = i % SINGLE_TICLONG_SIZE;
00238                 if(mech->tic[ticnum][j] & (1 << k))
00239                         count++;
00240         }
00241         present_count = count;
00242         c = SelCol_FunStringMenuK(2, tprintf("TIC #%d listing for %s", ticnum,
00243                                                                                  GetMechID(mech)), listtic_fun, MAX(1,
00244                                                                                                                                                         count));
00245         ShowCoolMenu(player, c);
00246         KillCoolMenu(c);
00247 }
00248 
00249 void mech_cleartic(dbref player, void *data, char *buffer)
00250 {
00251         MECH *mech = (MECH *) data;
00252 
00253         cch(MECH_USUALSM);
00254         cleartic_sub(player, mech, buffer);
00255 }
00256 
00257 void mech_addtic(dbref player, void *data, char *buffer)
00258 {
00259         MECH *mech = (MECH *) data;
00260 
00261         cch(MECH_USUALSM);
00262         addtic_sub(player, mech, buffer);
00263 }
00264 
00265 void mech_deltic(dbref player, void *data, char *buffer)
00266 {
00267         MECH *mech = (MECH *) data;
00268 
00269         cch(MECH_USUALSM);
00270         deltic_sub(player, mech, buffer);
00271 }
00272 
00273 void mech_firetic(dbref player, void *data, char *buffer)
00274 {
00275         MECH *mech = (MECH *) data;
00276 
00277         cch(MECH_USUALO);
00278         firetic_sub(player, mech, buffer);
00279 }
00280 
00281 void mech_listtic(dbref player, void *data, char *buffer)
00282 {
00283         MECH *mech = (MECH *) data;
00284 
00285         cch(MECH_USUALSM);
00286         listtic_sub(player, mech, buffer);
00287 }
00288 
00289 void heat_cutoff_event(MUXEVENT * e)
00290 {
00291         MECH *mech = (MECH *) e->data;
00292 
00293         if(e->data2) {
00294                 mech_notify(mech, MECHALL, "%cyHeat dissipation cutoff engaged!%c");
00295                 MechCritStatus(mech) |= HEATCUTOFF;
00296         } else {
00297                 mech_notify(mech, MECHALL,
00298                                         "%cgHeat dissipation cutoff disengaged!%c");
00299                 MechCritStatus(mech) &= ~(HEATCUTOFF);
00300         }
00301 }
00302 
00303 void heat_cutoff(dbref player, void *data, char *buffer)
00304 {
00305         MECH *mech = (MECH *) data;
00306 
00307         cch(MECH_USUALSMO);
00308         if(HeatcutoffChanging(mech)) {
00309                 notify(player,
00310                            "You are already toggling heat cutoff status. Please be patient.");
00311                 return;
00312         }
00313         if(Heatcutoff(mech)) {
00314                 notify(player, "Disengaging heat dissipation cutoff...");
00315                 MECHEVENT(mech, EVENT_HEATCUTOFFCHANGING, heat_cutoff_event, 4, 0);
00316         } else {
00317                 notify(player, "Engaging heat dissipation cutoff...");
00318                 MECHEVENT(mech, EVENT_HEATCUTOFFCHANGING, heat_cutoff_event, 4, 1);
00319         }
00320 }

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