Brief: //dnl ch61

- Basic support for reducing AI friendly fire.
Details:
- Friendly fire grids are defined during best shot calculation then AI decide depending of soldier character to fire or take other action. Still in autofire accidentally friendly hits could be higher depending of bullets spreading.


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6313 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Kriplo
2013-08-25 07:36:03 +00:00
parent 4ac9cf5ebe
commit f06df7741f
4 changed files with 107 additions and 2 deletions
+57 -2
View File
@@ -233,9 +233,11 @@ void CalcBestShot(SOLDIERTYPE *pSoldier, ATTACKTYPE *pBestShot, BOOLEAN shootUns
//KeepInterfaceGoing();
// calculate chance to get through the opponent's cover (if any)
//dnl ch61 180813
gUnderFire.Clear();
gUnderFire.Enable();
ubChanceToGetThrough = AISoldierToSoldierChanceToGetThrough( pSoldier, pOpponent );
gUnderFire.Disable();
// ubChanceToGetThrough = ChanceToGetThrough(pSoldier,pOpponent->sGridNo,NOTFAKE,ACTUAL,TESTWALLS,9999,M9PISTOL,NOT_FOR_LOS);
//NumMessage("Chance to get through = ",ubChanceToGetThrough);
@@ -494,6 +496,10 @@ void CalcBestShot(SOLDIERTYPE *pSoldier, ATTACKTYPE *pBestShot, BOOLEAN shootUns
pBestShot->iAttackValue = iAttackValue;
pBestShot->ubAPCost = ubMinAPcost;
pBestShot->bScopeMode = bScopeMode;
if(gUnderFire.Count(pSoldier->bTeam))//dnl ch61 180813
pBestShot->ubFriendlyFireChance = gUnderFire.Chance(pSoldier->bTeam);
else
pBestShot->ubFriendlyFireChance = 0;
}
}
pSoldier->bScopeMode = USE_BEST_SCOPE; // better reset this back
@@ -2894,3 +2900,52 @@ FLOAT AICalcRecoilForShot( SOLDIERTYPE *pSoldier, OBJECTTYPE *pWeapon, UINT8 ubS
FLOAT AverageRecoil = __max(0, ((FLOAT)sqrt( (FLOAT)(bRecoilX * bRecoilX) + (FLOAT)(bRecoilY * bRecoilY) ) - (gGameCTHConstants.RECOIL_MAX_COUNTER_FORCE * 0.7f) ) );
return AverageRecoil;
}
//dnl ch61 180813
UnderFire gUnderFire;
void UnderFire::Clear(void)
{
usUnderFireCnt = 0;
memset(usUnderFireID, 0, sizeof(usUnderFireID));
memset(ubUnderFireCTH, 0, sizeof(ubUnderFireCTH));
}
void UnderFire::Add(UINT16 usID, UINT8 ubCTH)
{
if(!fEnable)
return;
if(usUnderFireCnt < MAXUNDERFIRE)
{
for(int i=0; i<usUnderFireCnt; i++)
if(usUnderFireID[i] == usID)
{
if(ubUnderFireCTH[i] != ubCTH)
ubUnderFireCTH[i] = ubCTH;
return;
}
usUnderFireID[usUnderFireCnt++] = usID;
}
}
UINT16 UnderFire::Count(INT8 bTeam)
{
UINT16 cnt = 0;
for(int i=0; i<usUnderFireCnt; i++)
{
if(MercPtrs[usUnderFireID[i]]->bTeam == bTeam)
++cnt;
}
return(cnt);
}
UINT8 UnderFire::Chance(INT8 bTeam)
{
UINT8 cth = 0;
for(int i=0; i<usUnderFireCnt; i++)
{
if(MercPtrs[usUnderFireID[i]]->bTeam == bTeam && ubUnderFireCTH[i] > cth)
cth = ubUnderFireCTH[i];
}
return(cth);
}