Skip to content

Commit

Permalink
Remove the distinction between short and long range for accuracy purp…
Browse files Browse the repository at this point in the history
…oses.

Everything is now shooting at long range accuracy.
  • Loading branch information
perim committed Aug 11, 2012
1 parent 244c8ec commit 30e0f8e
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 130 deletions.
14 changes: 3 additions & 11 deletions src/action.cpp
Expand Up @@ -185,15 +185,8 @@ static bool actionInAttackRange(DROID *psDroid, BASE_OBJECT *psObj, int weapon_s
}
else
{
if (weaponShortHit(psStats, psDroid->player) > weaponLongHit(psStats, psDroid->player))
{
rangeSq = psStats->shortRange * psStats->shortRange;
}
else
{
longRange = proj_GetLongRange(psStats);
rangeSq = longRange * longRange;
}
longRange = proj_GetLongRange(psStats);
rangeSq = longRange * longRange;
}

/* check max range */
Expand Down Expand Up @@ -1830,9 +1823,8 @@ void actionUpdateDroid(DROID *psDroid)
if (!isVtolDroid(psDroid) &&
(order->psObj->type != OBJ_STRUCTURE))
{
//move droids to within short range of the sensor now!!!!
Vector2i diff = removeZ(psDroid->pos - order->psObj->pos);
int rangeSq = asWeaponStats[psDroid->asWeaps[0].nStat].shortRange;
int rangeSq = asWeaponStats[psDroid->asWeaps[0].nStat].longRange / 2; // move close to sensor
rangeSq = rangeSq * rangeSq;
if (diff*diff < rangeSq)
{
Expand Down
7 changes: 1 addition & 6 deletions src/combat.cpp
Expand Up @@ -162,12 +162,7 @@ bool combFire(WEAPON *psWeap, BASE_OBJECT *psAttacker, BASE_OBJECT *psTarget, in
}

int baseHitChance = 0;
if (dist <= psStats->shortRange && dist >= psStats->minRange)
{
// get weapon chance to hit in the short range
baseHitChance = weaponShortHit(psStats,psAttacker->player);
}
else if (dist <= longRange && dist >= psStats->minRange)
if (dist <= longRange && dist >= psStats->minRange)
{
// get weapon chance to hit in the long range
baseHitChance = weaponLongHit(psStats,psAttacker->player);
Expand Down
14 changes: 2 additions & 12 deletions src/function.cpp
Expand Up @@ -485,7 +485,7 @@ static bool loadWeaponUpgradeFunction(const char *pData)
WEAPON_UPGRADE_FUNCTION *psFunction;
char functionName[MAX_STR_LENGTH],
weaponSubClass[MAX_STR_LENGTH];
UDWORD firePause, shortHit, longHit, damage,
UDWORD firePause, dummyVal, longHit, damage,
radiusDamage, incenDamage, radiusHit;

//allocate storage
Expand All @@ -505,7 +505,7 @@ static bool loadWeaponUpgradeFunction(const char *pData)
functionName[0] = '\0';
weaponSubClass[0] = '\0';
sscanf(pData, "%255[^,'\r\n],%255[^,'\r\n],%d,%d,%d,%d,%d,%d,%d", functionName,
weaponSubClass, &firePause, &shortHit, &longHit, &damage, &radiusDamage,
weaponSubClass, &firePause, &dummyVal, &longHit, &damage, &radiusDamage,
&incenDamage, &radiusHit);

//allocate storage for the name
Expand All @@ -518,30 +518,24 @@ static bool loadWeaponUpgradeFunction(const char *pData)

//check none of the %increases are over UBYTE max
if (firePause > UBYTE_MAX ||
shortHit > UWORD_MAX ||
longHit > UWORD_MAX ||
damage > UWORD_MAX ||
radiusDamage > UWORD_MAX ||
incenDamage > UWORD_MAX ||
radiusHit > UWORD_MAX)
{
debug(LOG_ERROR, "A percentage increase for Weapon Upgrade function is too large");

return false;
}

//copy the data across
psFunction->firePause = (UBYTE)firePause;
psFunction->shortHit = (UWORD)shortHit;
psFunction->longHit = (UWORD)longHit;
psFunction->damage = (UWORD)damage;
psFunction->radiusDamage = (UWORD)radiusDamage;
psFunction->incenDamage = (UWORD)incenDamage;
psFunction->radiusHit = (UWORD)radiusHit;

//increment the number of upgrades
//numWeaponUpgrades++;

return true;
}

Expand Down Expand Up @@ -1153,10 +1147,6 @@ void weaponUpgrade(FUNCTION *pFunction, UBYTE player)
}
asWeaponUpgrade[player][pUpgrade->subClass].firePause = pUpgrade->firePause;
}
if (asWeaponUpgrade[player][pUpgrade->subClass].shortHit < pUpgrade->shortHit)
{
asWeaponUpgrade[player][pUpgrade->subClass].shortHit = pUpgrade->shortHit;
}
if (asWeaponUpgrade[player][pUpgrade->subClass].longHit < pUpgrade->longHit)
{
asWeaponUpgrade[player][pUpgrade->subClass].longHit = pUpgrade->longHit;
Expand Down
1 change: 0 additions & 1 deletion src/functiondef.h
Expand Up @@ -143,7 +143,6 @@ struct WEAPON_UPGRADE_FUNCTION : public FUNCTION
{
WEAPON_SUBCLASS subClass; /*which weapons are affected */
UBYTE firePause; /*The % to decrease the fire pause or reload time */
UWORD shortHit; /*The % to increase the short range accuracy */
UWORD longHit; /*The % to increase the long range accuracy */
UWORD damage; /*The % to increase the damage*/
UWORD radiusDamage; /*The % to increase the radius damage*/
Expand Down
8 changes: 4 additions & 4 deletions src/oprint.cpp
Expand Up @@ -168,11 +168,11 @@ static void printWeaponInfo(const WEAPON_STATS* psStats)

CONPRINTF(ConsoleString,(ConsoleString,"Weapon: "));
printComponentInfo((COMPONENT_STATS *)psStats);
CONPRINTF(ConsoleString,(ConsoleString," sRng %d lRng %d mRng %d %s\n"
" sHt %d lHt %d pause %d dam %d\n",
psStats->shortRange, proj_GetLongRange(psStats), psStats->minRange,
CONPRINTF(ConsoleString,(ConsoleString," lRng %d mRng %d %s\n"
" lHt %d pause %d dam %d\n",
proj_GetLongRange(psStats), psStats->minRange,
proj_Direct(psStats) ? "direct" : "indirect",
weaponShortHit(psStats,(UBYTE)selectedPlayer), weaponLongHit(psStats,
weaponLongHit(psStats,
(UBYTE)selectedPlayer), weaponFirePause(psStats,(UBYTE)selectedPlayer),
weaponDamage(psStats, (UBYTE)selectedPlayer)));
CONPRINTF(ConsoleString,(ConsoleString," rad %d radHt %d radDam %d\n"
Expand Down
22 changes: 0 additions & 22 deletions src/scriptfuncs.cpp
Expand Up @@ -10681,27 +10681,6 @@ static DROID_TEMPLATE* scrCheckTemplateExists(SDWORD player, DROID_TEMPLATE *psT
return NULL;
}

bool scrWeaponShortHitUpgrade(void)
{
SDWORD player,weapIndex;
const WEAPON_STATS *psWeapStats;

if (!stackPopParams(2, VAL_INT, &player, ST_WEAPON, &weapIndex))
{
return false;
}

psWeapStats = &asWeaponStats[weapIndex];

scrFunctionResult.v.ival = asWeaponUpgrade[player][psWeapStats->weaponSubClass].shortHit;
if (!stackPushResult(VAL_INT, &scrFunctionResult))
{
return false;
}

return true;
}

bool scrWeaponLongHitUpgrade(void)
{
SDWORD player,weapIndex;
Expand All @@ -10723,7 +10702,6 @@ bool scrWeaponLongHitUpgrade(void)
return true;
}


bool scrWeaponDamageUpgrade(void)
{
SDWORD player,weapIndex;
Expand Down
1 change: 0 additions & 1 deletion src/scriptfuncs.h
Expand Up @@ -651,7 +651,6 @@ extern bool scrMoveDroidStopped(void);
extern bool scrUpdateVisibleTiles(void);
extern bool scrCheckVisibleTile(void);
extern bool scrAssembleWeaponTemplate(void);
extern bool scrWeaponShortHitUpgrade(void);
extern bool scrWeaponLongHitUpgrade(void);
extern bool scrWeaponDamageUpgrade(void);
extern bool scrWeaponFirePauseUpgrade(void);
Expand Down
31 changes: 0 additions & 31 deletions src/scriptobj.cpp
Expand Up @@ -456,60 +456,29 @@ bool scrWeaponObjGet(UDWORD index)

switch (index)
{
case WEAPID_SHORT_RANGE:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].shortRange;

break;
case WEAPID_LONG_RANGE:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].longRange;

break;
case WEAPID_SHORT_HIT:
type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].shortHit;

break;
case WEAPID_LONG_HIT:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].longHit;

break;
case WEAPID_DAMAGE:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].damage;

break;
case WEAPID_FIRE_PAUSE:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].firePause;

break;
case WEAPID_RELOAD_TIME:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].reloadTime;

break;
case WEAPID_NUM_ROUNDS:

type = VAL_INT;

scrFunctionResult.v.ival = asWeaponStats[weapIndex].numRounds;

break;
default:
ASSERT( false, "unknown variable index" );
Expand Down
2 changes: 0 additions & 2 deletions src/scriptobj.h
Expand Up @@ -51,9 +51,7 @@ enum _objids
OBJID_SELECTED, // if droid is selected (humans only)
OBJID_TARGET, // added object->psTarget
OBJID_GROUP, // group a droid belongs to
WEAPID_SHORT_RANGE, // short range of a weapon
WEAPID_LONG_RANGE, // short range of a weapon
WEAPID_SHORT_HIT, // weapon's chance to hit in the short range
WEAPID_LONG_HIT, // weapon's chance to hit in the long range
WEAPID_FIRE_PAUSE, // weapon's fire pause
WEAPID_RELOAD_TIME, // weapon's reload time
Expand Down
12 changes: 0 additions & 12 deletions src/scripttabs.cpp
Expand Up @@ -1359,10 +1359,6 @@ FUNC_SYMBOL asFuncTable[] =
4, { VAL_INT, (INTERP_TYPE)ST_BODY, (INTERP_TYPE)ST_PROPULSION, (INTERP_TYPE)ST_WEAPON },
0, 0, NULL, 0, 0, NULL, NULL },

{ "weaponShortHitUpgrade", scrWeaponShortHitUpgrade, VAL_INT,
2, { VAL_INT, (INTERP_TYPE)ST_WEAPON },
0, 0, NULL, 0, 0, NULL, NULL },

{ "weaponLongHitUpgrade", scrWeaponLongHitUpgrade, VAL_INT,
2, { VAL_INT, (INTERP_TYPE)ST_WEAPON },
0, 0, NULL, 0, 0, NULL, NULL },
Expand Down Expand Up @@ -1633,18 +1629,10 @@ VAR_SYMBOL asObjTable[] =

/* Weapon Stats */

//weapon short range
{ "shortRange", VAL_INT, ST_OBJECT,
(INTERP_TYPE)ST_WEAPON, WEAPID_SHORT_RANGE, scrWeaponObjGet, NULL, 0, {0}, NULL },

//weapon long range
{ "longRange", VAL_INT, ST_OBJECT,
(INTERP_TYPE)ST_WEAPON, WEAPID_LONG_RANGE, scrWeaponObjGet, NULL, 0, {0}, NULL },

//weapon short hit chance
{ "shortHit", VAL_INT, ST_OBJECT,
(INTERP_TYPE)ST_WEAPON, WEAPID_SHORT_HIT, scrWeaponObjGet, NULL, 0, {0}, NULL },

//weapon long hit chance
{ "longHit", VAL_INT, ST_OBJECT,
(INTERP_TYPE)ST_WEAPON, WEAPID_LONG_HIT, scrWeaponObjGet, NULL, 0, {0}, NULL },
Expand Down
30 changes: 3 additions & 27 deletions src/stats.cpp
Expand Up @@ -625,7 +625,7 @@ bool loadWeaponStats(const char *pWeaponData, UDWORD bufferSize)
char fireOnMove[MAX_STR_LENGTH], weaponClass[MAX_STR_LENGTH], weaponSubClass[MAX_STR_LENGTH],
weaponEffect[MAX_STR_LENGTH], movement[MAX_STR_LENGTH], facePlayer[MAX_STR_LENGTH], //weaponEffect[15] caused stack corruption. --Qamly
faceInFlight[MAX_STR_LENGTH],lightWorld[MAX_STR_LENGTH];
UDWORD longRange, effectSize, numAttackRuns, designable;
UDWORD effectSize, numAttackRuns, designable;
UDWORD numRounds;

char *StatsName;
Expand Down Expand Up @@ -675,8 +675,8 @@ bool loadWeaponStats(const char *pWeaponData, UDWORD bufferSize)
WeaponName, dummy, &psStats->buildPower,&psStats->buildPoints,
&psStats->weight, &weaponsize, &dummyVal,
&psStats->body, GfxFile, mountGfx, muzzleGfx, flightGfx,
hitGfx, missGfx, waterGfx, trailGfx, &psStats->shortRange,
&psStats->longRange,&psStats->shortHit, &psStats->longHit,
hitGfx, missGfx, waterGfx, trailGfx, &dummyVal,
&psStats->longRange, &dummyVal, &psStats->longHit,
&psStats->firePause, &psStats->numExplosions, &numRounds,
&psStats->reloadTime, &psStats->damage, &psStats->radius,
&psStats->radiusHit, &psStats->radiusDamage, &psStats->incenTime,
Expand Down Expand Up @@ -997,24 +997,6 @@ bool loadWeaponStats(const char *pWeaponData, UDWORD bufferSize)
psStats->penetrate = false;
}

// error check the ranges
if (psStats->flightSpeed > 0 && !proj_Direct(psStats))
{
longRange = (UDWORD)proj_GetLongRange(psStats);
}
else
{
longRange = UDWORD_MAX;
}
if (psStats->shortRange > longRange)
{
debug( LOG_NEVER, "%s, flight speed is too low to reach short range (max range %d)\n", WeaponName, longRange );
}
else if (psStats->longRange > longRange)
{
debug( LOG_NEVER, "%s, flight speed is too low to reach long range (max range %d)\n", WeaponName, longRange );
}

//set the weapon sounds to default value
psStats->iAudioFireID = NO_SOUND;
psStats->iAudioImpactID = NO_SOUND;
Expand Down Expand Up @@ -2851,12 +2833,6 @@ UDWORD weaponReloadTime(WEAPON_STATS *psStats, UBYTE player)
psStats->weaponSubClass].firePause)/100);
}

UDWORD weaponShortHit(const WEAPON_STATS* psStats, UBYTE player)
{
return (psStats->shortHit + (psStats->shortHit * asWeaponUpgrade[player][
psStats->weaponSubClass].shortHit)/100);
}

UDWORD weaponLongHit(const WEAPON_STATS* psStats, UBYTE player)
{
return (psStats->longHit + (psStats->longHit * asWeaponUpgrade[player][
Expand Down
1 change: 0 additions & 1 deletion src/statsdef.h
Expand Up @@ -445,7 +445,6 @@ struct REPAIR_STATS : public COMPONENT_STATS

struct WEAPON_STATS : public COMPONENT_STATS
{
UDWORD shortRange; ///< Max distance to target for short range shot
UDWORD longRange; ///< Max distance to target for long range shot
UDWORD minRange; ///< Min distance to target for shot
UDWORD shortHit; ///< Chance to hit at short range
Expand Down

0 comments on commit 30e0f8e

Please sign in to comment.