Announcement

Collapse
No announcement yet.

SLIC questions

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

  • SLIC questions

    I need a little help with some SLIC I'm using.

    The following gives no errors with debugslic=yes, everything works fine everytime except the army doesn't group at the end. Is there something wrong with the code, or is the problem with the group commands? I've seen some kind of workaround for it in the Magnificant Samurai scenario where the AI is detached first? But it has some errors with the source code, so I wanted to try it the easy way first.

    Please point out any other errors or inefficient code so I can improve it.

    Code:
    HandleEvent(CaptureCity) 'kishinevTrig' pre { //if kishinev captured by germans, spawn germans around kirovgrad and russian partisans around kishinev
    unit_t tmpUnit;
    unit_t tmpUnit1;
    army_t tmpArmy;
    location_t randomkishinevLoc;
    location_t randomkirovgradLoc;
    
        if (PlayerCivilization(player[0]) == CivilizationIndex("German") 
            && PlayerCivilization(city[0].owner) == CivilizationIndex("Russian")
    	  && city[0].location==kishinevLoc ){
    		GetRandomNeighbor(kishinevLoc, randomkishinevLoc);
    			CreateUnit(1, UnitDB(UNIT_PARTISANS_RF), randomkishinevLoc, 0, tmpUnit);
    				if (tmpUnit.valid) {
    					Event:EntrenchUnit(tmpUnit);
    				}
    				if (tmpUnit.valid) {
    					message(city[0].owner,'kishinevpartisansMsg');
    				}
    		GetRandomNeighbor(kirovgradLoc, randomkirovgradLoc);
    		CreateUnit(5, UnitDB(UNIT_WEHRMACHT_RF), randomkirovgradLoc, 0, tmpUnit1);
    		CreateUnit(5, UnitDB(UNIT_WEHRMACHT_RF), randomkirovgradLoc, 0);
    		CreateUnit(5, UnitDB(UNIT_WEHRMACHT_RF), randomkirovgradLoc, 0);
    		CreateUnit(5, UnitDB(UNIT_15CMFELD_RF), randomkirovgradLoc, 0);
    		CreateUnit(5, UnitDB(UNIT_15CMFELD_RF), randomkirovgradLoc, 0);
    		CreateUnit(5, UnitDB(UNIT_15CMFELD_RF), randomkirovgradLoc, 0);
    		CreateUnit(5, UnitDB(UNIT_ROMINF_RF), randomkirovgradLoc, 0);
    			if (tmpUnit1.valid) {
    			GetArmyFromUnit(tmpUnit1, tmpArmy);
    			Event:GroupOrder(tmpArmy);
    		DisableTrigger('kishinevTrig');
    		}
    	}
    }
    Also is there a way to force the AI to attack a location/city with SLIC (rather than goals/strategies)? I have FrenzyAI working but I also need to force the AI to attack sometimes.
    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
    The problem with the events is that they are executed asynchrony. If you have something like this:

    Code:
    				Event:UngroupOrder(MGArmy);
    				for(j = MGUnitsAtLoc-1; j >= 0; j = j - 1) {
    					GetUnitFromCell(MGArmy.location, j, MGUnit);
    					GetArmyFromUnit(MGUnit, MGArmy2);
    					ClearOrders(MGUnit);
    				//	Event:MoveIntoTransport(MGArmy2, MGLoc);
    					Event:MoveArmy(MGArmy2,MGRandomPerm[k],1,0,MGLoc);
    				//	Event:MoveToOrder(MGArmy2, k);
    				}//No need to group the remaining units agian as they will grouped in the next turn when the ship is gone.
    Then this doesn't work, because the UngroupOrder event is executed after the for loop and GetUnitFromCell returns always the same army if there where just one army.

    And the order stuff as I figured it out, is just an order. So first you have a delay between event call and event execution and then you have a delay between order and order execution. From my reasoning it could happen that the AI would execute the orders on the next turn. In between the AI can of course clear the orders.

    To prevent this I used the BeginTurnExecute event.

    Maquiladora
    Also is there a way to force the AI to attack a location/city with SLIC (rather than goals/strategies)? I have FrenzyAI working but I also need to force the AI to attack sometimes.
    For that you should look into my AI code, the code indeed makes the AI to attack. Note that this code is unfinished and therefore some stuff doesn't work like the AI cross-sea-invasion stuff. And most of the stuff can be better solved with source code in-built slic function like the continent stuff.

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

    Comment


    • #3
      Thanks Martin. I still need to explore more (particularly how it affects city defence) but it certainly seems to perform much better than Frenzy, the AI is far more decisive at least.

      BTW, I had to change this to make it run without errors because it said it was the wrong arguement for AtWarWith:

      Code:
      HandleEvent(MoveUnits)'MG_ConquerFort'post{
      	if(TileHasImprovement(army[0].location, TerrainImprovementDB(TILEIMP_FORTIFICATIONS))
      	&& CellOwner(army[0].location) > -1
      	&& AtWarWith(army[0].owner, CellOwner(army[0].location))) {
      		MG_ChangeFortOwner(army[0].location,army[0].owner);
      	}
      }
      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


      • #4
        Another question, but I'm not sure if I should report it as a bug or something I'm doing wrong. Alert boxes don't seem to pause the game as they should (at least in the documentation I've read), is this a bug and is there a workaround or would it be easy to fix at source?
        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


        • #5
          Originally posted by Maquiladora
          Thanks Martin. I still need to explore more (particularly how it affects city defence) but it certainly seems to perform much better than Frenzy, the AI is far more decisive at least.
          If I remember correctly it just takes all units outside a city and sends them to the front. Actually it works on the surplus units the mod AI production cheats give. In fact it is able to make AIs to wipe out each other.

          Originally posted by Maquiladora
          BTW, I had to change this to make it run without errors because it said it was the wrong arguement for AtWarWith:
          That's odd, the order of the arguments shouldn't matter.

          Originally posted by Maquiladora
          Another question, but I'm not sure if I should report it as a bug or something I'm doing wrong. Alert boxes don't seem to pause the game as they should (at least in the documentation I've read), is this a bug and is there a workaround or would it be easy to fix at source?
          AlertBoxes are supposed to be modal, so you cannot do anything, until you clicked them away. But the game should continue to run, for instance if it is the turn of the AI.

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

          Comment


          • #6
            Originally posted by Martin Gühmann

            AlertBoxes are supposed to be modal, so you cannot do anything, until you clicked them away. But the game should continue to run, for instance if it is the turn of the AI.
            I wanted to stop the game and send an alertbox on an AI turn like Civ2, because it would be easier for the player to understand what just happened, and go through the alerts as each event happened. I guess this isn't possible so I'll work with the way CtP2 does 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.

            Comment


            • #7
              Is there an example of how to use the UseDirector() function? I couldn't find use of it anywhere.
              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


              • #8
                Originally posted by Maquiladora
                Is there an example of how to use the UseDirector() function? I couldn't find use of it anywhere.
                Peter uses it in his NewDiplomod.slc and it is also used in script.slc.

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

                Comment


                • #9
                  Thanks Martin.

                  I managed to figure out what this thing does, or at least what I needed it to do for me.

                  On some turns there were 6 or 7 important messages that I needed to auto-popup (or "show();"), but for some reason the queue for each one to popup up after another got confused and only 3 or 4 would popup after another was closed, and some stay unread in the msg log (that is, until you clicked them). Anyway I added UseDirector to them and now they all popup after another is closed.
                  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


                  • #10
                    I'm stuck on another piece of code that I thought would be easy to get working, but apparently I'm missing something...

                    Code:
                      //-------------------------------------------------------
                     // Kill Romanian Infantry after Soviets capture Bucharest
                    //---------------------------------------------------------
                    
                    HandleEvent(CaptureCity) 'RomanianSurrender' pre {
                    int_t numGerUnits;
                    int_t a;
                    unit_t gerUnit;
                    
                    	if (PlayerCivilization(player[0]) == CivilizationIndex("Russian") 
                    	    && PlayerCivilization(city[0].owner) == CivilizationIndex("German")
                    	      && city[0].location==bucharestLoc ){
                    
                    	player[0] = 5;
                    
                    		if (IsPlayerAlive(player[0])) {
                    
                    		numGerUnits = player[0].units;
                    
                    			for(a = 0; a < numGerUnits; a = a + 1) { // cycle through German units
                    				GetUnitByIndex(5, a, gerUnit);
                    				if (gerUnit.type == UnitDB(UNIT_ROMINF_RF)) { // if Romanian Infantry
                    					KillUnit(gerUnit); // kill it
                    				}
                    			}
                    		}
                    		message(1,'RomanianSurrenderMsg');
                    		DisableTrigger('RomanianSurrender');
                    	}
                    }
                    I get a "value out of bounds" error for the GetUnitByIndex function and I can't find a way to fix it. Basically what am I doing wrong?
                    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


                    • #11
                      Originally posted by Maquiladora
                      I get a "value out of bounds" error for the GetUnitByIndex function and I can't find a way to fix it. Basically what am I doing wrong?
                      The KillUnit function kills the unit directly without calling the KillUnit event, so the unit is dead in the next iteration and out of the player unit list. Therefore the list is shorter than it was before the loop has started.

                      Now you have two possibilities, either your cycle through the loop backwards or your use the KillUnit event insead of the KillUnit function.

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

                      Comment


                      • #12
                        Thanks (again) Martin. I'm using the KillUnit event instead.
                        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


                        • #13
                          I have another question, not related to SLIC but what the hell... how do I tell the AI to never give in to a threat?

                          I know how to prevent them accepting a proposal, but when I threaten afterwards then they ALWAYS agree to the proposal anyway, probably because of my much bigger military.
                          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


                          • #14
                            Originally posted by Maquiladora
                            I have another question, not related to SLIC but what the hell... how do I tell the AI to never give in to a threat?
                            Good question, the first place I would look would be diplomacy.txt but it looks like the Threaten flag there isn't used.

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

                            Comment

                            Working...
                            X