Re: Units in combat modification (shot at)
Posted: Sat Feb 04, 2023 5:48 pm
I happen to have made a modding to such effect. The lines between 255 and 322 says:
// Can't shoot at friends
if ((GetUnitSide(me) != GetUnitSide(unit)))
{
// Can't shoot if in Close Combat or Pursuing.
if ((IsInCloseCombat(me) == 0) && (MightPursue(me) == 0))
{
// instead of hiding, only disable button if we got this far. SetShootingString() should give explanatory messages for all cases where ret = -1
ret = -1 ;
distance = GetDistanceBetween(me, unit);
if (distance <= maxRange)
{
// Check whether unit has terrain LOS to target. Need to do this before next test or shooting tooltip will be wrong for artillery that have already shot.
terrainLOSClear = GetUnitLOSToUnit(me, unit);
if((IsArtillery(me) == 1) && (GetAttrib(me, "moved") != 0))
{
// Artillery that moved cannot fire
}
else
{
// Check whether units blocking LOS to target and whether shooter has shots left
unitBlocksLOS = UnitBlockingLOS(me, unit);
if (((terrainLOSClear != 0) || (GetAttrib (me, "LOS") >= 2000)) && ((unitBlocksLOS == 0) || (GetAttrib (me, "LOS") >= 2000)) && (shots > 0))
{
// Troops in close combat cannot be shot at
if (IsInCloseCombat(me) == 0)
{
// Pursued routers cannot be shot at
if (IsInCloseCombat(me) == 0)
{
// Check whether in arc of fire
volley = ArcOfFire(me, unit);
if (volley > 0)
{
if ((reaction == 1) && (GetAttrib(me, "ReactionRange") == 0))
{
SetAttrib(me, "ReactionRange", distance);
SetAttrib(me, "ReactionArc", volley);
}
ret = 0;
if ((GetCannotControl(me) == 0) && (GetUnitSide(unit) != GetShowSide()) && (doNotSetIcons == 0))
{
if (volley == 3)
{
SetUnitIconMask(unit, 1 << 22); // Will be full arc icon
SetShootableFlag(unit, 2);
}
else
{
SetUnitIconMask(unit, 1 << 23); // Will be half arc icon
SetShootableFlag(unit, 1);
}
SetIndicatorEnemyFacing(unit, CorrectedFacing(me));
}
}
}
}
}
}
}
}
}
}
// Can't shoot at friends
if ((GetUnitSide(me) != GetUnitSide(unit)))
{
// Can't shoot if in Close Combat or Pursuing.
if ((IsInCloseCombat(me) == 0) && (MightPursue(me) == 0))
{
// instead of hiding, only disable button if we got this far. SetShootingString() should give explanatory messages for all cases where ret = -1
ret = -1 ;
distance = GetDistanceBetween(me, unit);
if (distance <= maxRange)
{
// Check whether unit has terrain LOS to target. Need to do this before next test or shooting tooltip will be wrong for artillery that have already shot.
terrainLOSClear = GetUnitLOSToUnit(me, unit);
if((IsArtillery(me) == 1) && (GetAttrib(me, "moved") != 0))
{
// Artillery that moved cannot fire
}
else
{
// Check whether units blocking LOS to target and whether shooter has shots left
unitBlocksLOS = UnitBlockingLOS(me, unit);
if (((terrainLOSClear != 0) || (GetAttrib (me, "LOS") >= 2000)) && ((unitBlocksLOS == 0) || (GetAttrib (me, "LOS") >= 2000)) && (shots > 0))
{
// Troops in close combat cannot be shot at
if (IsInCloseCombat(me) == 0)
{
// Pursued routers cannot be shot at
if (IsInCloseCombat(me) == 0)
{
// Check whether in arc of fire
volley = ArcOfFire(me, unit);
if (volley > 0)
{
if ((reaction == 1) && (GetAttrib(me, "ReactionRange") == 0))
{
SetAttrib(me, "ReactionRange", distance);
SetAttrib(me, "ReactionArc", volley);
}
ret = 0;
if ((GetCannotControl(me) == 0) && (GetUnitSide(unit) != GetShowSide()) && (doNotSetIcons == 0))
{
if (volley == 3)
{
SetUnitIconMask(unit, 1 << 22); // Will be full arc icon
SetShootableFlag(unit, 2);
}
else
{
SetUnitIconMask(unit, 1 << 23); // Will be half arc icon
SetShootableFlag(unit, 1);
}
SetIndicatorEnemyFacing(unit, CorrectedFacing(me));
}
}
}
}
}
}
}
}
}
}