home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2006 April
/
Gamestar_83_2006-04_dvd.iso
/
Dema
/
demowot_english.exe
/
Script
/
Source
/
beh_Patrol.sma
< prev
next >
Wrap
Text File
|
2005-03-11
|
5KB
|
177 lines
// BUGOK:
// Akkor is iranyba fordul, ha -1 az ido
//
// FEATURE REQUEST:
// Ha forgathato a torony, akkor tornyot fordit oda odafordulas helyett
// Todo: set speed from code
// Todo: hold formation - don't hold formation
// Todo: tankoknal csoforditas
// Todo: mozgas vegen ne lassitsunk
// Todo: generate events at every waypoint, and others
#include "script.inc"
// GLOBALS:
// Max ilyen hosszu lehet az utvonal:
#define MAX_WAYPOINTS 40
new gGroup[STR_PROP_MAX_LENGTH]; // Akiket vegigvezetjuk a palyan
new Float:gSpeed; // Ilyen sebesseggel. -1 => max, 0 => leglassubb, >0 => probald ezzel
new eMovementStyle:gMovementStyle; // 0 => mindenki ahogy van (?), 1 => run, 2 => crawl, 3 => walk
new bool:gTwoWays; // 1 => oda-vissza, 0 => korbe-korbe
new Float:gLookAtWPDirThisTime; // float, ennyi ideig nez a waypoint iranyaba, mielott tovabbmegy
new DrID:gComp; // Ebbol a komponensbol kerjuk majd le az ertekeket
new DrID:gLastWaypoint; // Itt kell eventet dobni
new DrID:gSelf;
// ARRAYS:
new DrID:gWaypoints[MAX_WAYPOINTS+1]; // Ez definialja az utvonalat
const Float:gWheeledExtraWait = 5.0; // Kerekes jarmuvek es emberek ennyivel tovabb varnak, mint lanctalpasok (mivel ok nem tudnak fordulni)
//======================================================================================================
public PatrolInit()
{
gSelf = GetEntity( "self" );
gComp = GetComponent( gSelf, "cCpScriptVariable" );
if( IsDebugLevelOK( DL_BEHAVIOR )) {
new Message[100];
GetPropertyString( gSelf, "StringID", 100, Message );
ConcatString( Message, 100, "Patrol initialized: ", Message );
DebugMessage( Message, DL_MESSAGE );
}
// Valtozok feltoltese:
new TmpString[STR_PROP_MAX_LENGTH];
GetVarString( gComp, "Group", STR_PROP_MAX_LENGTH, gGroup );
gSpeed = Float:GetVar( gComp, "Speed" );
gMovementStyle = eMovementStyle:GetVar( gComp, "MovementStyle" );
gTwoWays = bool:GetVar( gComp, "TwoWays" );
gLookAtWPDirThisTime = Float:GetVar( gComp, "LookAtWPDirThisTime" ); //?
// Waypointok tombjenek feltoltese:
new i = GetArrayLength( gComp, "Waypoints" );
gWaypoints[i + 1] = DrID:0; // Terminating zero to simplify iterations
for( ; i >=0 ; i-- ) {
GetArrayVarString( gComp, "Waypoints", i, STR_PROP_MAX_LENGTH, TmpString );
gWaypoints[i] = GetEntity( TmpString );
}
AddAKEntityEvent( "mUnitArrived", ANY_ENTITY, UNIT_ARRIVED );
}
//======================================================================================================
public PatrolStart()
{
// Exit if this is not the target entity of the message
if( !IsTarget( gSelf )) return false;
if( IsDebugLevelOK( DL_BEHAVIOR )) {
new Message[100];
GetPropertyString( GetEntity( "self" ), "StringID", 100, Message );
ConcatString( Message, 100, "Patrol started: ", Message );
DebugMessage( Message, DL_MESSAGE );
}
new eQueuing:Queuing;
new Float:TmpVec3[vec3];
new wp = 0;
new Float:TmpDirection = 0.0;
new DrID:TmpUnit;
// Stop before:
CmdGroupStop( gGroup, Q_OVERRIDE );
// Set Movement Style:
if( gMovementStyle != MS_NONE )
CmdGroupSetMS( gGroup, Q_OVERRIDE, gMovementStyle );
// Set Speed:
if( gSpeed < 0.0 ) { // Set the speed to the slowest unit's speed
TmpUnit = GetSlowestUnitInSelector( gGroup, gMovementStyle );
if( !TmpUnit )
return false; // Exit function if there is no units in the selector
SetSpeedInSelector( gGroup, GetMaxSpeed( TmpUnit, gMovementStyle ));
}
else // Try this speed (if 0.0, then the units move at maximum speed)
SetSpeedInSelector( gGroup, gSpeed );
// Iterate waypoints (first part):
for( wp = 0; gWaypoints[wp]; wp++ ) {
Queuing = ( wp == 0 ) ? Q_OVERRIDE : Q_CYCLE;
GetPropertyVec3( gWaypoints[wp], "Pos", TmpVec3 );
CmdGroupMove( gGroup, Queuing, TmpVec3 );
new str[20];
Float2Str( gLookAtWPDirThisTime, str, 20 );
DebugMessage( str, DL_BEHAVIOR )
if( gLookAtWPDirThisTime >= 0.0 ) { // Turn to direction and wait
TmpDirection = GetEntityDir( gWaypoints[wp], DB_X_AXIS );
CmdGroupTurnToDir( gGroup, Q_CYCLE, TmpDirection, DB_X_AXIS );
CmdGroupWait( gGroup, Q_CYCLE, gLookAtWPDirThisTime );
}
}
// Iterate waypoints (second part):
wp--;
if( gTwoWays ) { // Ketiranyu bejaras
do {
GetPropertyVec3( gWaypoints[wp], "Pos", TmpVec3 );
CmdGroupMove( gGroup, Queuing, TmpVec3 );
if( gLookAtWPDirThisTime >= 0.0 ) { // Turn to direction and wait
TmpDirection = GetEntityDir( gWaypoints[wp], DB_X_AXIS );
CmdGroupTurnToDir( gGroup, Q_CYCLE, TmpDirection, DB_X_AXIS );
CmdGroupWait( gGroup, Q_CYCLE, gLookAtWPDirThisTime );
}
} while( wp-- );
gLastWaypoint = gWaypoints[0];
} else { // Korkoros bejaras
GetPropertyVec3( gWaypoints[0], "Pos", TmpVec3 );
CmdGroupMove( gGroup, Q_CYCLE, TmpVec3 );
gLastWaypoint = gWaypoints[wp];
}
return true;
}
public mUnitArrived( DrID:Unit )
{
if( GetMsgParamObject() != gLastWaypoint )
return false;
if( !IsInSelector( Unit, gGroup ))
return false;
CallUserEvent( UEM_PATROL_END );
return true;
}