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 >
Text File  |  2005-03-11  |  5KB  |  177 lines

  1. // BUGOK:
  2. // Akkor is iranyba fordul, ha -1 az ido
  3. // 
  4. // FEATURE REQUEST:
  5. // Ha forgathato a torony, akkor tornyot fordit oda odafordulas helyett
  6.  
  7. // Todo: set speed from code
  8. // Todo: hold formation - don't hold formation
  9. // Todo: tankoknal csoforditas
  10. // Todo: mozgas vegen ne lassitsunk
  11. // Todo: generate events at every waypoint, and others
  12.  
  13. #include "script.inc"
  14.  
  15. // GLOBALS:
  16. // Max ilyen hosszu lehet az utvonal:
  17. #define MAX_WAYPOINTS            40
  18.  
  19.  
  20. new gGroup[STR_PROP_MAX_LENGTH];            // Akiket vegigvezetjuk a palyan
  21. new Float:gSpeed;                            // Ilyen sebesseggel. -1 => max, 0 => leglassubb, >0 => probald ezzel
  22. new eMovementStyle:gMovementStyle;            // 0 => mindenki ahogy van (?), 1 => run, 2 => crawl, 3 => walk
  23. new bool:gTwoWays;                            // 1 => oda-vissza, 0 => korbe-korbe
  24. new Float:gLookAtWPDirThisTime;                // float, ennyi ideig nez a waypoint iranyaba, mielott tovabbmegy
  25.  
  26. new DrID:gComp;                                // Ebbol a komponensbol kerjuk majd le az ertekeket
  27. new DrID:gLastWaypoint;                        // Itt kell eventet dobni
  28. new DrID:gSelf;
  29.  
  30. // ARRAYS:
  31. new DrID:gWaypoints[MAX_WAYPOINTS+1];        // Ez definialja az utvonalat
  32. const Float:gWheeledExtraWait = 5.0;        // Kerekes jarmuvek es emberek ennyivel tovabb varnak, mint lanctalpasok (mivel ok nem tudnak fordulni)
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //======================================================================================================
  39. public PatrolInit()
  40. {
  41.     gSelf = GetEntity( "self" );
  42.     gComp = GetComponent( gSelf, "cCpScriptVariable" );
  43.     
  44.     if( IsDebugLevelOK( DL_BEHAVIOR )) {
  45.         new Message[100];
  46.         GetPropertyString( gSelf, "StringID", 100, Message );
  47.         ConcatString( Message, 100, "Patrol initialized: ", Message );
  48.         DebugMessage( Message, DL_MESSAGE );
  49.     }
  50.  
  51.     // Valtozok feltoltese:
  52.     new TmpString[STR_PROP_MAX_LENGTH];
  53.     GetVarString( gComp, "Group", STR_PROP_MAX_LENGTH, gGroup );
  54.     gSpeed = Float:GetVar( gComp, "Speed" );
  55.     gMovementStyle = eMovementStyle:GetVar( gComp, "MovementStyle" );
  56.     gTwoWays = bool:GetVar( gComp, "TwoWays" );
  57.     gLookAtWPDirThisTime = Float:GetVar( gComp, "LookAtWPDirThisTime" );    //?
  58.  
  59.     // Waypointok tombjenek feltoltese:
  60.     new i = GetArrayLength( gComp, "Waypoints" );
  61.     gWaypoints[i + 1] = DrID:0;                 // Terminating zero to simplify iterations
  62.     
  63.     for( ; i >=0 ; i-- ) {
  64.         GetArrayVarString( gComp, "Waypoints", i, STR_PROP_MAX_LENGTH, TmpString );
  65.         gWaypoints[i] = GetEntity( TmpString );
  66.     }
  67.     
  68.     AddAKEntityEvent( "mUnitArrived", ANY_ENTITY, UNIT_ARRIVED );
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75. //======================================================================================================
  76. public PatrolStart()
  77. {
  78.     // Exit if this is not the target entity of the message
  79.     if( !IsTarget( gSelf )) return false;
  80.  
  81.     if( IsDebugLevelOK( DL_BEHAVIOR )) {
  82.         new Message[100];
  83.         GetPropertyString( GetEntity( "self" ), "StringID", 100, Message );
  84.         ConcatString( Message, 100, "Patrol started: ", Message );
  85.         DebugMessage( Message, DL_MESSAGE );
  86.     }
  87.  
  88.     new eQueuing:Queuing;
  89.     new Float:TmpVec3[vec3];
  90.     new wp = 0;
  91.     new Float:TmpDirection = 0.0;
  92.     new DrID:TmpUnit;
  93.     
  94.     // Stop before:
  95.     CmdGroupStop( gGroup, Q_OVERRIDE );
  96.  
  97.     // Set Movement Style:
  98.     if( gMovementStyle != MS_NONE )
  99.         CmdGroupSetMS( gGroup, Q_OVERRIDE, gMovementStyle );
  100.         
  101.     // Set Speed:
  102.     if( gSpeed < 0.0 ) { // Set the speed to the slowest unit's speed
  103.         TmpUnit = GetSlowestUnitInSelector( gGroup, gMovementStyle );
  104.         if( !TmpUnit )
  105.             return false; // Exit function if there is no units in the selector
  106.         SetSpeedInSelector( gGroup, GetMaxSpeed( TmpUnit, gMovementStyle ));
  107.     }
  108.     else // Try this speed (if 0.0, then the units move at maximum speed)
  109.         SetSpeedInSelector( gGroup, gSpeed );
  110.         
  111.     // Iterate waypoints (first part):
  112.     for( wp = 0; gWaypoints[wp]; wp++ ) {
  113.         Queuing = ( wp == 0 ) ? Q_OVERRIDE : Q_CYCLE;
  114.             
  115.         GetPropertyVec3( gWaypoints[wp], "Pos", TmpVec3 );
  116.         CmdGroupMove( gGroup, Queuing, TmpVec3 );
  117.         
  118.         new str[20];
  119.         Float2Str( gLookAtWPDirThisTime, str, 20 );
  120.         DebugMessage( str, DL_BEHAVIOR )
  121.                 
  122.         if( gLookAtWPDirThisTime >= 0.0 ) { // Turn to direction and wait
  123.             TmpDirection = GetEntityDir( gWaypoints[wp], DB_X_AXIS );
  124.             CmdGroupTurnToDir( gGroup, Q_CYCLE, TmpDirection, DB_X_AXIS );
  125.             CmdGroupWait( gGroup, Q_CYCLE, gLookAtWPDirThisTime );
  126.         }
  127.     }
  128.     
  129.     // Iterate waypoints (second part):
  130.     wp--;
  131.     if( gTwoWays ) { // Ketiranyu bejaras
  132.         do {
  133.             GetPropertyVec3( gWaypoints[wp], "Pos", TmpVec3 );
  134.             CmdGroupMove( gGroup, Queuing, TmpVec3 );
  135.             
  136.             if( gLookAtWPDirThisTime >= 0.0 ) { // Turn to direction and wait
  137.                 TmpDirection = GetEntityDir( gWaypoints[wp], DB_X_AXIS );
  138.                 CmdGroupTurnToDir( gGroup, Q_CYCLE, TmpDirection, DB_X_AXIS );
  139.                 CmdGroupWait( gGroup, Q_CYCLE, gLookAtWPDirThisTime );
  140.             }
  141.         } while( wp-- );
  142.         gLastWaypoint = gWaypoints[0];
  143.     } else { // Korkoros bejaras
  144.         GetPropertyVec3( gWaypoints[0], "Pos", TmpVec3 );
  145.         CmdGroupMove( gGroup, Q_CYCLE, TmpVec3 );
  146.         gLastWaypoint = gWaypoints[wp];
  147.     }
  148.     
  149.     return true;
  150. }
  151.  
  152.  
  153.  
  154.  
  155. public mUnitArrived( DrID:Unit )
  156. {
  157.     if( GetMsgParamObject() != gLastWaypoint )
  158.         return false;
  159.         
  160.     if( !IsInSelector( Unit, gGroup ))
  161.         return false;
  162.         
  163.     CallUserEvent( UEM_PATROL_END );
  164.     return true;
  165. }
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.