Remove Guard stuff for action Still

This commit is contained in:
joris 2012-02-23 10:41:14 +01:00
parent 3b792e8ec2
commit 373616150a
11 changed files with 4 additions and 208 deletions

View file

@ -83,7 +83,6 @@ int DoActionMove(CUnit &unit)
// FIXME: So units flying up and down are not affected.
unit.IX = unit.IY = 0;
MapUnmarkUnitGuard(unit);
UnmarkUnitFieldFlags(unit);
d = NextPathElement(unit, &posd.x, &posd.y);
MarkUnitFieldFlags(unit);

View file

@ -80,70 +80,9 @@
-- Functions
----------------------------------------------------------------------------*/
static void MapMarkTileGuard(const CPlayer &player, const unsigned int index)
{
++Map.Field(index)->Guard[player.Index];
}
static void MapUnmarkTileGuard(const CPlayer &player, const unsigned int index)
{
Assert(Map.Field(index)->Guard[player.Index] > 0);
--Map.Field(index)->Guard[player.Index];
}
void MapMarkUnitGuard(CUnit &unit)
{
if (unit.IsAgressive() && !unit.GuardLock) {
if (!unit.Removed) {
unit.GuardLock = 1;
MapSight(*unit.Player, unit.tilePos,
unit.Type->TileWidth, unit.Type->TileHeight,
unit.GetReactRange(),
MapMarkTileGuard);
} else {
CUnit *c = unit.Container;
if (c && c->Type->AttackFromTransporter) {
unit.GuardLock = 1;
MapSight(*unit.Player, c->tilePos,
c->Type->TileWidth, c->Type->TileHeight,
unit.GetReactRange(), MapMarkTileGuard);
}
}
}
}
void MapUnmarkUnitGuard(CUnit &unit)
{
if (unit.IsAgressive() && unit.GuardLock) {
if (!unit.Removed) {
unit.GuardLock = 0;
MapSight(*unit.Player, unit.tilePos,
unit.Type->TileWidth, unit.Type->TileHeight,
unit.GetReactRange(), MapUnmarkTileGuard);
} else {
CUnit *c = unit.Container;
if (c && c->Type->AttackFromTransporter) {
unit.GuardLock = 0;
MapSight(*unit.Player, c->tilePos,
c->Type->TileWidth, c->Type->TileHeight,
unit.GetReactRange(), MapUnmarkTileGuard);
}
}
}
}
void UnHideUnit(CUnit &unit)
{
const int action = unit.CurrentAction();
const bool mark_guard = (action == UnitActionStill ||
action == UnitActionStandGround) &&
unit.Variable[INVISIBLE_INDEX].Value > 0;
unit.Variable[INVISIBLE_INDEX].Value = 0;
if (mark_guard)
{
MapMarkUnitGuard(unit);
}
}
/**
@ -195,7 +134,6 @@ static bool MoveRandomly(CUnit &unit)
order->Range = 0;
order->goalPos = pos;
unit.State = 0;
MapUnmarkUnitGuard(unit);
//return true;//TESTME: new localization
}
MarkUnitFieldFlags(unit);
@ -340,45 +278,6 @@ bool AutoAttack(CUnit &unit, bool stand_ground)
return true;
}
void AutoAttack(CUnit &unit, CUnitCache &targets, bool stand_ground)
{
// Cowards and invisible units don't attack unless ordered.
if (unit.IsAgressive()) {
// Normal units react in reaction range.
if (!stand_ground && !unit.Removed && unit.CanMove()) {
CUnit *goal = AutoAttackUnitsInDistance(unit, unit.GetReactRange(), targets);
if (goal) {
// Weak goal, can choose other unit, come back after attack
CommandAttack(unit, goal->tilePos, NULL, FlushCommands);
COrder *savedOrder = COrder::NewActionAttack(unit, unit.tilePos);
if (unit.StoreOrder(savedOrder) == false) {
delete savedOrder;
}
}
// Removed units can only attack in AttackRange, from bunker
} else {
CUnit *goal = AutoAttackUnitsInDistance(unit, unit.Stats->Variables[ATTACKRANGE_INDEX].Max, targets);
if (goal) {
CUnit *temp = unit.CurrentOrder()->GetGoal();
if (temp && temp->CurrentAction() == UnitActionDie) {
unit.CurrentOrder()->ClearGoal();
temp = NoUnitP;
}
if (unit.SubAction < SUB_STILL_ATTACK || temp != goal) {
// New target.
unit.CurrentOrder()->SetGoal(goal);
unit.State = 0;
unit.SubAction = SUB_STILL_ATTACK; // Mark attacking.
UnitHeadingFromDeltaXY(unit, goal->tilePos + goal->Type->GetHalfTileSize() - unit.tilePos);
}
}
}
}
}
/**
@ -401,7 +300,6 @@ void ActionStillGeneric(CUnit &unit, bool stand_ground)
switch (unit.SubAction) {
case SUB_STILL_INIT: //first entry
MapMarkUnitGuard(unit);
unit.SubAction = SUB_STILL_STANDBY;
// no break : follow
case SUB_STILL_STANDBY:

View file

@ -535,7 +535,6 @@ extern void CommandSharedVision(int player, bool state, int opponent);
extern void DropResource(CUnit &unit);
extern void ResourceGiveUp(CUnit &unit);
extern int GetNumWaitingWorkers(const CUnit &mine);
extern void AutoAttack(CUnit &unit, CUnitCache &targets, bool stand_ground);
extern bool AutoAttack(CUnit &unit, bool stand_ground);
extern bool AutoRepair(CUnit &unit);
extern bool AutoCast(CUnit &unit);

View file

@ -581,9 +581,6 @@ void MapMarkUnitSight(CUnit &unit);
/// Unmark on vision table the Sight of the unit.
void MapUnmarkUnitSight(CUnit &unit);
void MapMarkUnitGuard(CUnit &unit);
void MapUnmarkUnitGuard(CUnit &unit);
/*----------------------------------------------------------------------------
-- Defines
----------------------------------------------------------------------------*/

View file

@ -363,7 +363,6 @@ public:
// Upgrades/Allows:
CAllow Allow; /// Allowed for player
CUpgradeTimers UpgradeTimers; /// Timer for the upgrades
CUnitCache AutoAttackTargets; /// Current know autoattack targets
/// Change player side
void SetSide(int side);

View file

@ -151,7 +151,6 @@ public:
#endif
{
memset(Visible, 0, sizeof(Visible));
memset(Guard, 0, sizeof(Guard));
memset(VisCloak, 0, sizeof(VisCloak));
memset(Radar, 0, sizeof(Radar));
memset(RadarJammer, 0, sizeof(RadarJammer));
@ -165,7 +164,6 @@ public:
// different.
unsigned char Value; /// HP for walls/ Wood Regeneration
unsigned short Visible[PlayerMax]; /// Seen counter 0 unexplored
unsigned short Guard[PlayerMax]; /// Guard counter for autoatack: 0 unguarded
unsigned char VisCloak[PlayerMax]; /// Visiblity for cloaking.
unsigned char Radar[PlayerMax]; /// Visiblity for radar.
unsigned char RadarJammer[PlayerMax]; /// Jamming capabilities.

View file

@ -531,7 +531,6 @@ public:
unsigned Active : 1; /// Unit is active for AI
unsigned Boarded : 1; /// Unit is on board a transporter.
unsigned CacheLock : 1; /// Unit is on lock by unitcache operations.
unsigned GuardLock : 1; /// Unit is on lock by guard operations.
/** set to random 1..100 when MakeUnit()
** used for fancy buildings

View file

@ -269,30 +269,6 @@ void SavePlayers(CFile *file)
}
file->printf("}");
if (p.AutoAttackTargets.size() > 0) {
file->printf("\n \"enemy-targets\", {");
CUnitCache &autoatacktargets = const_cast<CUnitCache &>(p.AutoAttackTargets);
for(unsigned int k = 0; k < autoatacktargets.size();)
{
CUnit &aatarget = *autoatacktargets[k];
//Additional security
if (!aatarget.IsAliveOnMap() ||
Map.Field(aatarget.tilePos)->Guard[i] == 0) {
autoatacktargets.Units.erase(autoatacktargets.Units.begin() + k);
aatarget.RefsDecrease();
continue;
}
if (k) {
file->printf(" ,");
}
file->printf("\"%s\"", UnitReference(aatarget).c_str());
++k;
}
file->printf("}");
}
file->printf(")\n\n");
}
@ -321,8 +297,6 @@ void CreatePlayer(int type)
// FIXME: A: Johns: currently we need no init for the nobody player.
memset(player.Units, 0, sizeof (player.Units));
player.AutoAttackTargets.clear();
//
// Take first slot for person on this computer,
// fill other with computer players.
@ -534,7 +508,6 @@ void CPlayer::Clear()
TotalKills = 0;
Color = 0;
UpgradeTimers.Clear();
AutoAttackTargets.clear();
}
/*----------------------------------------------------------------------------
@ -760,34 +733,10 @@ void PlayersInitAi()
void PlayersEachCycle()
{
for (int player = 0; player < NumPlayers; ++player) {
CPlayer *p = &Players[player];
if (p->AutoAttackTargets.size() > 0) {
CUnitCache &autoatacktargets = p->AutoAttackTargets;
/* both loops can not be connected !!!! */
for (unsigned int i = 0; i < autoatacktargets.size();) {
CUnit *aatarget = autoatacktargets[i];
if (!aatarget->IsAliveOnMap() ||
Map.Field(aatarget->Offset)->Guard[player] == 0) {
autoatacktargets.Units.erase(autoatacktargets.Units.begin() + i);
aatarget->RefsDecrease();
continue;
}
++i;
}
if (autoatacktargets.size() > 0) {
for (int j = 0; j < p->TotalNumUnits; ++j) {
CUnit &guard = *p->Units[j];
bool stand_ground = guard.CurrentAction() == UnitActionStandGround;
if (guard.Type->CanAttack &&
(stand_ground || guard.IsIdle()) &&
!guard.IsUnusable()) {
AutoAttack(guard, autoatacktargets, stand_ground);
}
}
}
}
if (p->AiEnabled) {
AiEachCycle(p);
CPlayer &p = Players[player];
// AutoAttack(guard, autoatacktargets, stand_ground);
if (p.AiEnabled) {
AiEachCycle(&p);
}
}
}

View file

@ -361,17 +361,6 @@ static int CclPlayer(lua_State *l)
player->UpgradeTimers.Upgrades[k] = LuaToNumber(l, -1);
lua_pop(l, 1);
}
} else if (!strcmp(value, "enemy-targets")) {
if (!lua_istable(l, j + 1)) {
LuaError(l, "incorrect argument");
}
subargs = lua_objlen(l, j + 1);
for (k = 0; k < subargs; ++k) {
lua_rawgeti(l, j + 1, k + 1);
CclGetUnitFromRef(l);
player->AutoAttackTargets.Insert(CclGetUnitFromRef(l));
lua_pop(l, 1);
}
} else {
LuaError(l, "Unsupported tag: %s" _C_ value);
}

View file

@ -747,10 +747,6 @@ static bool CommandKey(int key)
return true;
}
#if defined(DEBUG) || defined(PROF)
extern void MapUnmarkUnitGuard(CUnit &unit);
#endif
/**
** Handle cheats
**
@ -774,17 +770,6 @@ int HandleCheats(const std::string &input)
SetMessage("Cannot disable 'ai me' cheat");
#endif
} else {
for (int j = 0; j < ThisPlayer->TotalNumUnits; ++j) {
CUnit *guard = ThisPlayer->Units[j];
bool stand_ground =
guard->CurrentAction() == UnitActionStandGround;
if ((stand_ground || guard->IsIdle()) &&
!guard->IsUnusable()) {
MapUnmarkUnitGuard(*guard);
guard->SubAction = 0;
}
}
ThisPlayer->AiEnabled = 1;
ThisPlayer->Type = PlayerComputer;
if (!ThisPlayer->Ai) {

View file

@ -177,7 +177,6 @@ void CUnit::Init()
Moving = 0;
ReCast = 0;
CacheLock = 0;
GuardLock = 0;
memset(&Anim, 0, sizeof(Anim));
CurrentResource = 0;
OrderFlush = 0;
@ -793,17 +792,6 @@ static void UnitInXY(CUnit &unit, const Vec2i &pos)
unit.tilePos = pos;
unit.Offset = Map.getIndex(pos);
if (!unit.Container) {
//Only Top Units
const CMapField *const mf = Map.Field(unit.Offset);
const CPlayer *const p = unit.Player;
for (int player = 0; player < NumPlayers; ++player) {
if(player != p->Index && mf->Guard[player] && p->IsEnemy(player)) {
Players[player].AutoAttackTargets.InsertS(&unit);
unit.RefsIncrease();
}
}
}
for (int i = unit.InsideCount; i--; unit_inside = unit_inside->NextContained) {
UnitInXY(*unit_inside, pos);
}
@ -843,7 +831,6 @@ void CUnit::Place(const Vec2i &pos)
Assert(Removed);
if (Container) {
MapUnmarkUnitGuard(*this);
MapUnmarkUnitSight(*this);
RemoveUnitFromContainer(*this);
}
@ -908,7 +895,6 @@ void CUnit::Remove(CUnit *host)
Map.Remove(*this);
MapUnmarkUnitSight(*this);
UnmarkUnitFieldFlags(*this);
MapUnmarkUnitGuard(*this);
if (host) {
AddInContainer(*host);
@ -1665,11 +1651,9 @@ void CUnit::ChangeOwner(CPlayer &newplayer)
*PlayerSlot = this;
MapUnmarkUnitSight(*this);
MapUnmarkUnitGuard(*this);
Player = &newplayer;
Stats = &Type->Stats[newplayer.Index];
UpdateUnitSightRange(*this);
MapMarkUnitGuard(*this);
MapMarkUnitSight(*this);
// Must change food/gold and other.