Debugging: Streamlined functions

Another possible option was a parameter for the log level, but I decided against it, because differently named functions feel better than a string constant as a parameter.. Removed some annoying log outputs that I added before.

 Any suggestions for the function names are welcome, because I am not quite happy with the names yet. The distinction between normal output and warning is maybe not even necessary.
install-platforms
Mark 2017-06-23 23:19:42 +02:00
parent dddf5e223a
commit fc4a1660da
5 changed files with 18 additions and 18 deletions

View File

@ -13,9 +13,17 @@ public func OnDefineAI(proplist def)
def->GetControlEffect().DebugLoggingOn = false; // Whether or not debug logging is turned on.
}
public func LogAI(effect fx, string message)
public func LogAI_Warning(effect fx, string message)
{
if (fx.DebugLoggingOn)
Log("[%d]AI WARNING (%v): %s", FrameCounter(), fx.Target, message);
Log("[%d] AI WARNING (%v): %s", FrameCounter(), fx.Target, message);
return;
}
// Logs AI info
public func LogAI_Info(proplist fx, string message)
{
if (fx.DebugLoggingOn)
Log("[%d] AI INFO (%v): %s", FrameCounter(), fx.Target, message);
return;
}

View File

@ -112,7 +112,7 @@ public func ExecuteStand(effect fx)
}
else
{
this->LogAI(fx, Format("ExecuteStand has no idea what to do for action %v and procedure %v.", fx.Target->GetAction(), fx.Target->GetProcedure()));
this->~LogAI_Warning(fx, Format("ExecuteStand has no idea what to do for action %v and procedure %v.", fx.Target->GetAction(), fx.Target->GetProcedure()));
// Hm. What could it be? Let's just hope it resolves itself somehow...
fx.Target->SetComDir(COMD_Stop);
}

View File

@ -145,7 +145,6 @@ 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,13 +289,6 @@ private func EditorProp_AIType(id type)
local Plane = 300;
public func DebugLogAI(proplist fx_ai, string message)
{
if (fx_ai.DebugLoggingOn)
DebugLog(message);
}
/*-- Callbacks --*/
// Callback from the effect Construction()-call

View File

@ -79,7 +79,7 @@ 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));
this->LogAI_Warning(fx, Format("Weapon %v is out of ammo, AI won't do anything.", fx.weapon));
fx.weapon = nil;
return false;
}
@ -87,7 +87,7 @@ public func Execute(effect fx, int time)
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));
this->LogAI_Info(fx, Format("Forgetting target %v, because it is dead or out of range", fx.target));
fx.target = nil;
}
if (!fx.target)
@ -95,7 +95,7 @@ public func Execute(effect fx, int time)
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");
this->LogAI_Warning(fx, Format("Will call ExecuteIdle, because there is no target. Auto-searching for target %v", fx.auto_search_target));
return ExecuteIdle(fx);
}
// First encounter callback. might display a message.
@ -126,9 +126,9 @@ public func Execute(effect fx, int time)
this->ExecuteAppearance(fx);
// 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->LogAI_Warning(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));
this->LogAI_Info(fx, Format("Calling strategy: %v", fx.strategy));
return this->Call(fx.strategy, fx);
}
@ -183,7 +183,7 @@ public func ExecuteArm(effect fx)
{
if (this->CheckVehicleAmmo(fx, fx.weapon))
{
this->DebugLogAI(fx, "Vehicle ammo is ok");
this->LogAI_Info(fx, "Vehicle ammo is ok");
fx.strategy = this.ExecuteVehicle;
fx.ranged = true;
fx.aim_wait = 20;
@ -192,7 +192,7 @@ public func ExecuteArm(effect fx)
}
else
{
this->DebugLogAI(fx, "Vehicle ammo is not ok. Weapon is %v, vehicle is %v", fx.weapon, fx.vehicle);
this->LogAI_Info(fx, "Vehicle ammo is not ok. Weapon is %v, vehicle is %v", fx.weapon, fx.vehicle);
fx.weapon = nil;
}
}