Skip to content

Commit cc0756a

Browse files
committed
Use the stats to determine struct height and clean up establishTargetHeight function.
This should improve shooting over structures in 3.0. Refs #2331.
1 parent 7ec9e03 commit cc0756a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/projectile.c

+10-19
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#define DIRECT_PROJ_SPEED 500
6464
#define VTOL_HITBOX_MODIFICATOR 100
65+
#define STRUCT_HITBOX_MAPPER 32
6566

6667
typedef struct _interval
6768
{
@@ -2005,8 +2006,7 @@ UDWORD establishTargetHeight(BASE_OBJECT *psTarget)
20052006
case OBJ_DROID:
20062007
{
20072008
DROID * psDroid = (DROID*)psTarget;
2008-
unsigned int height = asBodyStats[psDroid->asBits[COMP_BODY].nStat].pIMD->max.y - asBodyStats[psDroid->asBits[COMP_BODY].nStat].pIMD->min.y;
2009-
unsigned int utilityHeight = 0, yMax = 0, yMin = 0; // Temporaries for addition of utility's height to total height
2009+
unsigned int height = asBodyStats[psDroid->asBits[COMP_BODY].nStat].pIMD->max.y;
20102010

20112011
// VTOL's don't have pIMD either it seems...
20122012
if (isVtolDroid(psDroid))
@@ -2023,29 +2023,24 @@ UDWORD establishTargetHeight(BASE_OBJECT *psTarget)
20232023
if ((asWeaponStats[psDroid->asWeaps[0].nStat]).pIMD == NULL)
20242024
return height;
20252025

2026-
yMax = (asWeaponStats[psDroid->asWeaps[0].nStat]).pIMD->max.y;
2027-
yMin = (asWeaponStats[psDroid->asWeaps[0].nStat]).pIMD->min.y;
2026+
height += (asWeaponStats[psDroid->asWeaps[0].nStat]).pIMD->max.y;
20282027
}
20292028
break;
20302029

20312030
case DROID_SENSOR:
2032-
yMax = (asSensorStats[psDroid->asBits[COMP_SENSOR].nStat]).pIMD->max.y;
2033-
yMin = (asSensorStats[psDroid->asBits[COMP_SENSOR].nStat]).pIMD->min.y;
2031+
height += (asSensorStats[psDroid->asBits[COMP_SENSOR].nStat]).pIMD->max.y;
20342032
break;
20352033

20362034
case DROID_ECM:
2037-
yMax = (asECMStats[psDroid->asBits[COMP_ECM].nStat]).pIMD->max.y;
2038-
yMin = (asECMStats[psDroid->asBits[COMP_ECM].nStat]).pIMD->min.y;
2035+
height += (asECMStats[psDroid->asBits[COMP_ECM].nStat]).pIMD->max.y;
20392036
break;
20402037

20412038
case DROID_CONSTRUCT:
2042-
yMax = (asConstructStats[psDroid->asBits[COMP_CONSTRUCT].nStat]).pIMD->max.y;
2043-
yMin = (asConstructStats[psDroid->asBits[COMP_CONSTRUCT].nStat]).pIMD->min.y;
2039+
height += (asConstructStats[psDroid->asBits[COMP_CONSTRUCT].nStat]).pIMD->max.y;
20442040
break;
20452041

20462042
case DROID_REPAIR:
2047-
yMax = (asRepairStats[psDroid->asBits[COMP_REPAIRUNIT].nStat]).pIMD->max.y;
2048-
yMin = (asRepairStats[psDroid->asBits[COMP_REPAIRUNIT].nStat]).pIMD->min.y;
2043+
height += (asRepairStats[psDroid->asBits[COMP_REPAIRUNIT].nStat]).pIMD->max.y;
20492044
break;
20502045

20512046
case DROID_PERSON:
@@ -2062,19 +2057,15 @@ UDWORD establishTargetHeight(BASE_OBJECT *psTarget)
20622057
return height;
20632058
}
20642059

2065-
// TODO: check the /2 - does this really make sense? why + ?
2066-
utilityHeight = (yMax + yMin)/2;
2067-
2068-
return height + utilityHeight;
2060+
return height;
20692061
}
20702062
case OBJ_STRUCTURE:
20712063
{
20722064
STRUCTURE_STATS * psStructureStats = ((STRUCTURE *)psTarget)->pStructureType;
2073-
return (psStructureStats->pIMD->max.y + psStructureStats->pIMD->min.y);
2065+
return psStructureStats->height * STRUCT_HITBOX_MAPPER; // Map stats to reasonable structure heights
20742066
}
20752067
case OBJ_FEATURE:
2076-
// Just use imd ymax+ymin
2077-
return (psTarget->sDisplay.imd->max.y + psTarget->sDisplay.imd->min.y);
2068+
return psTarget->sDisplay.imd->max.y;
20782069
case OBJ_PROJECTILE:
20792070
return BULLET_FLIGHT_HEIGHT;
20802071
default:

0 commit comments

Comments
 (0)