Announcement

Collapse
No announcement yet.

Moving units and attacking with slic

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving units and attacking with slic

    I have an army I can't make attack a city when I want it to.

    On BeginTurnExecute I tell this army (with Event:MovePathOrder) to move to a city, this part works fine. Then in a pre MovePathOrder event handler I tell the army to move into (attack) the city, using Event:MoveToOrder, I've also tried Event:MoveArmy.

    But when the events are given, my army is given the order to siege another city, and so it moves away from it's target toward the other city. And as you can imagine, on the next BeginTurnExecute the army follows my orders again and goes back to the target city.

    I tried returning stop in a pre handler of MovePathOrder when my army is given a wrong location to move to, but this seems to do nothing. Obviously my army is being given *some* move event order before my own triggered "attack" events are being carried out.

    So how do I get it to ALWAYS attack the city, if it's next to it?
    Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
    CtP2 AE Wiki & Modding Reference
    One way to compile the CtP2 Source Code.

  • #2
    IIRC, this was one of the most difficult things to get to work. Here's the crucial bit of code:

    Code:
    if (SquaredDistance(tmpArmy.location,tarLoc.location)>2){
    				    event:MovePathOrder(tmpArmy,tarLoc.location); 
    			    }
    			    else{
    				    for (i=0;i<8;i=i+1){
    					   GetNeighbor(tmpArmy.location,i,attLoc);
    					   if (attLoc==tarLoc){
    						    event:MoveToOrder(tmpArmy,i);
    						    i=8;
    					   }
    				    }
    			    }
    This was part of a function that was called on ArmyBeginTurn so you have to filter out the other armies to make sure that tmpArmy above is the one you want to attack tarLoc. The whole thing is in CTC's New_Tactics.slc

    Comment


    • #3
      The problem is that the move events are given afterwards the AI has moved its armies. So no movepoints are left and on each turn the AI clears the orders of its armies, so the order isn't executed on the next turn. I have also some instances of that in my BetterAI.slc.

      -Martin
      Civ2 military advisor: "No complaints, Sir!"

      Comment


      • #4
        After a few years of research I came up with the following solution to force army movement via SLIC:

        Step 1: Introduce a global variable to hold the army I want to move:

        Code:
        army_t		MOD_MyMoveArmy;			// The army I want to move, dammit
        Step 2: Add the following set of event handlers and functions:

        Code:
        void_f ClearArmyOrders(army_t theArmy) {
        	army_t		tmpArmy;
        	int_t		tmpArmySize;
        	int_t		tmpCycle;
        	unit_t		tmpUnit;
        
        	tmpArmy = theArmy;
        	tmpArmySize = tmpArmy.size;
        
        	for(tmpCycle = 0; tmpCycle < tmpArmySize; tmpCycle = tmpCycle + 1) {
        		if(GetUnitFromArmy(tmpArmy, tmpCycle, tmpUnit)) {
        			ClearOrders(tmpUnit);
        		}
        	}
        }
        
        // Move army to target dammit
        
        HandleEvent(MoveOrder) 'DontOverrideMyMoveOrders' pre {			// triggers every time the exe gives a pathed move order
        	army_t tmpArmy;
        	
        	tmpArmy = army[0];
        
        	if(tmpArmy == MOD_MyMoveArmy) {
        		return STOP;
        	}
        	return CONTINUE;
        }
        
        HandleEvent(SettleOrder) 'DontOverrideMyMoveOrdersSettling' pre {	// triggers every time the exe gives a settle order
        	army_t tmpArmy;
        	
        	tmpArmy = army[0];
        
        	if(tmpArmy == MOD_MyMoveArmy) {
        		return STOP;
        	}
        	return CONTINUE;
        }
        
        HandleEvent(MovePathOrder) 'EnableMyOwnMoveOrders' post {		// triggers when a pathed move order is given via SLIC
        	army_t tmpArmy;
        
        	tmpArmy = army[0];
        
        	if(tmpArmy == MOD_MyMoveArmy) {
        		DisableTrigger('DontOverrideMyMoveOrders');	// in case the exe adds a MoveOrder to MY MovePathOrder
        	}
        }
        
        HandleEvent(MoveUnits) 'ResetDontOverrideMyMoveOrders' post {		// after the desired move has been executed
        	army_t tmpArmy;
        
        	tmpArmy = army[0];
        
        	if(tmpArmy == MOD_MyMoveArmy) {
        		EnableTrigger('DontOverrideMyMoveOrders');
        	}
        }
        
        void_f MoveArmyToTarget(army_t theArmy, location_t theLoc) {
        	army_t tmpArmy;
        	location_t tmpArmyLoc;
        	location_t tmpLoc;
        
        	tmpArmy = theArmy;
        	tmpLoc = theLoc;
        	tmpArmyLoc = tmpArmy.location;
        
        	if(ArmyIsValid(tmpArmy)) {
        		ClearArmyOrders(tmpArmy);
        		MOD_MyMoveArmy = tmpArmy;
        		Event:MovePathOrder(tmpArmy, tmpLoc);
        		Event:BeginTurnExecute(tmpArmy);
        	}
        }
        The obvious purpose of this framework is to prevent MOD_MyMoveArmy from doing anything other than MY ordered moves.

        Step 3: Whenever you want to move an army, use

        Code:
        MoveArmyToTarget(theArmyYouWantToMove, theTargetLocation);
        This works surprisingly well if I use it in "early" event handlers like BeginTurn or AiBeginTurn. If I use it in "late", army-related event handlers like BeginTurnArmy it seems to slow down the game and increase the crash chance dramatically.
        The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

        Comment


        • #5
          This has really killed my enthusiasm for scenario making at times. Something as simple as controlling armies or single units (even to make them stop moving/disbanding/ungrouping etc) should be a lot easier.
          Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
          CtP2 AE Wiki & Modding Reference
          One way to compile the CtP2 Source Code.

          Comment


          • #6
            It's the same with me: I am researching this since I started modding at all, because in my settling script each lost settler move causes a massive drawback for the affected AI and in the end they would do better without SLIC interference.

            Well, the above solution is, I think, the final solution -- as a model: In a particular mod/scenario it might be better to introduce individual global variables and probably an individual set of "stop-unwanted-moves-handlers" for each army one wishes to move in order to avoid confusion. But basically it works fine and moves "god's own armies" exactly as intended (by god) without delay.

            And the good news (also the bad news for me) is: It doesn't seem to exactly cause the crashes I observed (moving the functions to different event handlers or removing the whole thing entirely seems to have some influence on performance and the exact nature of the crashes, though).
            The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

            Comment


            • #7
              Thanks for posting your code by the way Bert.

              I did get this working a while ago, using a similar method to yours. Although I felt it was unwieldy and seemed to slow the game down. Probably because I was trying to control 14 or more full armies.
              Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
              CtP2 AE Wiki & Modding Reference
              One way to compile the CtP2 Source Code.

              Comment

              Working...
              X