Debugging: More log output

Will streamline the two different functions later on. The difference is, that one function issues a warning, while the other merely provides information. Logging calls in components have to be called failsafe, because the cannot rely on the actual AI implementation including AI_Debugging.

This helps me understand why the catapult in AI test #7 does not fire. The solution is very interesting: The AI executes the idle strategy as long as it has no contents. After giving contents to the AI it executes the catapult strategy.
install-platforms
Mark 2017-06-23 22:20:09 +02:00
parent d9f7147dd3
commit fe9ef89cf4
3 changed files with 16 additions and 6 deletions

View File

@ -145,6 +145,7 @@ private func ExecuteCatapult(effect fx)
private func CheckCatapultAmmo(effect fx, object vehicle)
{
this->~DebugLogAI(fx, Format("Contents count in vehicle %d, contents count in target %d", vehicle->ContentsCount(), fx.Target->ContentsCount()));
// Must have ammo in the catapult or in the clonk (or be respawning ammo)
return vehicle->ContentsCount() > 0 || fx.Target->ContentsCount() > 0 || fx.has_ammo_respawn;
}

View File

@ -289,12 +289,9 @@ private func EditorProp_AIType(id type)
local Plane = 300;
local DebugLoggingEnabled = false; // Whether or not debug logging is turned on.
public func DebugLogAI(string message)
public func DebugLogAI(proplist fx_ai, string message)
{
if (AI_Controller.DebugLoggingEnabled)
if (fx_ai.DebugLoggingOn)
DebugLog(message);
}

View File

@ -79,19 +79,25 @@ public func Execute(effect fx, int time)
// Weapon out of ammo?
if (fx.ammo_check && !this->Call(fx.ammo_check, fx, fx.weapon))
{
this->LogAI(fx, Format("Weapon %v is out of ammo, AI won't do anything.", fx.weapon));
fx.weapon = nil;
this->LogAI(fx, Format("weapon %v is out of ammo, AI won't do anything.", fx.weapon));
return false;
}
// Find an enemy.
if (fx.target)
if ((fx.target->GetCategory() & C4D_Living && !fx.target->GetAlive()) || (!fx.ranged && fx.Target->ObjectDistance(fx.target) >= fx.max_aggro_distance))
{
this->DebugLogAI(fx, Format("Forgetting target %v, because it is dead or out of range", fx.target));
fx.target = nil;
}
if (!fx.target)
{
this->CancelAiming(fx);
if (!fx.auto_search_target || !(fx.target = this->FindTarget(fx)))
{
this->DebugLogAI(fx, "No target found or not looking for target - will execute idle strategy");
return ExecuteIdle(fx);
}
// First encounter callback. might display a message.
if (fx.encounter_cb)
if (GameCall(fx.encounter_cb, fx.Target, fx.target))
@ -121,6 +127,8 @@ public func Execute(effect fx, int time)
// Attack it!
if (!this->IsWeaponForTarget(fx))
this->LogAI(fx, Format("weapon of type %i is not fit to attack %v (type: %i).", fx.weapon->GetID(), fx.target, fx.target->GetID()));
this->DebugLogAI(fx, Format("Calling strategy: %v", fx.strategy));
return this->Call(fx.strategy, fx);
}
@ -175,6 +183,7 @@ public func ExecuteArm(effect fx)
{
if (this->CheckVehicleAmmo(fx, fx.weapon))
{
this->DebugLogAI(fx, "Vehicle ammo is ok");
fx.strategy = this.ExecuteVehicle;
fx.ranged = true;
fx.aim_wait = 20;
@ -182,7 +191,10 @@ public func ExecuteArm(effect fx)
return true;
}
else
{
this->DebugLogAI(fx, "Vehicle ammo is not ok. Weapon is %v, vehicle is %v", fx.weapon, fx.vehicle);
fx.weapon = nil;
}
}
// Find a weapon. Depends on attack mode
if (Call(fx.attack_mode.FindWeapon, fx))