Announcement

Collapse
No announcement yet.

Getting Civs to Surrender

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

  • Getting Civs to Surrender

    OK, using Tony Evans's SwapCity function, I've got this little handler that makes AI civs surrender rather than fighting to the last city:

    Code:
    // Swaps City to Player. Kills all units first if flag is set to 1.
    int_f SwapCity (city_t swCity, int_t swPlayer, int_t killUnits) 
    {
    int_t		i;
    int_t		tmpPlayer;
    int_t		numUnits;
    unit_t		tmpUnit;
    city_t		tmpCity;
    location_t	tmpLoc;
    
    	tmpCity = swCity;
    
        if (CityIsValid(tmpCity)) {
    	    tmpPlayer = swPlayer;
    	    tmpLoc = tmpCity.location;
    	    numUnits = GetUnitsAtLocation(tmpLoc);
    	    if (killUnits == 1) {
    		    for (i = 0; i < numUnits; i = i + 1) {	// Kill all units
    			    GetUnitFromCell(tmpLoc, i, tmpUnit);
    			    Event: DisbandUnit(tmpUnit);
    		    }
    	    }
    	    Event:GiveCity(tmpCity, tmpPlayer);
        } 
        else {
    		return -1;// Can't swap due to invalid city
        }
    }
    
    HandleEvent(CaptureCity) 'CivSurrenders' pre {
    
    city_t	tmpCity;
    int_t	i;
    int_t     numCities;
    int_t     numUnits;
    unit_t    tmpUnit;	
    	
    	if ( IsHumanPlayer(player[0]) ){//what about AI?
    	    player[1]=city[0].owner;
    	    numUnits=player[1].units;
    	    TMP_PLAYER=player[1];
    	    TMP_CITY=city[0];
    	    	    
    	    if( MilitaryRank(player[0])-MilitaryRank(player[1])>25) {
                  
    	         for (i=0;i< numUnits;i=i+1 ){//first, kill his civilians
    		         GetUnitByIndex(TMP_PLAYER,i,tmpUnit);
    			    if (tmpUnit.valid && IsCivilian(tmpUnit) ) {
                            Event: DisbandUnit(tmpUnit); 
    			    }
    		    }
    
                  numCities=PlayerCityCount(TMP_PLAYER);
    		    for (i = 0; i < numCities; i = i + 1) {//then take his cities
    		         GetCityByIndex(TMP_PLAYER, i, tmpCity);
    		         if (tmpCity.location != city[0].location  ){
                          
    			         CreateUnit(player[0], UnitDB(UNIT_BOMBER), city[0].location, 1, tmpUnit);
    			         SwapCity(tmpCity, player[0].owner, 1);
    				    Event: DisbandUnit(tmpUnit); 
                          
    		         }
    	         }
    		    
    	    }
    	    EnableTrigger('SurrenderMessages');         
        }
    }
    HandleEvent(CaptureCity) 'SurrenderMessages' post {
    
        player[1]=TMP_PLAYER;
        city[0]=TMP_CITY;
        if( MilitaryRank(player[0])-MilitaryRank(player[1])>25 ){
             Message(player[0].owner, 'SurrenderMessage');
             
        }
        elseif( MilitaryRank(player[0])-MilitaryRank(player[1])>20 ){
    	    Message(player[0].owner, 'OverwhelmingSuperiority');
        }
        elseif( MilitaryRank(player[0])-MilitaryRank(player[1])>15 ){
             Message(player[0].owner, 'MajorSuperiority');
        }
        elseif (MilitaryRank(player[0])>MilitaryRank(player[1]) ){
             Message(player[0].owner, 'MilitarySuperiority');
        }
        DisableTrigger('SurrenderMessages');
    }
    
    messagebox 'SurrenderMessage' {
    show();
    Text (ID_TheSurrenderMessage) ;
    }
    
    //TheSurrenderMessage "Sire! We've won! With the capture of {city[0].name}, {player[1].civ_name_singular} resistence has //totally collapsed and they have agreed to an unconditional surrender!"
    
    messagebox 'OverwhelmingSuperiority' {
    Text (ID_OverwhelmingSuperiorityM) ;
    show();
    }
    //OverwhelmingSuperiorityM "With the capture of {city[0].name}, our generals are pleased to report that we have 
    //obtained overwhelming military superiority over the {player[1].civ_name_plural}. Victory is at hand!" 
    
    messagebox 'MajorSuperiority' {
    show();
    Text (ID_MajorSuperiorityM) ;
    }
    //MajorSuperiorityM "Sire, our generals report that the war is going very well.
    // \n They believe that we are now significantly stronger than the {player[1].civ_name_plural}." 
    messagebox 'MilitarySuperiority' {
    show();
    Text (ID_MilitarySuperiorityM) ;
    }
    //MilitarySuperiorityM "Sire, our generals report that the war with the {player[1].civ_name_plural} is going well. 
    //We have gained the upper hand."
    For one thing, I had to use Martin's technique of creating a Bomber unit to expose the city and then disbanding the unit after the city has been swapped to the human player. (Otherwise, I could only swap cities that the capturing player already knows about.) But it doesn't work as well here as it does in GoodMod. There's no real problem except that there can be 10 or 20 sec lag while the computer executes.

    The other thing is the triggering condition "MilitaryRank(player[0])-MilitaryRank(player[1])>25". The MilitaryRank function is, IMO, a bit weird. I think it must take Advances into account as well as existing military units, so that although your armies can have overwhelming military superiority on the ground, your enemy's MilitaryRank may not be that much lower than yours.

    So if anybody wants to play with this and try to optimize it, you're welcome to it. Cause I have to get back to Diplomacy.

  • #2
    I personally like the Alpha Centauri version where civs will surrender to you and swear loyalty. More realistic, plus it lets you work under the max city cap.

    Comment


    • #3
      Thats good stuff. No more endless wars finished by pity of the human player. But by a fancy request.
      I am going to test it as soon as possible. The AI is stronger and stronger every day.
      Cant wait others Peter Triggs improvements in diplomacy!
      "Kill a man and you are a murder.
      Kill thousands and you are a conquer.
      Kill all and you are a God!"
      -Jean Rostand

      Comment


      • #4
        Oh OH!

        Small fix needed!

        The symbols TMP_PLAYER and TMP_CITY are undefined.

        Could you fix it?
        "Kill a man and you are a murder.
        Kill thousands and you are a conquer.
        Kill all and you are a God!"
        -Jean Rostand

        Comment


        • #5
          Interesting looking code, Peter, very interesting indeed. It would be a nice addition to the game once the bugs are worked out. BTW, what does MilitaryRank return? A value between 1 and 100 or something?

          Pedrunn,

          Edit: silly me, the variables should be global. Add this:

          city_t TMP_CITY;
          int_t TMP_PLAYER;

          to the top of your file.
          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

          Comment


          • #6
            hi the big mc here I think I know what the problem is but with no way of testing it I may miss it but here goes

            code:--------------------------------------------------------------------------------
            // Swaps City to Player. Kills all units first if flag is set to 1.
            int_f SwapCity (city_t swCity, int_t swPlayer, int_t killUnits)
            {
            int_t i;
            int_t tmpPlayer;
            int_t numUnits;
            unit_t tmpUnit;
            city_t tmpCity;
            location_t tmpLoc;

            tmpCity = swCity;

            if (CityIsValid(tmpCity)) {
            tmpPlayer = swPlayer;
            tmpLoc = tmpCity.location;
            numUnits = GetUnitsAtLocation(tmpLoc);
            if (killUnits == 1) {
            for (i = 0; i < numUnits; i = i + 1) { // Kill all units
            GetUnitFromCell(tmpLoc, i, tmpUnit);
            Event: DisbandUnit(tmpUnit);
            }
            }
            Event:GiveCity(tmpCity, tmpPlayer);
            }
            else {
            return -1;// Can't swap due to invalid city
            }
            }

            HandleEvent(CaptureCity) 'CivSurrenders' pre {

            city_t tmpCity;
            int_t i;
            int_t numCities;
            int_t numUnits;
            unit_t tmpUnit;

            if ( IsHumanPlayer(player[0]) ){//what about AI?
            player[1]=city[0].owner;
            numUnits=player[1].units;
            TMP_PLAYER=player[1];
            TMP_CITY=city[0];

            if( MilitaryRank(player[0])-MilitaryRank(player[1])>25) {

            for (i=0;i< numUnits;i=i+1 ){//first, kill his civilians
            GetUnitByIndex(TMP_PLAYER,i,tmpUnit);
            if (tmpUnit.valid && IsCivilian(tmpUnit) ) {
            Event: DisbandUnit(tmpUnit);
            }
            }

            numCities=PlayerCityCount(TMP_PLAYER);
            for (i = 0; i < numCities; i = i + 1) {//then take his cities
            GetCityByIndex(TMP_PLAYER, i, tmpCity);
            if (tmpCity.location != city[0].location ){

            CreateUnit(player[0], UnitDB(UNIT_BOMBER), city[0].location, 1, tmpUnit);
            SwapCity(tmpCity, player[0].owner, 1);
            Event: DisbandUnit(tmpUnit);

            }
            }

            }
            EnableTrigger('SurrenderMessages');
            }
            }
            HandleEvent(CaptureCity) 'SurrenderMessages' post {
            city_t tmp_City;
            int_t TMP_PLAYER;

            player[1]=TMP_PLAYER;
            city[0]=TMP_CITY;
            if( MilitaryRank(player[0])-MilitaryRank(player[1])>25 ){
            Message(player[0].owner, 'SurrenderMessage');

            }
            elseif( MilitaryRank(player[0])-MilitaryRank(player[1])>20 ){
            Message(player[0].owner, 'OverwhelmingSuperiority');
            }
            elseif( MilitaryRank(player[0])-MilitaryRank(player[1])>15 ){
            Message(player[0].owner, 'MajorSuperiority');
            }
            elseif (MilitaryRank(player[0])>MilitaryRank(player[1]) ){
            Message(player[0].owner, 'MilitarySuperiority');
            }
            DisableTrigger('SurrenderMessages');
            }

            messagebox 'SurrenderMessage' {
            show();
            Text (ID_TheSurrenderMessage) ;
            }

            //TheSurrenderMessage "Sire! We've won! With the capture of {city[0].name}, {player[1].civ_name_singular} resistence has //totally collapsed and they have agreed to an unconditional surrender!"

            messagebox 'OverwhelmingSuperiority' {
            Text (ID_OverwhelmingSuperiorityM) ;
            show();
            }
            //OverwhelmingSuperiorityM "With the capture of {city[0].name}, our generals are pleased to report that we have
            //obtained overwhelming military superiority over the {player[1].civ_name_plural}. Victory is at hand!"

            messagebox 'MajorSuperiority' {
            show();
            Text (ID_MajorSuperiorityM) ;
            }
            //MajorSuperiorityM "Sire, our generals report that the war is going very well.
            // \n They believe that we are now significantly stronger than the {player[1].civ_name_plural}."
            messagebox 'MilitarySuperiority' {
            show();
            Text (ID_MilitarySuperiorityM) ;
            }
            //MilitarySuperiorityM "Sire, our generals report that the war with the {player[1].civ_name_plural} is going well.
            //We have gained the upper hand."
            --------------------------------------------------------------------------------




            any way I look at the code and found something useful the life of a slic learner
            "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
            The BIG MC making ctp2 a much unsafer place.
            Visit the big mc’s website

            Comment


            • #7
              The Big Mc,
              What the hell? Could you perhaps indicate what you changed so I don't have to spit through the entire code? Also, if you put your code between code tags ("[ code ]" and "[ /code ]" but then without the spaces), it will look a whole lot better...
              Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

              Comment


              • #8
                looks like me and locutos responded at the same time ops
                "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
                The BIG MC making ctp2 a much unsafer place.
                Visit the big mc’s website

                Comment


                • #9
                  Two times in a row too
                  Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                  Comment


                  • #10
                    I put the city stuff in just after the last handle event
                    any way it's my first attempt at putting the coding brackets on
                    "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
                    The BIG MC making ctp2 a much unsafer place.
                    Visit the big mc’s website

                    Comment


                    • #11
                      Okay, I see it. That's what I had too at first (and I had it in the first handler too), then I actually looked at what the code was supposed to do and realized it probably needed to be global.
                      Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                      Comment


                      • #12
                        poor Pedrunn. I think he expected about 1 or two post but not about fifty telling him what to do
                        "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
                        The BIG MC making ctp2 a much unsafer place.
                        Visit the big mc’s website

                        Comment


                        • #13
                          And it's not over yet either, I'm sure Peter has some words to say about this too when he reads this
                          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                          Comment


                          • #14
                            yes he will probably laugh
                            "Every time I learn something new it pushes some old stuff out of my brain" Homer Jay Simpson
                            The BIG MC making ctp2 a much unsafer place.
                            Visit the big mc’s website

                            Comment


                            • #15


                              10 posts in 28 minutes!!!!!!!!!!

                              Am i really in a CTP2 forum????!!!!????

                              I havent seem so much posts since the terrorist attacks threads in setember 11!

                              And all because of me . I feel so important now!

                              Thank you guys. it is fixed
                              "Kill a man and you are a murder.
                              Kill thousands and you are a conquer.
                              Kill all and you are a God!"
                              -Jean Rostand

                              Comment

                              Working...
                              X