src/hcode/btech/mech.sensor.functions.c

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: mech.sensor.functions.c,v 1.1.1.1 2005/01/11 21:18:23 kstevens Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *  Copyright (c) 1998-2002 Thomas Wouters
00009  *  Copyright (c) 2000-2002 Cord Awtry
00010  *       All rights reserved
00011  *
00012  * Created: Mon Sep  2 16:57:30 1996 fingon
00013  * Last modified: Tue Oct  6 17:21:27 1998 fingon
00014  *
00015  */
00016 
00017 #include "mech.h"
00018 #include "mech.sensor.h"
00019 #include "p.map.obj.h"
00020 #include "p.mech.update.h"
00021 #include "p.mech.utils.h"
00022 #include "p.template.h"
00023 
00024 /* Full chance of seeing, except if range > conditionrange */
00025 SEEFUNC(vislight_see, r > (c * ((!l && t &&
00026                                                                  IsLit(t)) ? 3 : 1)) ? 0 : (100 -
00027                                                                                                                         (r / 3)) / ((t
00028                                                                                                                                                  &&
00029                                                                                                                                                  (MechType
00030                                                                                                                                                   (t)
00031                                                                                                                                                   ==
00032                                                                                                                                                   CLASS_BSUIT
00033                                                                                                                                                   ||
00034                                                                                                                                                   MechType
00035                                                                                                                                                   (t)
00036                                                                                                                                                   ==
00037                                                                                                                                                   CLASS_MW))
00038                                                                                                                                                 ? 3 :
00039                                                                                                                                                 1));
00040 
00041 /* In perfect darkness, 2x conditionrange. Otherwise conditionrange,
00042    always same chance of seeing */
00043 SEEFUNC(liteamp_see, ((!l && r > (2 * c)) ? 0 : (l &&
00044                                                                                                  r > c) ? 0 : (70 - r)) / ((t
00045                                                                                                                                                         &&
00046                                                                                                                                                         (MechType
00047                                                                                                                                                          (t)
00048                                                                                                                                                          ==
00049                                                                                                                                                          CLASS_BSUIT
00050                                                                                                                                                          ||
00051                                                                                                                                                          MechType
00052                                                                                                                                                          (t)
00053                                                                                                                                                          ==
00054                                                                                                                                                          CLASS_MW))
00055                                                                                                                                                    ? 3
00056                                                                                                                                                    :
00057                                                                                                                                                    1));
00058 
00059 /* Always same chance, if within range */
00060 SEEFUNC(infrared_see, (80 - r));
00061 SEEFUNC(electrom_see, MAX(r < 24 ? 2 : 0, (60 - (r * 2))) / 2);
00062 SEEFUNC(seismic_see, 50 - (r * 4));
00063 
00064 SEEFUNC(radar_see, BOUNDED(10, (180 - r), 90));
00065 SEEFUNC(bap_see, 101);
00066 SEEFUNC(blood_see, 101);
00067 
00068 /* Prior requirement: the seechance > 0. We assume it so,
00069    and only examine the flag. */
00070 
00071 extern float ActualElevation(MAP * map, int x, int y, MECH * mech);
00072 
00073 /* Visual methods are hampered by excess woods / water */
00074 CSEEFUNC(vislight_csee, !(map->sensorflags & (1 << SENSOR_VIS)) &&
00075                  !(f & (MECHLOSFLAG_BLOCK | MECHLOSFLAG_FIRE | MECHLOSFLAG_SMOKE)) &&
00076                  MechLOSFlag_WoodCount(f) < 3 && (!t || MechZ(t) >= 0 ||
00077                                                                                   ActualElevation(getMap(t->mapindex),
00078                                                                                                                   MechX(t), MechY(t),
00079                                                                                                                   t) >= 0.0
00080                                                                                   || MechLOSFlag_WaterCount(f) < 6));
00081 
00082 /* Liteamp doesn't see into water, thanks to reflections etc */
00083 CSEEFUNC(liteamp_csee, !(map->sensorflags & (1 << SENSOR_LA)) &&
00084                  !(f & (MECHLOSFLAG_BLOCK | MECHLOSFLAG_FIRE | MECHLOSFLAG_SMOKE)) &&
00085                  (!t || !IsLit(t)) && MechLOSFlag_WoodCount(f) < 2
00086                  && !(MechLOSFlag_WaterCount(f)));
00087 
00088 /* Not too good with woods, infra.. too much variation in temperature */
00089 CSEEFUNC(infrared_csee, !(map->sensorflags & (1 << SENSOR_IR)) &&
00090                  !(f & (MECHLOSFLAG_BLOCK | MECHLOSFLAG_FIRE)) &&
00091                  MechLOSFlag_WoodCount(f) < 6 && (!t || (MechType(t) != CLASS_BSUIT &&
00092                                                                                                  MechType(t) != CLASS_MW)));
00093 
00094 /* Mountains provide too much hindarance in terms of electromagnetic
00095    detection */
00096 CSEEFUNC(electrom_csee, !(map->sensorflags & (1 << SENSOR_EM)) &&
00097                  !(f & (MECHLOSFLAG_BLOCK | MECHLOSFLAG_MNTN)) &&
00098                  MechLOSFlag_WoodCount(f) < 8 && !AnyECMDisturbed(m) && (!t ||
00099                                                                                                                                  (MechType(t)
00100                                                                                                                                   !=
00101                                                                                                                                   CLASS_MW)));
00102 
00103 /* Seismic sees, as long as there is a target, and it isn't jumping or
00104    flying, or hovering, or otherwise with little or no contact to the
00105    ground. Period. */
00106 CSEEFUNC(seismic_csee,
00107                  !(map->sensorflags & (1 << SENSOR_SE)) &&
00108                  t && (!Jumping(m)) &&
00109                  (mudconf.btech_seismic_see_stopped ? 1 : (abs(MechSpeed(t)) > MP1))
00110                  &&
00111                  (((MechMove(m) != MOVE_VTOL)
00112                    || ((MechMove(m) == MOVE_VTOL) && Landed(m)))
00113                   && ((MechMove(m) != MOVE_FLY)
00114                           || ((MechMove(m) == MOVE_FLY) && Landed(m))) && Started(t)
00115                   && !Jumping(t) && (MechType(t) != CLASS_BSUIT)
00116                   && (MechType(t) != CLASS_MW) && (MechMove(t) != MOVE_HOVER)
00117                   && ((MechMove(t) != MOVE_VTOL)
00118                           || ((MechMove(t) == MOVE_VTOL) && Landed(t)))
00119                   && ((MechMove(t) != MOVE_FLY)
00120                           || ((MechMove(t) == MOVE_FLY) && Landed(t))))
00121                  && (MechMove(t) != MOVE_NONE));
00122 
00123 /* Radar sees, as long as the target is flying and not near disruptions. */
00124 CSEEFUNC(radar_csee,
00125                  !(map->sensorflags & (1 << SENSOR_RA)) &&
00126                  t &&
00127                  MechZ(t) > 2 &&
00128                  !(f & MECHLOSFLAG_BLOCK) &&
00129                  (MechZ(t) >= 10 || (r < (MechZ(t) * MechZ(t)))) &&
00130                  MechsElevation(t) > 1);
00131 
00132 /* BAP is disrupted by ECM and can't pick up units with nullsig active. */
00133 CSEEFUNC(bap_csee,
00134                  !(map->sensorflags & (1 << SENSOR_BAP)) &&
00135                  !AnyECMDisturbed(m) &&
00136                  t &&
00137                  !AngelECMProtected(t) &&
00138                  !StealthArmorActive(t) && !NullSigSysActive(t));
00139 
00140 /* Bloodhound is only disrupted by ECM. */
00141 CSEEFUNC(blood_csee,
00142                  !(map->sensorflags & (1 << SENSOR_BHAP)) &&
00143                  !AnyECMDisturbed(m) && t && !AngelECMProtected(t));
00144 
00145 /* Basically, mechs w/o heat are +2 tohit, mechs in utter overheat are
00146    -2 tohit */
00147 #ifdef BT_SCALED_INFRARED
00148 #define HEAT_MODIFIER(a) ((a) <= 0 ? 2 : (a) > 50 ? -2 : (a) > 35 ? -1 : (a) > 20 ? 0 : 1)
00149 #else
00150 
00151 /*
00152 #define HEAT_MODIFIER(a) ((a) <= 7 ? 2 : (a) > 28 ? -2 : (a) > 21 ? -1 : (a) > 14 ? 0 : 1)
00153 */
00154 
00155 #define HEAT_MODIFIER(a) ((a) <= 7 ? 2 : (a) <= 10 ? 1 : (a) <= 15 ? 0 : (a) <= 22 ? -1 : -2)
00156 #endif
00157 /* Heavy/assault -1 tohit, medium 0, light +1 */
00158 #define WEIGHT_MODIFIER(a) (a > 65 ? -1 : a > 35 ? 0 : 1)
00159 
00160 /* If target's moving, +1 tohit */
00161 #define MOVE_MODIFIER(a) (abs(a) >= 10.75 ? 1 : 0)
00162 
00163 #define nwood_count(mech,a)  (MechLOSFlag_WoodCount(a) + \
00164                              ((MechElevation(mech) + 2) < MechZ(mech) ? 0 : \
00165                               MechRTerrain(mech) == LIGHT_FOREST ? 1 : \
00166                               MechRTerrain(mech) == HEAVY_FOREST ? 2 : 0))
00167 
00168 /* To-hit functions */
00169 /* Visual - Non-Day, Interrupting woods, partial LOS, and hulldown. */
00170 TOHITFUNC(vislight_tohit, ((!t ||
00171                                                         !IsLit(t)) ? (2 - l) : 0) + nwood_count(t,
00172                                                                                                                                         f) +
00173                   ((f & MECHLOSFLAG_PARTIAL) ? 3 + (IsHulldown(t) ? 2 : 0) : 0));
00174 
00175 /* Liteamp - Interrupting woods, partial LOS, hulldown. */
00176 TOHITFUNC(liteamp_tohit, ((2 - l) / 2) + ((nwood_count(t,
00177                                                                                                            f) * 3) / 2) +
00178                   ((f & MECHLOSFLAG_PARTIAL) ? 3 + (IsHulldown(t) ? 2 : 0) : 0));
00179 
00180 /* Infrared - Interrupting Woods, partial LOS, Hulldown, heat. */
00181 #ifdef BT_SCALED_INFRARED
00182 TOHITFUNC(infrared_tohit, ((nwood_count(t, f) * 4) / 3) +
00183                   ((f & MECHLOSFLAG_PARTIAL) ? 3 : 0) +
00184                   HEAT_MODIFIER((2 * (MechPlusHeat(t) - MechMinusHeat(t))) +
00185                                                 MIN(MechPlusHeat(t), MechMinusHeat(t))));
00186 #else
00187 TOHITFUNC(infrared_tohit, ((nwood_count(t,
00188                                                                                 f) * 4) / 3) +
00189                   ((f & MECHLOSFLAG_PARTIAL) ? 3 + (IsHulldown(t) ? 2 : 0) : 0) +
00190                   HEAT_MODIFIER(MechHeat(t) + 7));
00191 #endif
00192 /* Emag - Interrupting woods, partial LOS, hulldwon, weight/movement,
00193  * recently fired. */
00194 TOHITFUNC(electrom_tohit, ((nwood_count(t,
00195                                                                                 f) * 2) / 3) +
00196                   ((f & MECHLOSFLAG_PARTIAL) ? 3 + (IsHulldown(t) ? 2 : 0) : 0) +
00197                   WEIGHT_MODIFIER(MechTons(t)) + MOVE_MODIFIER(MechSpeed(t)) +
00198                   (MechStatus(t) & FIRED ? -1 : 0) + MNumber(m, 0, 1));
00199 
00200 /* Seismic - Partial LOS, hulldown, weight, speed */
00201 TOHITFUNC(seismic_tohit,
00202                   2 + ((f & MECHLOSFLAG_PARTIAL) ? 3 + (IsHulldown(t) ? 2 : 0) : 0) +
00203                   WEIGHT_MODIFIER(MechRealTons(t)) - MOVE_MODIFIER(MechSpeed(t)) +
00204                   MNumber(m, 0, 1));
00205 
00206 /* BAP - Flat BTH? */
00207 TOHITFUNC(bap_tohit, MNumber(m, 0, 2)); /* Very evil */
00208 
00209 /* BloodHound - Flat BTH? */
00210 TOHITFUNC(blood_tohit, MNumber(m, 0, 2));       /* Very evil */
00211 
00212 /* Radar - Only 10z and above, partial LOS, interrupting woods. */
00213 TOHITFUNC(radar_tohit, ((MechZ(t) >= 10 ||
00214                                                  FlyingT(t)) ? -3 : 0) +
00215                   ((f & MECHLOSFLAG_PARTIAL) ? 2 + (IsHulldown(t) ? 2 : 0) : 0) +
00216                   nwood_count(t, f));

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