home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 April / Gamestar_83_2006-04_dvd.iso / Dema / demowot_english.exe / Script / Source / convoycontrol.inc < prev    next >
Text File  |  2005-03-11  |  8KB  |  234 lines

  1. // Use only on maps with Convoy!
  2. // variables used:
  3. /*
  4. const gConvoyTotal = 1; //the number of convoys controlled
  5. new gConvoyArray[gConvoyTotal][] = {}; //the actual position of the convoy
  6. new gConvoyNames[gConvoyTotal][25] = {}; //the name basic of the convoy
  7. new gConvoyWPNames[gConvoyTotal][25] = {}; //the name basic of the convoy waypoints
  8. new gConvoyCount[gConvoyTotal] = {}; //the number of the convoy members
  9. new gConvoyWPCount[gConvoyTotal] = {}; //the number of the convoy waypoints
  10. new Float:gConvoyStartDelays[gConvoyTotal] = {}; //the delay beetween convoy members start
  11. #include "convoycontrol.inc"
  12. */
  13.  
  14. public ReachedAPoint(DrID:WhoReached)
  15. {
  16.     new WichPoint = GetMsgParamInt();
  17.     new TheReacher[25];
  18.     new lTmpStr[66];
  19.     new i;
  20.     new lTmpInt1;
  21.     new lTmpInt2;
  22.     GetPropertyString( WhoReached, "StringID", 20, TheReacher );
  23. //debugging
  24.     ConcatString( lTmpStr, 66, "Evented: ", TheReacher);
  25.     DebugMessage( lTmpStr, DL_BEHAVIOR )            
  26. //debugging
  27.     for(i=0;i<gConvoyTotal;i++)
  28.     {
  29.         ConcatString( lTmpStr, 25, "", gConvoyNames[i] );
  30.         if((StrFind(TheReacher,lTmpStr) != -1))
  31.         {
  32.             ConcatString( lTmpStr, 25, "", TheReacher );
  33.             lTmpInt1 = strlen(gConvoyNames[i]);
  34.             lTmpInt2 = strlen(lTmpStr);
  35.             lTmpInt1--;
  36.             lTmpInt2--;            
  37.             StrMid(lTmpStr,lTmpStr,lTmpInt2, lTmpInt2 -lTmpInt1);
  38.             gConvoyArray[i][(Str2Int(lTmpStr)-1)] = WichPoint;
  39. //debugging
  40.             Int2Str( WichPoint, lTmpStr, 66);
  41.             ConcatString( lTmpStr, 66, " is at ", lTmpStr);
  42.             ConcatString( lTmpStr, 66, TheReacher, lTmpStr );
  43.             DebugMessage( lTmpStr, DL_BEHAVIOR )            
  44. //debugging
  45.         }    
  46.     }
  47. }
  48.  
  49. stock ResetConvoy(RC_ConvNum, RC_Start=0, RC_End=0)
  50. {
  51.     if(RC_End==0||RC_End>gConvoyCount[RC_ConvNum])
  52.     {
  53.         RC_End=gConvoyCount[RC_ConvNum]-1;
  54.     }
  55.     if(RC_End<RC_Start)
  56.     {
  57.         return;
  58.     }    
  59.     new i;
  60.     for(i=RC_Start;i<=RC_End;i++)
  61.     {
  62.         gConvoyArray[RC_ConvNum][i]=0;
  63.     }
  64. }
  65.  
  66. stock ConvoyGo(ConvNum,eQueuing:ConvoyStyle = Q_ENQUEUE, eMoveFlag:MoveStyle = MF_OVERRUN )
  67. {
  68.     new i;
  69.      new Float:ActStartDelay = 0.0;
  70.     for(i=1;i<=gConvoyCount[ConvNum];i++)
  71.     {
  72.          ConvoyMover(gConvoyNames[ConvNum],i,gConvoyWPNames[ConvNum],gConvoyWPCount[ConvNum],ActStartDelay,i,(gConvoyArray[ConvNum][i-1]+1),ConvoyStyle, MoveStyle);         
  73.          ActStartDelay = ActStartDelay + gConvoyStartDelays[ConvNum];
  74.      }
  75. }
  76.  
  77. stock ConvoyGoMember(ConvNum,ConvMemb,eQueuing:ConvoyStyle = Q_ENQUEUE, eMoveFlag:MoveStyle = MF_OVERRUN)
  78. {
  79.     ConvoyMover(gConvoyNames[ConvNum],ConvMemb,gConvoyWPNames[ConvNum],gConvoyWPCount[ConvNum],0.0,ConvMemb,(gConvoyArray[ConvNum][ConvMemb-1]+1),ConvoyStyle, MoveStyle);         
  80. }
  81.  
  82. stock ConvoyStop(ConvNum)
  83. {
  84.     new i;
  85.     new lTmpStr[25];
  86.     for(i=1;i<=gConvoyCount[ConvNum];i++)    
  87.     {
  88.         Int2Str( i, lTmpStr, 25, "" );
  89.         ConcatString( lTmpStr, 25, gConvoyNames[ConvNum], lTmpStr );
  90.         CmdStop( GetEntity(lTmpStr), Q_OVERRIDE );
  91.         RemoveEntityEvent( "ReachedAPoint", GetEntity( lTmpStr ));
  92.         if(!GetEntity(lTmpStr))
  93.             DebugMessage( "Invalid entity asked to stop", DL_ERROR )
  94.     }    
  95. }
  96.  
  97. stock ConvoyStopMember(ConvNum,ConvMemb)
  98. {
  99.     new lTmpStr[25];
  100.     Int2Str( ConvMemb, lTmpStr, 25, "" );
  101.     ConcatString( lTmpStr, 25, gConvoyNames[ConvNum], lTmpStr );
  102.     CmdStop( GetEntity(lTmpStr), Q_OVERRIDE );
  103.     RemoveEntityEvent( "ReachedAPoint" GetEntity( lTmpStr ));
  104.     if(!GetEntity(lTmpStr))
  105.         DebugMessage( "Invalid entity asked to stop", DL_ERROR )
  106. }
  107.  
  108. //----Convoy mover script ... requested-----
  109. stock ConvoyMover(ConvoyName[],ConvoyMembs,WayPointName[],WayPointNum,Float:StartDelay=0.0, MemberNumber = 1, WaypointNumber = 1, eQueuing:QueueStyle = Q_ENQUEUE, eMoveFlag:MoveStyle = MF_OVERRUN, bool:ContinueWhatDoing=false)
  110. {
  111.     new MemberNo = 1;
  112.     new ActMember[255];
  113.     new ActWaypoint[255];
  114.     new WaypointNo = 1;
  115.     new Float:ActDelay = StartDelay;
  116.     
  117.     new lTmpStr[255];
  118.     
  119.     if(ConvoyMembs<1 || ConvoyMembs < MemberNumber)
  120.     {
  121.         DebugMessage( "akcommon.inc:ConvoyMover: Convoy Member less than 1!", DL_ERROR );
  122.         return false;
  123.     }
  124.  
  125.     if(WayPointNum<1)
  126.     {
  127.         DebugMessage( "akcommon.inc:ConvoyMover: Waypoint Number less than 1!", DL_ERROR );
  128.         return false;
  129.     }
  130.     
  131.     if(WayPointNum < WaypointNumber && QueueStyle == Q_ENQUEUE)
  132.     {
  133.         DebugMessage( "akcommon.inc:ConvoyMover: Waypoint Number less than 1 and ENQUEUE style!", DL_ERROR );
  134.         return false;
  135.     }
  136.     
  137.     if(!(QueueStyle == Q_CYCLE || QueueStyle == Q_ENQUEUE))
  138.     {
  139.         DebugMessage( "akcommon.inc:ConvoyMover: Invalid Queue Style!", DL_ERROR );
  140.         return false;
  141.     }
  142.     
  143.     for(MemberNo = MemberNumber; MemberNo <= ConvoyMembs; MemberNo++)
  144.     {
  145.         Int2Str( MemberNo, ActMember, 3, "" );        
  146.         ConcatString( ActMember, 19, ConvoyName, ActMember);
  147.         if(GetEntity( ActMember ))
  148.         {
  149.             for (WaypointNo = WaypointNumber; WaypointNo <= WayPointNum; WaypointNo++)
  150.             {
  151.                 Int2Str( WaypointNo,ActWaypoint, 3, "" );
  152.                 ConcatString( ActWaypoint, 255, WayPointName, ActWaypoint);
  153.                 if(GetEntity( ActWaypoint ))
  154.                 {
  155.                     if(WaypointNo == WaypointNumber)
  156.                     {
  157.                         if(!ContinueWhatDoing)
  158.                             CmdWait(GetEntity( ActMember ), Q_OVERRIDE, ActDelay);
  159.                         if(WaypointNumber==1)    
  160.                             CmdMoveToEnt( GetEntity (ActMember), GetEntity( ActWaypoint) , QueueStyle, MoveStyle );
  161.                         CmdThrowEvent( GetEntity (ActMember), QueueStyle, WaypointNo );
  162.                         ConcatString( lTmpStr, 166,"ConvoyMover: First waypoint (", ActWaypoint);
  163.                         ConcatString( lTmpStr, 166, lTmpStr, ") added to ");
  164.                         ConcatString( lTmpStr, 166, lTmpStr, ActMember );
  165.                         DebugMessage( lTmpStr , DL_MESSAGE );
  166.                     }
  167.                     else
  168.                     {
  169.                         if(WaypointNo < WayPointNum)
  170.                         {
  171.                             CmdMoveToEnt( GetEntity (ActMember), GetEntity( ActWaypoint) , QueueStyle, MoveStyle );
  172.                             CmdThrowEvent( GetEntity (ActMember), QueueStyle, WaypointNo );
  173.                             ConcatString( lTmpStr, 166,"ConvoyMover: Waypoint (", ActWaypoint);
  174.                             ConcatString( lTmpStr, 166, lTmpStr, ") added to ");
  175.                             ConcatString( lTmpStr, 166, lTmpStr, ActMember );
  176.                             DebugMessage( lTmpStr , DL_BEHAVIOR );
  177.                         }
  178.                         else
  179.                         {
  180.                             CmdMoveToEnt( GetEntity (ActMember), GetEntity( ActWaypoint), Q_CYCLE, MoveStyle ); // this is the last waypoint
  181.                             CmdThrowEvent( GetEntity (ActMember), QueueStyle, WaypointNo );
  182.                             ConcatString( lTmpStr, 166,"ConvoyMover: Last waypoint (", ActWaypoint);
  183.                             ConcatString( lTmpStr, 166, lTmpStr, ") added to ");
  184.                             ConcatString( lTmpStr, 166, lTmpStr, ActMember );
  185.                             DebugMessage( lTmpStr , DL_MESSAGE );
  186.                         }
  187.                     }
  188.                 }
  189.                 else
  190.                 {
  191.                         ConcatString( lTmpStr, 166,"ConvoyMover: Waypoint (", ActWaypoint);
  192.                         ConcatString( lTmpStr, 166, lTmpStr, ") doesn't exists! Requested by: ");
  193.                         ConcatString( lTmpStr, 166, lTmpStr, ActMember );
  194.                         DebugMessage( lTmpStr , DL_ERROR );
  195.                 }                    
  196.             }
  197.             if(QueueStyle == Q_CYCLE)
  198.             {
  199.                 for (WaypointNo = 1; WaypointNo <= WaypointNumber; WaypointNo++)
  200.                 {
  201.                     Int2Str( WaypointNo,ActWaypoint, 3, "" );
  202.                     ConcatString( ActWaypoint, 255, WayPointName, ActWaypoint);
  203.                     if(GetEntity( ActWaypoint ))
  204.                     {
  205.                         CmdMoveToEnt( GetEntity (ActMember), GetEntity( ActWaypoint) , QueueStyle, MoveStyle );
  206.                         CmdThrowEvent( GetEntity (ActMember), QueueStyle, WaypointNo );
  207.                         ConcatString( lTmpStr, 166,"ConvoyMover.patrol: Waypoint (", ActWaypoint);
  208.                         ConcatString( lTmpStr, 166, lTmpStr, ") added to ");
  209.                         ConcatString( lTmpStr, 166, lTmpStr, ActMember );
  210.                          DebugMessage( lTmpStr , DL_BEHAVIOR );
  211.                     }
  212.                     else
  213.                     {
  214.                         ConcatString( lTmpStr, 166,"ConvoyMover: Waypoint (", ActWaypoint);
  215.                         ConcatString( lTmpStr, 166, lTmpStr, ") doesn't exists! Requested by: ");
  216.                         ConcatString( lTmpStr, 166, lTmpStr, ActMember );
  217.                         DebugMessage( lTmpStr , DL_ERROR );
  218.                     }                    
  219.                 }
  220.             }
  221.             AddAKEntityEvent( "ReachedAPoint", GetEntity(ActMember), CMD_EVENT );
  222.         }
  223.         else
  224.         {
  225.                         ConcatString( lTmpStr, 166,"ConvoyMover: Entity (", ActMember);
  226.                         ConcatString( lTmpStr, 166, lTmpStr, ") doesn't exists!");
  227.                         DebugMessage( lTmpStr , DL_ERROR );
  228.         }
  229.            ActDelay = ActDelay + StartDelay;
  230.     }
  231.     return true;
  232. }
  233.  
  234.