src/hcode/btech/mine.c File Reference

#include "copyright.h"
#include "config.h"
#include <math.h>
#include "mech.h"
#include "mine.h"
#include "p.artillery.h"
#include "p.map.obj.h"
#include "p.mine.h"
#include "p.mech.utils.h"
#include "p.btechstats.h"
#include "p.template.h"

Include dependency graph for mine.c:

Go to the source code of this file.

Defines

#define READINT(from, to)   DOCHECK(Readnum(to,from), "Invalid number!")

Functions

int compare_array (char *[], char *)
void add_mine (MAP *map, int x, int y, int dam)
static void mine_damage_mechs (MAP *map, int tx, int ty, char *tomsg, char *otmsg, char *tomsg1, char *otmsg1, int dam, int heat, int nb)
static void update_mine (MAP *map, mapobj *mine)
void make_mine_explode (MECH *mech, MAP *map, mapobj *o, int x, int y, int reason)
static void possible_mine_explosion (MECH *mech, MAP *map, int x, int y, int reason)
void possible_mine_poof (MECH *mech, int reason)
void possibly_remove_mines (MECH *mech, int x, int y)
static void add_mine_on_map (MAP *map, int x, int y, char type, int data)
void recalculate_minefields (MAP *map)
void map_add_mine (dbref player, void *data, char *buffer)
void explode_mines (MECH *mech, int chn)
void show_mines_in_hex (dbref player, MECH *mech, float range, int x, int y)

Variables

char * mine_type_names []


Define Documentation

#define READINT ( from,
to   )     DOCHECK(Readnum(to,from), "Invalid number!")


Function Documentation

void add_mine ( MAP map,
int  x,
int  y,
int  dam 
)

Definition at line 52 of file mine.c.

References add_mapobj(), is_mine_hex(), MAP::mapobj, MINE_STANDARD, mapobj_struct::next, TYPE_MINE, mapobj_struct::x, and mapobj_struct::y.

Referenced by artillery_hit_hex().

00053 {
00054         mapobj *o, foo;
00055 
00056         if(is_mine_hex(map, x, y)) {
00057                 for(o = map->mapobj[TYPE_MINE]; o; o = o->next)
00058                         if(o->x == x && o->y == y)
00059                                 break;
00060                 if(o)
00061                         return;
00062         }
00063         bzero(&foo, sizeof(foo));
00064         foo.x = x;
00065         foo.y = y;
00066         foo.datas = dam;
00067         foo.datac = MINE_STANDARD;
00068         add_mapobj(map, &map->mapobj[TYPE_MINE], &foo, 1);
00069 }

static void add_mine_on_map ( MAP map,
int  x,
int  y,
char  type,
int  data 
) [static]

Definition at line 285 of file mine.c.

References FindHexRange(), MAP::map_height, MAP::map_width, MapCoordToRealCoord(), MINE_HIGH, MINE_LOW, MINE_TRIGGER, set_hex_mine(), and VIBRO.

Referenced by recalculate_minefields().

00286 {
00287         int x1, y1;
00288         int mdis = (100 - data) / 10;
00289         int t = mdis * 3 / 2;
00290 
00291         if(type == MINE_TRIGGER) {
00292 
00293                 float fx, fy, fx1, fy1;
00294 
00295                 /* Get the main hex's location in floating values */
00296                 MapCoordToRealCoord(x, y, &fx, &fy);
00297 
00298                 /* Loop through all the possible hexes within range
00299                  * and add mines to those hexes if they are within
00300                  * range */
00301                 for(x1 = x - data; x1 <= x + data; x1++)
00302                         for(y1 = y - data; y1 <= y + data; y1++) {
00303 
00304                                 /* Check the range, if in range add a mine */
00305                                 /* We round because of weirdness with FindHexRange returning
00306                                  * values like 1.00215 */
00307                                 MapCoordToRealCoord(x1, y1, &fx1, &fy1);
00308                                 if(nearbyintf(FindHexRange(fx, fy, fx1, fy1)) <=
00309                                    ((float) data))
00310                                         set_hex_mine(map, x1, y1);
00311                         }
00312 
00313         } else if(type >= MINE_LOW && type <= MINE_HIGH) {
00314 
00315                 if(VIBRO(type) && mdis) {
00316                         for(x1 = x - mdis; x1 <= (x + mdis); x1++)
00317                                 for(y1 = y - mdis; y1 <= (y + mdis); y1++)
00318                                         if((abs(x1 - x) + abs(y1 - y)) <= t)
00319                                                 if(!(x1 < 0 || y1 < 0 || x1 >= map->map_width ||
00320                                                          y1 >= map->map_height))
00321                                                         set_hex_mine(map, x1, y1);
00322                 } else {
00323                         set_hex_mine(map, x, y);
00324                 }
00325         }
00326 }

int compare_array ( char *  [],
char *   
)

Definition at line 1194 of file template.c.

Referenced by BuildBitVector(), BuildBitVectorNoErr(), BuildBitVectorWithDelim(), CheckSpecialsList(), debug_makemechs(), find_section(), fun_btmakemechs(), load_template(), map_add_mine(), mechMovefunc(), and mechTypefunc().

01195 {
01196         int x;
01197 
01198         if(!list)
01199                 return -1;
01200         for(x = 0; list[x]; x++)
01201                 if(!strcasecmp(list[x], command))
01202                         return x;
01203 
01204         return -1;
01205 }

void explode_mines ( MECH mech,
int  chn 
)

Definition at line 383 of file mine.c.

References mapobj_struct::datac, mapobj_struct::datai, getMap(), make_mine_explode(), MECH::mapindex, MAP::mapobj, MINE_COMMAND, mapobj_struct::next, recalculate_minefields(), and TYPE_MINE.

00384 {
00385         MAP *map = getMap(mech->mapindex);
00386         mapobj *o, *o2;
00387         int count = 0;
00388 
00389         if(!map)
00390                 return;
00391         for(o = map->mapobj[TYPE_MINE]; o; o = o2) {
00392                 o2 = o->next;
00393                 if(o->datac == MINE_COMMAND)
00394                         if(o->datai == chn) {
00395                                 make_mine_explode(mech, map, o, 0, 0, 0);
00396                                 count++;
00397                         }
00398         }
00399         if(count)
00400                 recalculate_minefields(map);
00401 }

void make_mine_explode ( MECH mech,
MAP map,
mapobj o,
int  x,
int  y,
int  reason 
)

Definition at line 89 of file mine.c.

References A_AMINETRIGGER, mapobj_struct::datac, mapobj_struct::datas, did_it(), GetMechID(), HexLOSBroadcast(), mapobj_del(), mech_notify(), mech_printf(), MECHALL, MechLOSBroadcast(), MINE_COMMAND, mine_damage_mechs(), MINE_DROP, MINE_FALL, MINE_INFERNO, MINE_LAND, MINE_MIN, MINE_STANDARD, MINE_STEP, MINE_TRIGGER, MINE_VIBRA, MECH::mynum, recalculate_minefields(), SendTrigger, tprintf(), TYPE_MINE, unset_hex_mine(), update_mine(), mapobj_struct::x, and mapobj_struct::y.

Referenced by explode_mines(), and possible_mine_explosion().

00091 {
00092         int cool = (o->datas >= MINE_MIN);
00093 
00094         if((o->datac == MINE_TRIGGER)
00095            && reason != MINE_STEP && reason != MINE_LAND)
00096                 return;
00097         if(o->datac != MINE_TRIGGER) {
00098                 if(o->datac != MINE_COMMAND) {
00099                         switch (reason) {
00100                         case MINE_STEP:
00101                                 MechLOSBroadcast(mech,
00102                                                                  tprintf
00103                                                                  ("moves to %d,%d, and triggers a mine!", x,
00104                                                                   y));
00105                                 mech_printf(mech, MECHALL,
00106                                                         "As you move to %d,%d, you trigger a mine!", x,
00107                                                         y);
00108                                 break;
00109                         case MINE_LAND:
00110                                 MechLOSBroadcast(mech, tprintf("triggers a mine!", x, y));
00111                                 mech_notify(mech, MECHALL, "You trigger a mine!");
00112                                 break;
00113                         case MINE_DROP:
00114                         case MINE_FALL:
00115                                 MechLOSBroadcast(mech, tprintf("triggers a mine!", x, y));
00116                                 mech_notify(mech, MECHALL, "You trigger a mine!");
00117                                 break;
00118                         }
00119                 } else
00120                         HexLOSBroadcast(map, o->x, o->y, "A mine explodes in $H!");
00121         }
00122 
00123         switch (o->datac) {
00124         case MINE_STANDARD:
00125                 update_mine(map, o);
00126                 mine_damage_mechs(map, o->x, o->y, "A blast of shrapnel hits you!",
00127                                                   "is hit by shrapnel!", NULL, NULL, o->datas, 0, 0);
00128                 if(!cool)
00129                         mapobj_del(map, o->x, o->y, TYPE_MINE);
00130                 break;
00131         case MINE_INFERNO:
00132                 update_mine(map, o);
00133                 mine_damage_mechs(map, o->x, o->y, "Globs of flaming gel hit you!",
00134                                                   "is hit by globs of flaming gel!", NULL, NULL,
00135                                                   o->datas / 3, o->datas, 0);
00136                 if(!cool)
00137                         mapobj_del(map, o->x, o->y, TYPE_MINE);
00138                 break;
00139         case MINE_COMMAND:
00140                 unset_hex_mine(map, o->x, o->y);
00141                 mine_damage_mechs(map, o->x, o->y, "A blast of shrapnel hits you!",
00142                                                   "is hit by shrapnel!",
00143                                                   "A little blast of shrapnel hits you!",
00144                                                   "is hit by some of the shrapnel!", o->datas, 0, 1);
00145                 mapobj_del(map, o->x, o->y, TYPE_MINE);
00146                 break;
00147         case MINE_TRIGGER:
00148                 SendTrigger(tprintf("#%d %s activated trigger at %d,%d.",
00149                                                         mech->mynum, GetMechID(mech), o->x, o->y));
00150 
00151                 // Trigger the unit's AMECHDEST attribute.
00152                 if(mech->mynum > 0)
00153                     did_it(mech->mynum, mech->mynum, 0, NULL, 0, NULL, A_AMINETRIGGER, (char **) NULL, 0);
00154                 
00155                 return;
00156         case MINE_VIBRA:
00157                 unset_hex_mine(map, o->x, o->y);
00158                 if(o->x != x || o->y != y)
00159                         HexLOSBroadcast(map, o->x, o->y, "A mine explodes in $H!");
00160                 mine_damage_mechs(map, o->x, o->y, "A blast of shrapnel hits you!",
00161                                                   "is hit by shrapnel!",
00162                                                   "A little blast of shrapnel hits you!",
00163                                                   "is hit by some of the shrapnel!", o->datas, 0, 1);
00164                 mapobj_del(map, o->x, o->y, TYPE_MINE);
00165                 break;
00166         }
00167         recalculate_minefields(map);
00168 }

void map_add_mine ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 339 of file mine.c.

References add_mapobj(), args, compare_array(), DOCHECK, MAP::mapobj, mech_parseattributes(), mine_type_names, notify_printf(), READINT, recalculate_minefields(), TYPE_MINE, x, and y.

00340 {
00341 
00342         char *args[6];
00343         int argc;
00344         int x, y, str, type, extra = 0;
00345         MAP *map = (MAP *) data;
00346         mapobj foo;
00347 
00348         if(!map)
00349                 return;
00350 
00351 #define READINT(from,to) \
00352     DOCHECK(Readnum(to,from), "Invalid number!")
00353 
00354         argc = mech_parseattributes(buffer, args, 6);
00355         DOCHECK(argc < 4 || argc > 5, "Invalid arguments!");
00356         READINT(args[0], x);
00357         READINT(args[1], y);
00358         READINT(args[3], str);
00359 
00360         if(argc == 5)
00361                 READINT(args[4], extra);
00362 
00363         DOCHECK((type = compare_array(mine_type_names, args[2])) < 0,
00364                         "Invalid mine type!");
00365         DOCHECK(!((x >= 0) && (x < map->map_width) && (y >= 0) &&
00366                           (y < map->map_height)), "X,Y out of range!");
00367 
00368         bzero(&foo, sizeof(foo));
00369         foo.x = x;
00370         foo.y = y;
00371         foo.datai = extra;
00372         foo.datas = str;
00373         foo.datac = type + 1;
00374         foo.obj = player;
00375         add_mapobj(map, &map->mapobj[TYPE_MINE], &foo, 1);
00376 
00377         notify_printf(player,
00378                                   "%s mine added to (%d,%d) (strength: %d / extra: %d)",
00379                                   mine_type_names[type], x, y, str, extra);
00380         recalculate_minefields(map);
00381 }

static void mine_damage_mechs ( MAP map,
int  tx,
int  ty,
char *  tomsg,
char *  otmsg,
char *  tomsg1,
char *  otmsg1,
int  dam,
int  heat,
int  nb 
) [static]

Definition at line 71 of file mine.c.

References blast_hit_hexes(), and MINE_TABLE.

Referenced by make_mine_explode().

00074 {
00075         blast_hit_hexes(map, dam, 5, heat, tx, ty, tomsg, otmsg, tomsg1,
00076                                         otmsg1, MINE_TABLE, 2, 1, 1, 1);
00077 }

static void possible_mine_explosion ( MECH mech,
MAP map,
int  x,
int  y,
int  reason 
) [static]

Definition at line 173 of file mine.c.

References mapobj_struct::datac, mapobj_struct::datai, mapobj_struct::datas, FindHexRange(), make_mine_explode(), MapCoordToRealCoord(), MAP::mapobj, mech_notify(), MECHALL, MechRealTons, MINE_COMMAND, MINE_TRIGGER, MINE_VIBRA, mapobj_struct::next, TYPE_MINE, VIBRO, mapobj_struct::x, and mapobj_struct::y.

Referenced by possible_mine_poof().

00175 {
00176         mapobj *o, *o2;
00177         int mdis = (MechRealTons(mech) - 20) / 10;
00178         float x1, y1, x2, y2, range;
00179 
00180         MapCoordToRealCoord(x, y, &x1, &y1);
00181         for(o = map->mapobj[TYPE_MINE]; o; o = o2) {
00182 
00183                 int real = 1;
00184 
00185                 o2 = o->next;
00186                 if(o->x == x && o->y == y) {
00187 
00188                         switch (o->datac) {
00189 
00190                         case MINE_TRIGGER:
00191                                 if(o->datas > MechRealTons(mech))
00192                                         continue;
00193                                 break;
00194                         case MINE_VIBRA:
00195                                 if(o->datai > MechRealTons(mech))
00196                                         continue;       /* No message, just boom */
00197                                 break;
00198                         case MINE_COMMAND:
00199                                 mech_notify(mech, MECHALL,
00200                                                         "You spot small bomblets lying on the ground here..");
00201                                 real = 0;
00202                                 continue;
00203                         }
00204 
00205                         if(!real)
00206                                 return;
00207 
00208                         make_mine_explode(mech, map, o, x, y, reason);
00209 
00210                 } else if(VIBRO(o->datac)) {
00211 
00212                         if(o->datac == MINE_TRIGGER) {
00213 
00214                                 /* To small let it go */
00215                                 if(o->datas > (MechRealTons(mech)))
00216                                         continue;
00217 
00218                                 MapCoordToRealCoord(o->x, o->y, &x2, &y2);
00219 
00220                                 /* Out side of range */
00221                                 /* Using round here because we get some funky ranges like
00222                                  * 0.999987 and 1.00000072 */
00223                                 if(nearbyintf(FindHexRange(x1, y1, x2, y2)) >
00224                                    ((float) o->datai))
00225                                         continue;
00226 
00227                                 make_mine_explode(mech, map, o, x, y, reason);
00228 
00229                         } else if(o->datai < MechRealTons(mech)) {
00230 
00231                                 if(abs(o->x - x) <= mdis && abs(o->y - y) <= mdis) {
00232 
00233                                         /* Possible remote explosion */
00234                                         MapCoordToRealCoord(o->x, o->y, &x2, &y2);
00235                                         if((range = FindHexRange(x1, y1, x2, y2)) >
00236                                            (MechRealTons(mech) - o->datai) / 10)
00237                                                 continue;
00238 
00239                                         make_mine_explode(mech, map, o, x, y, reason);
00240                                 }
00241                         }
00242                 }
00243         }
00244 }

void possible_mine_poof ( MECH mech,
int  reason 
)

Definition at line 246 of file mine.c.

References Elevation, getMap(), ICE, is_mine_hex(), MECH::mapindex, MechRTerrain, MechX, MechY, MechZ, possible_mine_explosion(), x, and y.

Referenced by aero_land(), LandMech(), mech_drop(), MechFalls(), and NewHexEntered().

00247 {
00248         MAP *map = getMap(mech->mapindex);
00249         int x = MechX(mech);
00250         int y = MechY(mech);
00251 
00252         if(!is_mine_hex(map, x, y))
00253                 return;
00254 
00255         if(MechZ(mech) > (MechRTerrain(mech) == ICE ? 0 : Elevation(map, x, y)))
00256                 return;
00257 
00258         possible_mine_explosion(mech, map, x, y, reason);
00259 }

void possibly_remove_mines ( MECH mech,
int  x,
int  y 
)

Definition at line 261 of file mine.c.

References FindObjectsData(), is_mine_hex(), MECH::mapindex, mapobj_del(), recalculate_minefields(), Roll(), and TYPE_MINE.

Referenced by possibly_clear().

00262 {
00263         MAP *map = FindObjectsData(mech->mapindex);
00264 
00265         if(!map)
00266                 return;
00267         if(!is_mine_hex(map, x, y))
00268                 return;
00269 
00270         /* Do the cleaning stuff here */
00271 
00272         /* Ok, we're lazy and just decide that roll of <= 4 removes
00273            all traces of mines in the hex */
00274         if(Roll() <= 4) {
00275                 if(mapobj_del(map, x, y, TYPE_MINE)) {
00276                         /* There _was_ something to clear.. no message, we're evil */
00277                         recalculate_minefields(map);
00278                 }
00279         }
00280 }

void recalculate_minefields ( MAP map  ) 

Definition at line 329 of file mine.c.

References add_mine_on_map(), clear_hex_bits(), mapobj_struct::datac, mapobj_struct::datai, MAP::mapobj, mapobj_struct::next, TYPE_MINE, mapobj_struct::x, and mapobj_struct::y.

Referenced by explode_mines(), load_update3(), make_mine_explode(), map_add_mine(), and possibly_remove_mines().

00330 {
00331         mapobj *o;
00332 
00333         clear_hex_bits(map, 1);
00334         for(o = map->mapobj[TYPE_MINE]; o; o = o->next)
00335                 add_mine_on_map(map, o->x, o->y, o->datac, o->datai);
00336 }

void show_mines_in_hex ( dbref  player,
MECH mech,
float  range,
int  x,
int  y 
)

Definition at line 403 of file mine.c.

References DOCHECK, getMap(), is_mine_hex(), MadePerceptionRoll(), MECH::mapindex, MAP::mapobj, mech_notify(), MECHALL, mapobj_struct::next, Number, TYPE_MINE, mapobj_struct::x, and mapobj_struct::y.

Referenced by mech_scan().

00404 {
00405         MAP *map = getMap(mech->mapindex);
00406         mapobj *o;
00407 
00408         DOCHECK(!is_mine_hex(map, x, y),
00409                         "You see nothing else of interest in the hex, either.");
00410 
00411         for(o = map->mapobj[TYPE_MINE]; o; o = o->next)
00412                 if(o->x == x && o->y == y)
00413                         break;
00414 
00415         DOCHECK(!o, "You see nothing else of interest in the hex, either.");
00416         DOCHECK(Number(2, 9) < ((int) range),
00417                         "You see nothing else of interest in the hex, either.");
00418         DOCHECK(!MadePerceptionRoll(mech, 0),
00419                         "You see nothing else of interest in the hex, either.");
00420         mech_notify(mech, MECHALL,
00421                                 "Small bomblets litter the hex, interesting... You vaguely "
00422                                 "recall them from some class or other.");
00423 }

static void update_mine ( MAP map,
mapobj mine 
) [static]

Definition at line 79 of file mine.c.

References mapobj_struct::datas, MINE_MIN, and MINE_NEXT_MODIFIER.

Referenced by make_mine_explode().

00080 {
00081         int i;
00082 
00083         i = mine->datas;
00084         i = i * MINE_NEXT_MODIFIER;
00085         if(i >= MINE_MIN)
00086                 mine->datas = i;
00087 }


Variable Documentation

char* mine_type_names[]

Initial value:

 {
        "Standard",
        "Inferno",
        "Command",
        "Vibra",
        "Trigger",      
        NULL
}

Definition at line 41 of file mine.c.

Referenced by map_add_mine().


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