Announcement

Collapse
No announcement yet.

How to make AI convert their terrain?

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

  • #16
    Originally posted by
    sun_tzu_159

    The SLIC completes its checking loop correctly but does not put the good back on the square it came from with the above command - any ideas.
    In GoodMod you can devide the goods into two parts. On the one hand the invisible part, the tile improvement that adds the boni to the tile and on the other hand the trade good, that is also in the original game. And it is the visible part of the Good.

    So you want to recreate the entire good. You have to recreate the tile improvement. Note that the first argument must be the owner of the cell or the owner of an unit that has this location in its vision range. If the future owner does not own the location he can only build there tile improvements with fort like characteristics.

    Maybe you should rather use the version of the goods restoration code:

    PHP Code:
    Event:CreateImprovement(CellOwner(location[0]), location[0], 520); 
    Instead of the number for the third argument you can also use a funktion that returns the DB index of the improvment here is an example from BlueO:

    PHP Code:
    EventCreateImprovement(tmpCity.ownertmpLocTerrainImprovementDB(TILEIMP_ROAD), TerrainImprovementDB(TILEIMP_ROAD)); 
    You notice that he used the fourth argument it requres an Int but I have also no idea what it does. From BlueO's example you might think this could the an option for a second improvment, but I think it does nothing it is just there. Otherwise my code would create a lot of advanced farms.

    With this funktion you don't need to take so much care on your improvemnt database as you have to do it if you use the numbers.

    If the the tile improvment is back on the map than it needs a certain time until it is finished. All good improvments have a contruction time of ten turns. As long as you don't use this function on the given location:

    PHP Code:
    FinishImprovements(MGUnitLoc); 
    So the improvment will be finished but in your case the good would be still missing just the terrain boni would be back. So finally or at first you have to plant a good that is the funktion that will do the job:

    PHP Code:
    PlantGood(MGGoodLoc); 
    But why do it in a so complecate way just prevent the AI and the mayors from terraforming the good. From your ImprovementsList.txt I know that you considered more terraforming options for the AI (I just use the grassland option), but that means that you have to modify my code that I gave above.

    PHP Code:
    HandleEvent (CreateImprovement)'MG_ImpOnGoodStop' pre {
    int_t MG_tilimpcreate;
    MG_tilimpcreate value[0];
    improvement[0] = MG_tilimpcreate;
        if (
    GetCurrentRound () > 1) {
            if (
    HasGood(MGGoodLoc)>-1) {
                if ((
    MG_tilimpcreate == TerrainImprovementDB(TILEIMP_TERRAFORM_GRASSLAND))
                  ||(
    MG_tilimpcreate == TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS))
                  ||(
    MG_tilimpcreate == TerrainImprovementDB(TILEIMP_TERRAFORM_JUNGLE))
                  ||(
    MG_tilimpcreate == TerrainImprovementDB(TILEIMP_TERRAFORM_FOREST))
                  ||(
    MG_tilimpcreate == TerrainImprovementDB(TILEIMP_TERRAFORM_SWAMP))) {
                    return 
    STOP;
                }
            }
        }

    Another note about the improvment list the original file looks unfinished and the AI was able to improve its terrain. It uses also some of my good improvments. So I guess this file is there but completely useless.

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

    Comment


    • #17
      Dear all,

      Immortal Wombat - thanks for the pointers, I think this function was made for something not fully implemented. I have tried many values for the last digit but no effect is seen.
      Great suggestions - keep them coming. I have pasted below my slic file so far. It scans the whole map at the start of the turn and records the goods locations in the array JDGoodsHere. I have put Dales trumpets in just to prove that it correctly identifies all squares with goods on.


      location_t JDGoodLoc; //where the search for goods is at
      int_t JDCounter; //array location counter
      location_t JDGoodsHere[]; //array to load with location of all goods at start of turn
      int_t JDTerrainScore; //determine which terrain the new good is to be placed on
      int_t CellOwner; //Returns value for player number

      #include "tut2_terraina.slc" //TERRAIN_SCOREA array is here

      // Load up array with location of squares with goods on them.

      HandleEvent(BeginTurn) 'JRD_BeginTurn' pre {

      //set up local variables for routine

      int_t i; //array location counter
      int_t j; //array location counter

      JDCounter=0;
      for (i=0; i<=GetMapWidth()-1; i=i+1) {
      for (j=0; j<=GetMapHeight()-1 ; j=j+1) {
      MakeLocation(JDGoodLoc, i, j);
      if (HasGood(JDGoodLoc) > -1) {
      JDCounter=JDCounter+1;
      JDGoodsHere[JDCounter]=JDGoodLoc;
      }
      }
      }
      }

      //################################################## ###############################################
      //################################################## ###############################################

      //Next bit attempts to stop tile improvement being placed on trade good.

      HandleEvent(CreateImprovement) 'JRD_CreateImprovement' pre {

      //set up local variables for routine

      int_t m; //array location counter

      for(m=0;m JDGoodLoc=JDGoodsHere[m];
      JDTerrainScore=TERRAIN_SCOREA[TerrainType(JDGoodLoc)];
      if (HasGood(JDGoodLoc)>-1){
      AddEffect(JDGoodLoc, "SPECEFFECT_DIPLOMATIC", "SOUND_ID_EXPEL");
      return STOP;
      }
      }
      }

      //################################################## ###############################################
      //################################################## ###############################################


      Somehow the AI gets round the return STOP whether pre or post createimprovement and transforms the land and deletes the trade goods.

      So I have tried putting the trade goods back but don't know an instruction to do this. The following piece of code checks the array of goods set up prior to the terrainimprovement and compares it to the current map. Where goods are missing they should be replaced. But I do not know the numbers to put in to replace trade goods.


      //Next bit runs every turn to check if any goods have disappeared
      //if they have then they are replaced on the map with the appropriate good for the transformed tile
      //Check done by checking terrain score to see what type of terrain

      HandleEvent(ImprovementComplete) 'JRD_ImprovementComplete' post {

      //set up local variables for routine

      int_t m; //array location counter

      for(m=0;m JDTerrainScore=TERRAIN_SCOREA[TerrainType(JDGoodsHere[m])];
      JDGoodLoc=JDGoodsHere[m];
      AddEffect(JDGoodLoc, "SPECEFFECT_DIPLOMATIC", "SOUND_ID_EXPEL");
      if (HasGood(JDGoodLoc)<0){//Replace Goods Here
      AddEffect(JDGoodLoc, "SPECEFFECT_DIPLOMATIC", "SOUND_ID_EXPEL");
      Event:CreateImprovement(player[CellOwner], JDGoodLoc, 49, 0);



      I have observed that the scenario (cheat) editor quite happily transforms land without deleting goods and adds/removes trade goods without a problem. There must be a code linked to pressing the add goods buttons 1-4 on this menu that can be used in this SLIC. Does anyone know what the code is or where it is?

      Martin I will try out with PlantGood function mentioned - thanks for the suggestion. I will post a working SLIC as soon as I have one but it will be MedMod because there are less goods and easier checking. The code will be easily expanded though.

      I agree that the original improvement file was hopeless - the AI could only build a very few improvements.

      I am sorry if the code is a bit clumsy but this is my first attempt at writing a complete script code from scratch.

      Waiting for any more input.

      Regards
      AOW.
      Lady Astor : "If I were your wife I would put poison in your drink"
      Churchill : "If I were your husband I would gladly drink it"
      Unclear words can wipe out all human life on earth if used improperly

      Comment


      • #18
        Hi all,
        Back again, and so soon. Please find attached file which works by scanning all the map prior to the start of the turn and loads all the locations of the trade goods into an array. As I said before this is based on MedMod but may well work with any mod.
        The second part runs after the terrainimprovements are done and checks that no values on the map are different to the start of the turn for those locations where goods existed. If they are different the trade good is replaced and will reappear but only as trade good 1.
        Could there be a way to get the good replaced with the number of good prior to transformation.
        I cannot see any reason why this would not work with any Mod.

        Regards
        AOW
        Attached Files
        Lady Astor : "If I were your wife I would put poison in your drink"
        Churchill : "If I were your husband I would gladly drink it"
        Unclear words can wipe out all human life on earth if used improperly

        Comment


        • #19
          Hi, sun_tzu

          I don't think it's a good idea to search the whole map at the beginning of *every* turn: not all of us have supercomputers like Martin's and even his might find it difficult.

          I'm not at all sure what you guys are on about here, but I'm assuming that what you want to do is to stop the AI from terraforming tiles that have trade goods on them. In this case, what Martin suggested should work. In his GoodMod he had to use the MakeLocation function to assign a value to MGGoodLoc but here we can recover the location we want from the CreateImprovement event. In fact, we can recover the database value of the terrain improvement from this event too, so you don't even have to define any variables (unless you want to). Try this:

          Code:
          HandleEvent (CreateImprovement)'MG_ImpOnGoodStop' pre {
            
              if (GetCurrentRound () > 1) {//don't conflict with GoodMod
                  if (HasGood(location[0])>-1 && !IsHumanPlayer(player[0])) {
          	   //if the location has a good and it's the AI trying to:
                             //terraform it into grassland
                      if (( value[0] == TerrainImprovementDB(TILEIMP_TERRAFORM_GRASSLAND))  
                        ||( value[0] == TerrainImprovementDB(TILEIMP_TERRAFORM_PLAINS))     // ditto plains
                        ||( value[0] == TerrainImprovementDB(TILEIMP_TERRAFORM_JUNGLE))     // and so on
                        ||( value[0] == TerrainImprovementDB(TILEIMP_TERRAFORM_FOREST))
                        ||( value[0] == TerrainImprovementDB(TILEIMP_TERRAFORM_SWAMP))) {
                          return STOP; // don't let it do it
                      }
                  }
              }
          }
          This is basically what Martin wrote, I just added the condition "&& !IsHumanPlayer(player[0])" so that the human player can do any (maybe stupid) thing he wants. To test it, omit this clause; the handler should then prevent you from terraforming, e.g., any grassland tile that has a good on it.

          BTW, if you use 'code' and '/code', both in square brackets, at the beginning and end of your code it won't get left justified like that. The same thing works with 'quote' and '/quote'. It took me about a year of frustrating posts before I asked Locutus and he explained these things to me.

          Comment


          • #20
            Originally posted by Peter Triggs
            I don't think it's a good idea to search the whole map at the beginning of *every* turn: not all of us have supercomputers like Martin's and even his might find it difficult.
            I aggree therefore I suggested the code above. Maybe I should rewrite the Commerce Improvement For AI's code, so I could also speed up my games. But the delay that my good improving code cause it is not so long that the goody hut delay caused by the militia code. And of course it is much smaller than the delay caused by the original code.

            Originally posted by Peter Triggs
            This is basically what Martin wrote, I just added the condition "&& !IsHumanPlayer(player[0])" so that the human player can do any (maybe stupid) thing he wants. To test it, omit this clause; the handler should then prevent you from terraforming, e.g., any grassland tile that has a good on it.
            Actually I skipped that this small condition on purpose just to prevent human mayors to terraform goods.

            Originally posted by Peter Triggs
            BTW, if you use 'code' and '/code', both in square brackets, at the beginning and end of your code it won't get left justified like that. The same thing works with 'quote' and '/quote'. It took me about a year of frustrating posts before I asked Locutus and he explained these things to me.
            'PHP' and '/PHP' in square brackets will also work, it gives you this nice color effect and if you want to post some code from the Great Library it will display the code probably.

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

            Comment


            • #21
              Hi all,
              I have been away off the net with modem problems but all is now right again.

              quote:

              Originally posted by Peter Triggs
              I don't think it's a good idea to search the whole map at the beginning of *every* turn: not all of us have supercomputers like Martin's and even his might find it difficult.

              I do not have a supercomputer - I have a 233MHz PII for my CTP2 testing. Even as it is the routine is taking about 0.75 seconds per turn on a 144x72 map.

              The point of scanning the map on each turn is so that the goods are put back on the map at the end of each turn when the terrain terraform is completed - so you don't have to prevent terraforming by anyone.

              If the data held in the array was preserved when the game is saved then it is static data from the first turn and the whole map scan only has to be done once.

              If someone with a little more experience than me could put a Disable Trigger in the code after the first turn then the second part only checks the squares with goods on each turn - which on a V. large map is about 300 squares max. This cannot take alot of processor power.

              Any thoughts on a slight mod of the code I posted. I can test any suggestions put forward.

              Thanks for your input
              AOW
              Lady Astor : "If I were your wife I would put poison in your drink"
              Churchill : "If I were your husband I would gladly drink it"
              Unclear words can wipe out all human life on earth if used improperly

              Comment


              • #22
                Hi all,
                I have been experimenting with the settings for AI to terraform and the file I posted earlier - mm2_terrainmod.zip - does work for all trade goods so my comment about only putting back trade goods type 1 was wrong.
                The problem I have now is that the human player can use any available transformation immediately. e.g. from hill to grassland while the AI is forced by my terraform settings in tileimp.txt to go from hill to plains to grassland. This is because the human player is only restricted by the simple test as to whether or not the transform from hill and to grassland are available in terrain.txt and the AI uses tileimp.txt. Does anyone have any suggestions of a starting point for a SLIC code to control the human terraform.
                Did anyone follow up earlier comments about the AI not building undersea tunnels? Has anyone seen the AI construct undersea tunnels? When and where if they did?
                I have tried the following without success.
                1) Reducing the cost to miniscule amount of gold
                2) Increasing the movement rate per turn so that troops can move faster even than on MagLevs.
                3) Replacing the undersea tunnels with Maglevs to see if maglevs could be built in water.

                Perhaps a SLIC code along the lines of Cradles which forces the building of forts. Can I have some pointers and I will pick up suggestions and try them.

                Cheers
                AOW
                Lady Astor : "If I were your wife I would put poison in your drink"
                Churchill : "If I were your husband I would gladly drink it"
                Unclear words can wipe out all human life on earth if used improperly

                Comment


                • #23
                  I would like to include this code in my upcoming update for the Medpack, but I am confused as to whose code works the best.
                  Please paste in the code in with your new post.

                  Also, how intelligently does the AI use its terraforming ability? I mean, you only want to terraform Jungles to Plains and Plains to Grassland if the city is short on food. You also usually only need to terraform a few tiles per city. Does the AI keep terraforming simply because it can?
                  Also, the AIs need to be able and willing plant forests as well as clear them. How is it set up to do this?

                  This code can be a crucial improvement to the AI, since it only builds mines on plains and farms on grassland. Changing a few tiles from one to the other can have a huge effect on balancing a city's output.

                  Edit: I had Wouter send me copies of the files Sun Tzu posted here, and there are problems. First, the originals he used are now out-dated, and then he made his own modifications to the improvement effects. Thus, I don't know if the lines which fool the AI will work properly if pasted into standard versions of the MM2 tileimp.txt.
                  Last edited by WesW; February 27, 2002, 04:58.

                  Comment


                  • #24
                    I wouldn't use all his modifications, as the PW costs in terraform section are probably ignored, too. Sun Tzu thought that the costs are also set in the tileimp, too. But actual you have only consider the material costs of the add and remove section in the terrain.txt. For instance in the original terrain.txt it costs 2000 PW to remove a mountain and it costs 8000 to add an artic mountain, so terraforming from grey to white mountain costs in the original game 10000 PW. The production time is obviously taken from the terrain.txt, too. Another problem with his settings I think is that he made the AI terraform like the Civ2 human and AI players had to do it through the settler system. I made now for every terrain an own terrain block, to let the AI know when it can use the terraform option and gave every terrain effect block a food bonus value. You can find my code below I only modified the grassland option as I don't want to make the AI build forrest, but you could modify the forest section, too, although I think that will cause some more difficuilties. Unfortunatly I only played early games so far and the AI will only put a terrain improvement on a tile without an improvement as I saw that the Good tiles are usually without an additional tile improvement. So I would have to go into the late game when the AI can terraform tundra and mountains.

                    -Martin


                    PHP Code:
                    ## 28 ##########################################################

                    TILEIMP_TERRAFORM_GRASSLAND {
                       
                    Icon ICON_TERRAIN_GRASSLANDS
                       Tooltip TOOLTIP_TILEIMP_SELECT_GRASSLND_BUTTON
                       Statusbar STATUSBAR_TILEIMP_SELECT_GRASSLND_BUTTON
                       TerraformTerrain TERRAIN_GRASSLAND
                       Level 1
                       Column 0
                       
                    Class:Terraform
                       GLHidden

                       ConstructionTiles 1
                       ConstructionTiles 1
                       ConstructionTiles 1

                       CantBuildOn TERRAIN_WATER_BEACH
                       CantBuildOn TERRAIN_WATER_DEEP
                       CantBuildOn TERRAIN_WATER_KELP
                       CantBuildOn TERRAIN_WATER_REEF
                       CantBuildOn TERRAIN_WATER_RIFT
                       CantBuildOn TERRAIN_WATER_SHALLOW
                       CantBuildOn TERRAIN_WATER_SHELF
                       CantBuildOn TERRAIN_WATER_TRENCH
                       CantBuildOn TERRAIN_WATER_VOLCANO

                       Excludes
                    :Structure2
                       Excludes
                    :Structure1
                       Excludes
                    :OceanMine
                       Excludes
                    :OceanFarm
                       Excludes
                    :OceanDetector
                       Excludes
                    :OceanATM
                       Excludes
                    :Mine
                       Excludes
                    :LandDetector
                       Excludes
                    :Farm
                       Excludes
                    :ATM
                       Excludes
                    :OceanRoad
                       Excludes
                    :Road

                       TerrainEffect 
                    {
                          
                    Terrain TERRAIN_BROWN_HILL
                          BonusFood 30 
                          EnableAdvance ADVANCE_EXPLOSIVES
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_BROWN_MOUNTAIN
                          BonusFood 30 
                          EnableAdvance ADVANCE_FUSION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_DESERT
                          BonusFood 30 
                          EnableAdvance ADVANCE_AGRICULTURAL_REVOLUTION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_FOREST
                          BonusFood 30 
                          EnableAdvance ADVANCE_AGRICULTURAL_REVOLUTION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_GLACIER
                          BonusFood 30 
                          EnableAdvance ADVANCE_ADVANCED_COMPOSITES
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_HILL
                          BonusFood 30 
                          EnableAdvance ADVANCE_EXPLOSIVES
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_JUNGLE
                          BonusFood 30 
                          EnableAdvance ADVANCE_AGRICULTURAL_REVOLUTION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_MOUNTAIN
                          BonusFood 30 
                          EnableAdvance ADVANCE_FUSION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_PLAINS
                          BonusFood 5 
                          EnableAdvance ADVANCE_TOOLMAKING
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_SWAMP
                          BonusFood 30 
                          EnableAdvance ADVANCE_INDUSTRIAL_REVOLUTION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_TUNDRA
                          BonusFood 30 
                          EnableAdvance ADVANCE_ADVANCED_COMPOSITES
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_WHITE_HILL
                          BonusFood 30 
                          EnableAdvance ADVANCE_EXPLOSIVES
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_WHITE_MOUNTAIN
                          BonusFood 30 
                          EnableAdvance ADVANCE_FUSION
                          TilesetIndex 1
                       
                    }
                       
                    TerrainEffect {
                          
                    Terrain TERRAIN_DEAD
                          BonusFood 300 
                          EnableAdvance ADVANCE_CONSERVATION
                          TilesetIndex 1
                       
                    }

                    Civ2 military advisor: "No complaints, Sir!"

                    Comment

                    Working...
                    X