![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 #ifndef __SRAUTILITY_H 00002 #define __SRAUTILITY_H 00003 00004 //As of 6/20/2010, this is a legacy file that may need to be re-implemented in UnrealScript as needed 00005 00007 //This file contains a mix of generally useful methods 00008 //These include functions that act on basic types using by the SR library 00009 //Also, this contains all of the magic formulae for character, utilizing SrConstants 00010 //NOTE: All of these functions are inlined for performance 00012 00013 #include <map> 00014 #include <string> 00015 #include <sstream> 00016 00017 #include "CodeGenMacros.h" 00018 #include "SrConstants.h" 00019 #include "SraConstants.h" 00020 00021 namespace SraLogic 00022 { 00024 //Functions that work on types defined in SraTypes 00026 00030 INLINE int GetRecoilPenalty(FireMode mode, bool firstShot, bool heavyWeapon) 00031 { 00032 int recoil = 0; 00033 if(firstShot) 00034 { 00035 switch(mode) 00036 { 00037 case SingleShot: recoil = RECOIL_FIRST_SEMIAUTO; break; 00038 case SemiAuto: recoil = RECOIL_FIRST_SEMIAUTO; break; 00039 case BurstFire: recoil = RECOIL_FIRST_BURST; break; 00040 case LongBurst: recoil = RECOIL_FIRST_LONGBURST; break; 00041 case FullAuto: recoil = RECOIL_FIRST_LONGBURST; break; 00042 } 00043 } 00044 else 00045 { 00046 switch(mode) 00047 { 00048 case SemiAuto: recoil = RECOIL_SECOND_SEMIAUTO; break; 00049 case BurstFire: recoil = RECOIL_SECOND_BURST; break; 00050 case LongBurst: recoil = RECOIL_SECOND_LONGBURST; break; 00051 //NOTE: second single-shot and full bursts should NOT happen 00052 } 00053 } 00054 00055 if(heavyWeapon) 00056 recoil*= RECOIL_HEAVY_MULTIPLIER; 00057 00058 return recoil; 00059 } 00060 00064 INLINE int GetCoverPenalty(Cover cover) 00065 { 00066 switch(cover) 00067 { 00068 case PartialCover: return RANGED_TARGET_PARTIAL_COVER; 00069 case GoodCover: return RANGED_TARGET_GOOD_COVER; 00070 case TotalCover: return RANGED_TARGET_TOTAL_COVER; 00071 default: return 0; 00072 } 00073 } 00074 00079 INLINE float GetAcceptableLossPercentage(ProfessionalRating professionalRating) 00080 { 00081 switch(professionalRating) 00082 { 00083 case Untrained: return PROFESSIONALRATING_ACCEPTABLELOSSES_UNTRAINED; 00084 case SemiTrained: return PROFESSIONALRATING_ACCEPTABLELOSSES_SEMITRAINED; 00085 case Trained: return PROFESSIONALRATING_ACCEPTABLELOSSES_TRAINED; 00086 case Elite: return PROFESSIONALRATING_ACCEPTABLELOSSES_ELITE; 00087 } 00088 00089 return PROFESSIONALRATING_ACCEPTABLELOSSES_UNTRAINED; 00090 } 00091 00096 INLINE bool IsAcceptableLoss(ProfessionalRating professionalRating, 00097 int initialBadGuys, int currentBadGuys) 00098 { 00099 return ((float)currentBadGuys / (float)initialBadGuys) > 00100 GetAcceptableLossPercentage(professionalRating); 00101 } 00102 00104 //Functions that calculate 00106 00112 INLINE int GetConcealabilityRating(Concealability conc) 00113 { 00114 switch(conc) 00115 { 00116 case Miniscule: return CONCEALABILITY_MINISCULE; 00117 case Tiny: return CONCEALABILITY_TINY; 00118 case Small: return CONCEALABILITY_SMALL; 00119 case Medium: return CONCEALABILITY_MEDIUM; 00120 case Big: return CONCEALABILITY_BIG; 00121 case Large: return CONCEALABILITY_LARGE; 00122 case Huge: return CONCEALABILITY_HUGE; 00123 } 00124 00125 return 0; 00126 } 00127 00131 INLINE int GetMinorNpcDamageTrack(int bodyRating, int willRating) 00132 { 00133 //take the higher of body or will 00134 if(willRating > bodyRating) 00135 bodyRating = willRating; 00136 00137 return MINORNPC_DMG_BASE + (int)((float)bodyRating*MINORNPC_DMG_MULTIPLIER); 00138 } 00139 00145 INLINE int GetPlayerStunDamageTrack(int willRating) 00146 { 00147 //pg. 65 00148 // 8 + (half willpower rounded up) 00149 int ret = STUN_DMG_BASE + (willRating/ STUN_DMG_DIVISOR); 00150 if(willRating%STUN_DMG_DIVISOR > 0) 00151 ret +=1; 00152 return ret; 00153 } 00154 00160 INLINE int GetPlayerPhysicalDamageTrack(int bodRating) 00161 { 00162 //pg. 65 00163 // 8 + (half bod rounded up) 00164 int ret = PHYSICAL_DMG_BASE + (bodRating/ PHYSICAL_DMG_DIVISOR); 00165 if(bodRating%PHYSICAL_DMG_DIVISOR > 0) 00166 ret +=1; 00167 return ret; 00168 } 00169 00173 INLINE int GetSoundDistancePenalty(float distanceInMeters) 00174 { 00175 //At the moment, this is based on rules on pg. 117, but maybe a formula would work better 00176 if(distanceInMeters <= DISTANCE_FOR_SOUND_NOT_IMMEDIATE_VICINITY) 00177 return SOUND_IMMEDIATE_VICINITY; 00178 else if(distanceInMeters > DISTANCE_FOR_SOUND_NOT_IMMEDIATE_VICINITY && distanceInMeters <DISTANCE_FOR_SOUND_FAR_AWAY) 00179 return SOUND_NOT_IMMEDIATE_VICINITY; 00180 else 00181 return SOUND_FAR_AWAY; 00182 } 00183 00187 INLINE int GetSightDistancePenalty(float distanceInMeters) 00188 { 00189 //At the moment, this is based on rules on pg. 117, but maybe a formula would work better 00190 if(distanceInMeters <= DISTANCE_FOR_SIGHT_NOT_IMMEDIATE_VICINITY) 00191 return SIGHT_IMMEDIATE_VICINITY; 00192 else if(distanceInMeters > DISTANCE_FOR_SIGHT_NOT_IMMEDIATE_VICINITY && distanceInMeters <DISTANCE_FOR_SIGHT_FAR_AWAY) 00193 return SIGHT_NOT_IMMEDIATE_VICINITY; 00194 else 00195 return SIGHT_FAR_AWAY; 00196 } 00197 00204 INLINE int GetFallingDamage(float metersFallen) 00205 { 00206 if(metersFallen <= 0.0f) 00207 return 0; 00208 else if(metersFallen > 0.0f && metersFallen < 3.0f) 00209 return 2; 00210 else if(metersFallen >= 3.0f && metersFallen < 6.0f) 00211 return 4; 00212 else if(metersFallen >= 6.0f && metersFallen < 8.0f) 00213 return 6; 00214 else 00215 { 00216 metersFallen -= 8.0f; 00217 return 6 + (int)(metersFallen/2.0f); 00218 } 00219 } 00220 00226 INLINE int BuyHits(int totalRating) 00227 { 00228 //no dice == no hits 00229 if(totalRating <= 0) 00230 return 0; 00231 00232 return totalRating/AUTO_SUCCESS_DIVISOR; 00233 } 00234 00238 INLINE int RollHits(int totalRating) 00239 { 00240 //no dice == no hits 00241 if(totalRating <= 0) 00242 return 0; 00243 00244 //make one "roll" per rating point 00245 int numHits = 0; 00246 int randomNumber; 00247 for(int i = 0; i < totalRating; ++i) 00248 { 00249 //A hit is a 5 or better on a d6, or 1 in 3 chance 00250 randomNumber = rand()%3; 00251 if(randomNumber == 2) 00252 numHits++; 00253 } 00254 00255 return numHits; 00256 } 00257 00261 INLINE int GetHealingEssencePenalty(int currentEssence) 00262 { 00263 return (INITIAL_ESS - currentEssence)/HEALING_ESSENCE_MULTIPLIER; 00264 } 00265 00269 INLINE int GetPhysicalHealingPerDay(int bodyRating) 00270 { 00271 return (HEALING_PHYSICAL_MULTIPLIER*bodyRating)/HEALING_PHYSICAL_DIVISOR; 00272 } 00273 00278 INLINE float GetTimeForOneBoxStunInRealHours(int willRating, int bodyRating) 00279 { 00280 int stunBoxesPerGameHour = (willRating + bodyRating)/HEALING_STUN_DIVISOR; 00281 return REAL_HOURS_PER_GAME_HOUR/(float)stunBoxesPerGameHour; 00282 } 00283 00288 INLINE int GetWoundModifier(int numberOfBoxes) 00289 { 00290 return numberOfBoxes/WOUNDMODIFIER_DIVISOR; 00291 } 00292 00296 INLINE int GetNaturalReachBonus(Race race) 00297 { 00298 if(race == Troll) 00299 return TROLL_REACH_BONUS; 00300 00301 return 0; 00302 } 00303 } 00304 00305 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.