No announcement yet.

Making the AI Terraform

  • Filter
  • Time
  • Show
Clear All
new posts

  • Making the AI Terraform

    I have heard people say that the AI doesn't terraform it's terrain. Having played for a while I am starting to agree. I opened the tile improvement file and saw that there are improvements that start with TILEIMP_TERRAFORM and have a terrain type there. So I decided to put this in the improvementlist.txt file. So I put the terraform grassland and terraform plains improvement on the growth list and mountains, forest, and hills in the production list.

    Well I put it in and I didn't get an error, but the thing is that I have been playing for about 50 or so turns and The AI hasn't terraformed. What am I doing wrong? I know the AI can terraform, becuase it cleans up pollution. so why is it not terraforming the terrain even though I put it in the list. Has anyone been succesful in getting the AI to terraform? If so how? Is ther a way to make the AI terraform through slic or some other way I'm overlooking.

  • #2
    Hmmm, well, 50 isn't exactly very long, maybe you should play a little longer. Also, making the priority of terraforming very high could help (presuming you can somehow set a priority for this). Of course it can be done through SLIC but that would be like the Frenzy SLIC code: it will get the AI to terraform but it won't do it in a very intelligent way.
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery


    • #3
      In Mars 2020 (new version soon), I have had to do that, but its a long code, and for not very good results. You would have to make the AI consider more than just the top 50 (I think) tile improvements it is defaulted to. The actual terraforming doesn't improve it enough to make the AI consider it worthwhile, but in the long-term (which the AI can't plan for) it is benefitial.
      Concrete, Abstract, or Squoingy?
      "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis


      • #4
        hi, IW so what you're basically saying is that I need a code and to make the AI consider more than 50 tile improvements. Did you put the improvement tile improvement in the improvementlists.txt file or did you just use the code. I will go to your website and get the mars2020 mod and look for the code. I want this because in my current game I have AIs surrounded by jungles and forest so they dont grow much.


        • #5

          If it's just forests and jungles you're worried about, that's no problem. I've got a couple of handlers that'll cut down the trees. It's getting late here now, but I'll pull them out of my scenario.slc and post them tomorrow.


          • #6
            To increase the amount of proposals the AI will think about, so into strategies.txt and for each strategy (warlike, economic, etc) there is a number (commented for clarity) that tells you how many imporvements the AI will consider using. This will work in conjunction with the terraforming in the improvementslist.txt to let the AI choose.
            I found that the AI didn't terraform no matter what I did, so I made some code that automatically terraforms terrain into a special AI terrain on settlement, and then at certain random times, terraforms bits of grassland and forest in places.
            Concrete, Abstract, or Squoingy?
            "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis


            • #7
              The promised code is attached. It's been so long since I actually played the game (as opposed to trying to reprogramme it) that I almost forgot I had them. I hope that I've put everything in that you need and that it's working properly.

              But I think a few words of explanation might be called for. There's two handlers: NewCityTileImprovement, which triggers whenever a city is created, and ExpandingCityTileImprovement, which triggers whenever a city's population reaches six, the default min population for citysize1.

              NewCityTileImprovement basically just terraforms any forest or jungle tiles (that don't have trade goods on them) in a new city's radius into plains. It actually does a bit more because I had to overcome an AI design fault. Any human player who is about to build a city and discovers there's a Goody Hut next door will automatically look in the Goody Hut. The AI doesn't do this: because the GOAL_SETTLE priorities have to be so much higher than all the other goals, settlers will ignore Goody Huts. So the situation can arise where the AI builds a city adjacent to a Goody Hut and then later discovers that the Goody Hut is one of those city generating ones. But you can't build a city inside another city's radius, so this situation has to be excluded, otherwise the handler causes the game to crash. While doing this I thought I'd exclude another irksome AI feature where the city generating Goody Hut is not actually in another city's radius but close to it so that the AI ends up with two cities that are *very* close together. The bit of code

              if (Distance(location[0], THE_NEAREST_CITY.location)<7 
              			          && !IsHumanPlayer(player[0])) {//but it's in a lousy location, so
                                                event: DisbandCity(tmpCity);    
              will disband any AI city that comes from a Goody Hut and is within a radius of 7 of an existing city. You might want to adjust the "7"; I play on big maps and like my AI cities far apart.

              There's also a couple of lines further down:

              if (TerrainType(theLoc)==18) { //brown (desert) hills
              		        Terraform(theLoc, 9);//change to hills 
              Sometimes the AI builds cities next to those 'Sand Dune'-like hills. I think this is a waste of time so this just changes them to ordinary hills. Actually, I guess you could add code like this, here and in the corresponding slots in the ExpandingCityTileImprovement handler, to terraform anything you want. Here's the numbers you need:

              CTP2 Terrain Indices:

              0 TERRAIN_FOREST
              1 TERRAIN_PLAINS
              2 TERRAIN_TUNDRA
              3 TERRAIN_GLACIER
              4 TERRAIN_GRASSLAND
              5 TERRAIN_DESERT
              6 TERRAIN_SWAMP
              7 TERRAIN_JUNGLE
              8 TERRAIN_MOUNTAIN
              9 TERRAIN_HILL
              10 TERRAIN_WATER_SHALLOW
              11 TERRAIN_WATER_DEEP
              12 TERRAIN_WATER_VOLCANO
              13 TERRAIN_WATER_BEACH
              14 TERRAIN_WATER_SHELF
              15 TERRAIN_WATER_TRENCH
              16 TERRAIN_WATER_RIFT
              17 TERRAIN_DEAD
              18 TERRAIN_BROWN_HILL
              20 TERRAIN_WHITE_HILL
              22 TERRAIN_WATER_KELP
              23 TERRAIN_WATER_REEF
              24 TERRAIN_SPECIAL1
              25 TERRAIN_SPECIAL1

              ExpandingCityTileImprovement is a bit different. The SLIC terraform function works instantaneously and doesn't have any prerequisites. The event CreateImprovement, on the other hand, requires both that the cell owner has any Advances that are needed for the type of improvement you want to carry out and also that he has enough PW stored up to pay for them. It also doesn't work instantaneously but more realistically takes a few turns just like when you do it manually.

              So you'll need to adjust the RemoveAdvance lines for forest and jungle in terrain.txt from agricultural revolution to something really basic like agriculture. Also, to make sure that the AI has enough PW to pay for these improvements you might have to lower their cost. If there's a problem here, tell me about it because another possibility is to use SLIC to give the AI whatever PW it needs. (In the mod I was working on, the AI is a bit different and always has lots of reserve PW; so I never had to worry about this.)

              What happens here is that when the city grows to 6, you get a message saying

              "Sire, The city of {city[0].name} is bursting at the seams. We have
              sent squads of workers to scour the surrounding countryside and collect building
              materials for it's expansion."
              and most, but not all, of the forests/jungles in the cells that the city is about to expand out into will start to be transformed into plains.

              While we're on the topic of terraforming, the reason, IMHO, why you need to terraform so much is because the map generator is so lousy. Here's the settings from Const.txt that I use for my map generator:

              # all numbers are integers ranging from 0 to 100

              PERCENT_LAND 40 # how much of the world is land
              PERCENT_CONTINENT 50 # how much of the world tends toward big continents verses small islands
              PERCENT_HOMOGENOUS 5 ## how "clumpy" the land terrain is

              # the meridians are normalized on the map at 0 to 100 - 0 is all the way north
              # and 100 is all the way south - 50 is the middle - this works on a map of
              # any size

              MERIDIANA 1 # north of this is north pole
              MERIDIANB 44 # north of this is north mild
              MERIDIANC 48 # north of this is north desert
              MERIDIAND 52 # north of this is the equatorial region
              MERIDIANE 56 # north of this is south desert
              MERIDIANF 99 # north of this is the south mild, south is the south pole

              # the humidity controls the distribution of forest, jungle, swamp, grass, plains, desert
              # tundra and glacier
              # A bump map is randomly generated. The bumps range from 0 to 100. High bumps are
              # wet terrain, low vallies are dry terrain.
              # What terrain is used depends on what meridian you are in

              # The height values have a gaussian distribution, with middle values being the most
              # common. The HLEVEL values should be adjusted to take into account the integral
              # of the gaussian.

              # HLEVELA must be greater than HLEVELB, HLEVELB must be greater than HLEVELC etc

              HLEVELA 99 # above this is the wet terrain
              HLEVELB 95 # above this is sort of wet terrain
              # here's the middle
              HLEVELC 5 # below this is sort of dry terrain
              HLEVELD 1 # below this is dry terrain

              # The wet/dry slider on the custommap screen uses these values.
              # The sum of all the wet values together with the swamp wet value will add to 100.
              # Similarly for the dry values. Actually, swamp = 100 - (forest + grass + plains + desert).

              FORESTWET 20
              GRASSWET 70
              PLAINSWET 10
              DESERTWET 0
              # This leaves 0 for swamp.

              FORESTDRY 20
              GRASSDRY 70
              PLAINSDRY 10
              DESERTDRY 0
              # This leaves 0 for swamp.

              # The warm/cold slider on the custommap screen uses these values.

              WHITEWARM 1#5
              BROWNWARM 5#30

              WHITECOLD 1#30
              BROWNCOLD 5

              # The goodcount slider on the custommap screen uses these values.

              RICHNESSFEWGOODS 25

              RICHNESSMANYGOODS 75

              PERCENT_MOUNTAIN 5 # percentage of land with mountains on it - this is a target only
              MOUNTAIN_CELL 10#5 # length of a side of a cell - one cell contains at most 1 mountain chain.

              PERCENT_HILLS 15 # percent of land with hills on it
              MOUNTAIN_SPREAD 25 # chance that the mountain chain spreads out
              MOUNTAIN_LENGTH 3 #25 # average length of a mountain chain

              GLACIER_EXTENT 1#3 # number of tiles the glacier extends - should be normalized
              PERCENT_VOLCANO 1 # percent of deep sea floor with volcanos
              PERCENT_TRENCH 4 # percent chance that a trench is seeded - then it spreads automatically

              # Swamps are placed at humidity levels above what forest works out to.
              PERCENT_FOREST 20
              PERCENT_GRASS 40
              PERCENT_PLAINS 25
              PERCENT_DESERT 1#10
              PERCENT_WHITE 2#20
              PERCENT_BROWN 2#20
              TEMPERATURE_RANGE_ADJUST 10#60
              # Adjust the temperature height map by negative this amount at the
              # poles, positive at the equator, linear scale in between

              NICE_RADIUS 10 # radius of effect when calculating niceness of player placement
              # the mininum start distance between players is 2 * NICE_RADIUS

              PERCENT_RIVER 5 # percent of land with a river on it
              RIVER_LENGTH 15 # average river length
              RIVER_CELL_WIDTH 5 # Size of cells to be searched for river starts
              RIVER_CELL_HEIGHT 5 # (highest point in each cell)
              These give (dare I say it in the context of the current civ3 vs CTP2 controversy) more civ2 like maps. They're by no means perfect: I can't get rid of the big clumps of hills and mountains. As I recall Scorpion59 had an excellent map generator but he'd never tell us the secret of it. Whenever the topic came up he'd just say something like 'It's an ongoing process. It just takes patience and fiddling around with the settings a bit.' Maybe if anyone reading this can get really good results, they could post them or start a discussion or something.

              Finally, it looks like we can safely conclude that the terraforming/tileimprovement apparatus as given in Strategies.txt is broken. When you first posted I thought 'Good luck to him. Maybe he'll find something I overlooked.' But now Wombat says he never could get it to work, and that makes three of us. It's clear that it's only half exposed: there's no mention of nets in ImprovementLists.txt yet the AI builds them quite happily. It looks like using SLIC is the only way you can get the terraforming/tileimprovements you want.
              Attached Files


              • #8
                Hi Peter,

                I'm using medmod 2 and city sizes change at size 8. I was wondering if there's a way to make it so that this triggers when a city reaches a low growth rate, or if not size 3. I would also like it to look within it's radius and terraform( in the real way using create improvement) forest jungles and other terrain to grassland or plains(whichever the AI has enough PW to build).

                I would also like the AI to build hills or mountains in its low production cities or remove them in order to reduce pollution. I was also wondering if it's possible to make the AI build commerce Improvements when it's science gets low, because as it stands it only builds them on swamps tundras and other bad terrains.

                this is how I edited the file, to try to make it terraform at size 3 and in the current raduis.

                HandleEvent(MakePop)'ExpandingCityTileImprovement' post {

                location_t theLoc;
                location_t firstLoc;

                // this triggers when the city's population grows to
                // 3

                int_t i;
                int_t j;

                if (city[0].population==3) {
                for (j=0; j<=7 ; j=j+1) { //directions
                GetNeighbor(firstLoc, j, theLoc);//look around

                if ( CellOwner(theLoc)==city[0].owner && HasGood(theLoc)==-1) {
                if (TerrainType(theLoc)==0 || TerrainType(theLoc)==7 ) {
                // 0=forest, 7=jungle
                Event:CreateImprovement(city[0].owner,theLoc, 32,0);
                //change to plains

                will it work?


                • #9
                  No. Because that only fires when the city grows in size, the event is (makepop).

                  The code does everything in the city radius, and you only need to terraform the next ring out when it is size 6. To allow for MedMod, change the 3 you added, to 8. When the city is size 3, the other handler will have taken care of everything.

                  Concrete, Abstract, or Squoingy?
                  "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis


                  • #10
                    I don't like the other handler because it uses terraform instead of createimprovement, so I'll just change that. Will the make pop trigger(the second one) stop when the City gets bigger than 6( or in my case 8)? Would I have to make more trigger for size 20( when it reaches maxsize again for the second radius in medmod), size 36(max for 3rd radius), size 44(max for 4th radius), and size 56( max for 5th raduis)?

                    I added the code to my mm2_scenario.slc and it says that there's a syntax error in the code on line 189, which is somewhere in the beginning of the code.


                    • #11
                      You would have to make an extra bit of code for each size, but the code would get increasingly complicated as you tried to find the affected squares. By that time, a few forests shouldn't matter much.
                      Concrete, Abstract, or Squoingy?
                      "I don't believe in giving scripting languages because the only additional power they give users is the power to create bugs." - Mike Breitkreutz, Firaxis


                      • #12
                        There should be a semi-colon after THE_NEAREST_CITY declaration.

                        The reason I used the terraform function for the NewCity handler is that I think it corresponds with the way the city is created: one second there's a settler then 'whosh' there's a city. What did they build it from? So I thought it's reasonable to have any nearby trees disappear as the city materializes out of nowhere. If you prefer to do it by the CreateImprovement event, go ahead; but it's not going to make a lot of difference.

                        The way it's set up the AI only gets one chance at doing the terraforming: if it doesn't have enough PW when the events occur, it won't get another whack at it. The alternative would be to check every tile in every city's radius at every turn. I didn't even think about trying this because it would be bound to slow the game down to a snail's pace.


                        • #13
                          I guess that makes sense, I think I'll leave it like that, but change it to grassland. Is there a way to make it so that it does it if a city is larger than or equal to 8, by using >= instead of ==. How would I make it so that it does this at citysizes 3, 4, etc... how would it look at the tiles?

                          I was wondering does this work for the human player or just the AI? I think the create one should work for the human and the AI, but the second one should only work for the AI, seeing as how the human knows how to terraform.


                          • #14
                            Hmm, I never thought of that. If you were to use 3<=city[0].population then, I think that what should happen is that every time the city's population increases beyond 2 it'll do a search of the tiles (within the citysize1 radius) and try to do the terraforming. If it's got enough PW, it'll do it and after that nothing happens. If it doesn't have enough PW, it'll do whatever it can and then try again when the city's pop increases again. Sounds like a good idea. See if it works.

                            Edit: This is assuming you're not using the NewCity handler. Otherwise, make it 8<=city[0].population. This would be my choice because it should ensure that the AI gets off to a better start.


                            • #15
                              Originially posted by Peter Triggs
                              The way it's set up the AI only gets one chance at doing the terraforming: if it doesn't have enough PW when the events occur, it won't get another whack at it.
                              There is a way to make shure when the event occurs that the AI has enough PW. In the Mars 2020 scenario there is a code that gives the player extra PW. Here is the code that I found in the treecutters.slc modified with Ben's Mars 2020 PW add code.

                              if (TerrainType(theLoc)==0 || TerrainType(theLoc)==7 )  {
                              // 0=forest, 7=jungle
                                      tmpPw = player[0].publicworkslevel;
                                      tmpPw2 = tmpPw + 400;
                                      setPW(city[0].owner, tmpPw2);
                                      Event:CreateImprovement(city[0].owner,theLoc, 32,0);
                                      //change to plains 		       
                              Of course tmpPw and tmpPw2 must be declared before in the event handler.

                              PS: Disclamer: untested, untried

                              Civ2 military advisor: "No complaints, Sir!"