Files
dsrc/sku.0/sys.server/compiled/game/script/city/droid_wander.script
T
2013-09-10 23:17:15 -07:00

179 lines
4.8 KiB
Plaintext

include library.ai_lib;
include library.utils;
const string[] patrolPoints = {
"droid1", "droid2", "droid3", "droid4", "droid5", "droid6"
};
const int PATH_VERIFICATION_TIME = 30;
const int PATH_FAILURES_MAXIMUM = 5;
trigger OnAttach()
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.OnAttach enter");
utils.setScriptVar(self, "path.timeCompleted", getGameTime());
utils.setScriptVar(self, "path.pathFailures", 0);
ai_lib.setDefaultCalmBehavior( self, ai_lib.BEHAVIOR_SENTINEL );
messageTo(self, "pathRandom", null, 1, false);
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.OnInitialize enter name: " + getName(self));
utils.setScriptVar(self, "path.timeCompleted", getGameTime());
utils.setScriptVar(self, "path.pathFailures", 0);
messageTo(self, "pathRandom", null, 1, false);
return SCRIPT_CONTINUE;
}
trigger OnLoiterMoving()
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.OnLoiterMoving enter name: " + getName(self));
stop(self);
messageTo(self, "pathRandom", null, 2, false);
return SCRIPT_OVERRIDE;
}
messageHandler pathRandom()
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.pathRandom enter name: " + getName(self));
params = new dictionary();
params.put("pathVerifyTime", getGameTime());
messageTo(self, "pathVerify", params, PATH_VERIFICATION_TIME - 1, false);
if(hasObjVar(self, "ai.inFormation"))
{
return SCRIPT_CONTINUE;//this guy is following someone
}
else
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.pathRandom setting patrol points");
ai_lib.setPatrolRandomNamedPath(self, patrolPoints);
}
return SCRIPT_CONTINUE;
}
messageHandler pathVerify()
{
if(aiGetMovementState(self) != MOVEMENT_PATROL || hasCondition(self, CONDITION_HIBERNATING))
{
return SCRIPT_CONTINUE;
}
int timeCompleted = utils.getIntScriptVar(self, "path.timeCompleted");
int lastVerify = utils.getIntScriptVar(self, "path.pathVerifyTime");
int pathFailures = utils.getIntScriptVar(self, "path.pathFailures");
location lastPathLocation = utils.getLocationScriptVar(self, "path.lastLocation");
int gameTime = getGameTime();
int pathVerifyTime = params.getInt("pathVerifyTime");
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.pathVerify enter name: " + getName(self));
if(lastVerify > pathVerifyTime)
{
return SCRIPT_CONTINUE;
}
utils.setScriptVar(self, "path.pathVerifyTime", pathVerifyTime);
params = new dictionary();
params.put("pathVerifyTime", gameTime);
if(timeCompleted + PATH_VERIFICATION_TIME > gameTime)
{
messageTo(self, "pathVerify", params, PATH_VERIFICATION_TIME - 1, false);
return SCRIPT_CONTINUE;
}
float distance = utils.getDistance2D(getLocation(self), lastPathLocation);
utils.setScriptVar(self, "path.lastLocation", getLocation(self));
if(distance > 1.0f)
{
utils.setScriptVar(self, "path.timeCompleted", getGameTime());
utils.setScriptVar(self, "path.pathFailures", 0);
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.pathVerify() found the distance between now and last check to be " + distance + " meters. name: " + getName(self));
messageTo(self, "pathVerify", params, PATH_VERIFICATION_TIME - 1, false);
return SCRIPT_CONTINUE;
}
if(pathFailures > PATH_FAILURES_MAXIMUM)
{
LOG("guard_wander", "Patrol pathfinding failures exceeded (5). Stopping self: " + self + " getName: " + getName(self) + " at " + getLocation(self));
stop(self);
utils.setScriptVar(self, "path.timeCompleted", getGameTime());
utils.setScriptVar(self, "path.pathFailures", 0);
messageTo(self, "pathRandom", params, 600, false);
return SCRIPT_CONTINUE;
}
if(hasObjVar(self, "ai.inFormation"))
{
ai_lib.resumeFormationFollowing(self);
return SCRIPT_CONTINUE;
}
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.pathVerify() messaging pathRandom() for " + getName(self) + " pathFailures: " + pathFailures);
pathFailures++;
utils.setScriptVar(self, "path.pathFailures", pathFailures);
messageTo(self, "pathRandom", params, 3, false);
return SCRIPT_CONTINUE;
}
trigger OnMovePathComplete()
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.OnMovePathComplete enter name: " + getName(self));
utils.setScriptVar(self, "path.timeCompleted", getGameTime());
utils.setScriptVar(self, "path.pathFailures", 0);
messageTo(self, "pathRandom", null, rand(30, 60), false);
return SCRIPT_CONTINUE;
}
trigger OnMovePathNotFound()
{
LOGC(aiLoggingEnabled(self), "debug_ai", "guard_wander.OnMovePathNotFound enter name: " + getName(self));
messageTo(self, "pathRandom", null, rand(30, 60), false);
return SCRIPT_CONTINUE;
}
trigger OnHibernateEnd()
{
dictionary params = new dictionary();
params.put("pathVerifyTime", getGameTime());
messageTo(self, "pathVerify", params, PATH_VERIFICATION_TIME - 1, false);
return SCRIPT_CONTINUE;
}