Announcement

Collapse
No announcement yet.

creating natural disasters via SLIC????

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

  • #46
    Important correction: to add a building one should use the code:
    Event:CreateBuilding(tmpCity, BuildingDB(IMPROVE_DROUGHT));
    So with 'Event:' in front of the eventname. I don't know how that could fallen away. To destroy it the function DestroyBuilding will work, as Radical mentioned earlier.

    To get non-global floods, you could use the Terraform function. My suggestion would be: check all squares in a 3 tile radius (or something similar) and if a tile is swamp, plain or grassland either adjacent to sea or with a river running through it, terraform it to beach/shallow water (whatever turns out to work best), do the same for all squares adjacent to it. (To get an adjacent tile, use a for loop and GetNeighbor). If a tile is of any other terraintype or doesn't have a river or sea near it, check the next tile. A good way to cycle through tiles could be to use a double for-loop with MakeLocation that has variables x and y(which range from location.x - 3 to location.x + 3, similar for y) as arguments, which come from the for-loops.
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

    Comment


    • #47
      I've got part of the earthquake stuff working.

      So far if it's centered on a city it may destroy a building depending on the size quake. Also depends on if the building is there or not. It may try to destroy a building that isn't built yet in which case nothing happens. If it's level 8 (highest) you'll lose city walls. That can be easily changed by anyone to something else or deleted.

      Random tiles surrounding the epicenter may lose tile improvements.

      Random units in or around the epicenter will lose hitpoints. At this point I don't have them getting killed. I have it tied to the scale of the quake but if their hit points are less than 8 I'm not taking hitpoints because they ended up with negative hitpoints in some cases and weird stuff started happening.

      All this works with me specifying a location I know is a city. I'm working on the random location part but it's been crashing so far. I haven't tried with specifying a location say one tile from a city to see what happens. Probably gonna break for a while and watch some football. I'll post what works later today even if I don't get the random location part working. Maybe someone else can get that. I was trying to make it so this would work with any size map automatically. It may turn out that you just have to edit scenario.txt and plug in your map size.

      I'm trying to use GetMapHeight () and GetMapWidth ()
      I'm not sure if a variable goes between the () or not. I'm crashing with nothing between the (). Hopefully Locutus or someone else can answer before I get back to it later.

      Comment


      • #48
        quote:

        Originally posted by Locutus on 01-07-2001 02:26 PM
        To get non-global floods, you could use the Terraform function. My suggestion would be: check all squares in a 3 tile radius (or something similar) and if a tile is swamp, plain or grassland either adjacent to sea or with a river running through it, terraform it to beach/shallow water (whatever turns out to work best), do the same for all squares adjacent to it. (To get an adjacent tile, use a for loop and GetNeighbor). If a tile is of any other terraintype or doesn't have a river or sea near it, check the next tile. A good way to cycle through tiles could be to use a double for-loop with MakeLocation that has variables x and y(which range from location.x - 3 to location.x + 3, similar for y) as arguments, which come from the for-loops.


        This this the same concept i'd use to see if a tile has a river so i can build a dam on it as a tile improvement?

        ------------------
        History is written by the victor.

        Comment


        • #49
          Radical, post what you have, even if it doesn't work (the random part). I'll have a look at it. I got mapsize-independent location-generators working for CtPI and if needed I'll do it again for CtPII.

          Alpha,
          Yeah, I suppose that's possible. What effect should a dam have anyway?
          [This message has been edited by Locutus (edited January 07, 2001).]
          Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

          Comment


          • #50
            quote:

            Originally posted by Locutus on 01-07-2001 04:05 PM
            Radical, post what you have, even if it doesn't work (the random part). I'll have a look at it. I got mapsize-independent location-generators working for CtPI and if needed I'll do it again for CtPII.

            Alpha,
            Yeah, I suppose that's possible. What effect should a dam have anyway?
            [This message has been edited by Locutus (edited January 07, 2001).]


            I figured dams were early power generators, so they'd production. Figured it would give me another option for some forst tiles since this is were I like to build and i cant put farms or mines there. Then a wonder like TVA or Hoover would double that effect.

            ------------------
            History is written by the victor.

            Comment


            • #51
              AW, please type your email address so I can send you the files. I'll post here but figured it would be eaiser for you if I sent them. I'll also send to Locutus and Herdie if his addy is here. Your addy came up strange when I clicked on the email icon.

              Comment


              • #52
                Still didn't get random location to work. It just crashes with no msg when I include the lines for that. It may be that it's putting the location off the map. Perhaps limiting to between 3 and max x-4 would fix it. Same with y. Anyway, this works for a certain location, whatever is in tmpXloc, tmpYloc. I commented out the last random part I tried to get to work.

                I was using huge map size for testing it so it may not work with other sizes. Put a city in the location, add some bldgs, and units all around and in the city and see what happens. Pretty cool, IMHO. It works at locations other than cities as well. I probably have some unnecessary stuff in this but it works (except the random part) anyway. Never claimed to be a programmer. I planned to add a msg and maybe have a city lose a pop if the epicenter was a city, but this is what's done for now.

                scenario.slc

                /////////////////////////////////////////////////////////////////////////////////////
                // Script for the earthquake disaster mod 1.0 //
                // last update 01-07-2001 by Charles Rothermel Apolyton name Radical_Manuvr //
                /////////////////////////////////////////////////////////////////////////////////////


                //////////////////////
                // Global variables //
                //////////////////////

                int_t humanPlayer; // The human player number
                int_t tmpYloc;
                int_t tmpXloc;
                int_t turnCount; // Number of turns elapsed
                int_t turnMax; // Turns until scenario ends
                location_t disasterLoc;
                location_t disasterLoc2;

                #include "EQ_func.slc" // Functions

                //////////////
                // Handlers //
                //////////////

                //---------------------------------
                // Stuff to do when the game starts
                //-----------------------------------

                HandleEvent(BeginTurn) 'EQStart_F' pre {
                int_t tmpPlayer;
                if(IsHumanPlayer(player[0])) {
                humanPlayer = player[0];

                turnMax = 600; // if turnCount reaches turnMax, the game ends
                turnCount = 0; // number of turns elapsed
                // tmpXloc = 64; // max x for huge map, if using different size enter max x here
                // tmpYloc = 128; // max y for huge map, if using different size enter max y here
                // tmpXloc = GetMapWidth();
                // tmpYloc = GetMapheight();
                DisableTrigger('EQStart_F');
                }
                }

                //-----------------------
                // Stuff to do every turn
                //-------------------------

                HandleEvent(BeginTurn) 'EQEachTurn_F' post {
                city_t tmpCity;
                int_t i;
                int_t tmpPlayer;
                int_t tmpRichter; // Richter scale simulator
                int_t tmpDestroy; // used to determine which building to destroy
                int_t tmpnumberUnits;

                tmpPlayer = player[0];
                // tmpXloc = Random(63); // -1 from map size since random starts at 0
                // tmpYloc = Random(127); // -1 same

                tmpXloc = 29;
                tmpYloc = 75;

                if (tmpPlayer == 1) {
                turnCount = turnCount + 1; // increment turn counter
                if (turnCount > turnMax) {
                if (humanPlayer == 1) {
                Event:GiveMap(2,1); // this is temporary just need something here
                }
                } // temp for testing take out later
                MakeLocation(disasterLoc, tmpXloc, tmpYloc);
                tmpRichter = Random(8); // random number from 0-8
                tmpDestroy = Random(52); // random number from 0-52
                GetCityByLocation(disasterLoc, tmpCity);

                if (CityIsValid(tmpCity)) { // if a city exists at the epicenter
                tmpnumberUnits = UnitsInCell(disasterLoc); // number of units in cell
                if (tmpnumberUnits > 0) {
                QuakeDamage (disasterLoc, tmpnumberUnits, tmpRichter);
                }
                for (i = 0; i < tmpRichter; i = i + 1) {
                GetRandomNeighbor(disasterLoc, disasterLoc2); // find a random tile one tile from epicenter
                Event:CutImprovements(disasterLoc2); // destroy tile improvements if found
                tmpnumberUnits = UnitsInCell(disasterLoc2); // number of units in cell
                if (tmpnumberUnits > 0) {
                QuakeDamage (disasterLoc2, tmpnumberUnits, tmpRichter);
                }
                }
                if (tmpRichter > 5) { // if quake is 6, 7, or 8 a building will be destroyed if it exists
                // if the building doesn't exist nothing happens to buildings
                if (tmpDestroy == 0 | | tmpDestroy == 1) { // 2 in 52 chance
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_VR_AMUSEMENT_PARK));
                } elseif (tmpDestroy == 2) { // 1 in 52 chance
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ACADEMY));
                } elseif (tmpDestroy == 3) { // 1 in 52 chance from here down
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_AIRPORT));
                } elseif (tmpDestroy == 4) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ANTI_BALLISTIC_MISSILES));
                } elseif (tmpDestroy == 5) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_AQUA_FILTER));
                } elseif (tmpDestroy == 6) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_AQUEDUCT));
                } elseif (tmpDestroy == 7) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ARCOLOGIES));
                } elseif (tmpDestroy == 8) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ARENA));
                } elseif (tmpDestroy == 9) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BALLISTA_TOWERS));
                } elseif (tmpDestroy == 10) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BANK));
                } elseif (tmpDestroy == 11) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BASCILICA));
                } elseif (tmpDestroy == 12) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BATTLEMENTS));
                } elseif (tmpDestroy == 13) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BAZAAR));
                } elseif (tmpDestroy == 14) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BEHAVIORAL_MOD_CENTER));
                } elseif (tmpDestroy == 15) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BODY_EXCHANGE));
                } elseif (tmpDestroy == 16) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_BROKERAGE));
                } elseif (tmpDestroy == 17) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_CAPITOL));
                } elseif (tmpDestroy == 18) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_CITY_WALLS));
                } elseif (tmpDestroy == 19) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_COMPUTER_CENTER));
                } elseif (tmpDestroy == 20) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_CORNUCOPIC_VAT));
                } elseif (tmpDestroy == 21) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_CORRECTIONAL_FACILITY));
                } elseif (tmpDestroy == 22) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_COURTHOUSE));
                } elseif (tmpDestroy == 23) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_DRUG_STORE));
                } elseif (tmpDestroy == 24) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_E_BANK));
                } elseif (tmpDestroy == 25) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ECO_TRANSIT));
                } elseif (tmpDestroy == 26) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_FACTORY));
                } elseif (tmpDestroy == 27) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_FLAK_TOWERS));
                } elseif (tmpDestroy == 28) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_FOOD_SILO));
                } elseif (tmpDestroy == 29) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_FORCEFIELD));
                } elseif (tmpDestroy == 30) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_FUSION_PLANT));
                } elseif (tmpDestroy == 31) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_GAIA_COMPUTER));
                } elseif (tmpDestroy == 32) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_GRANARY));
                } elseif (tmpDestroy == 33) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_HOSPITAL));
                } elseif (tmpDestroy == 34) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_INCUBATION_CENTER));
                } elseif (tmpDestroy == 35) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_MATTER_DECOMPILER));
                } elseif (tmpDestroy == 36) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_MICRO_DEFENSE));
                } elseif (tmpDestroy == 37) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_MILL));
                } elseif (tmpDestroy == 38) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_MOVIE_PALACE));
                } elseif (tmpDestroy == 39) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_NANITE_FACTORY));
                } elseif (tmpDestroy == 40) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_NUCLEAR_PLANT));
                } elseif (tmpDestroy == 41) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_OIL_REFINERY));
                } elseif (tmpDestroy == 42) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ORBITAL_LABORATORY));
                } elseif (tmpDestroy == 43) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_POWER_SATELLITE));
                } elseif (tmpDestroy == 44) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_PUBLIC_TRANSPORTATION));
                } elseif (tmpDestroy == 45) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_PUBLISHING_HOUSE));
                } elseif (tmpDestroy == 46) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_RECYCLING_PLANT));
                } elseif (tmpDestroy == 47) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_ROBOTIC_PLANT));
                } elseif (tmpDestroy == 48) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_SECURITY_MONITOR));
                } elseif (tmpDestroy == 49) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_SHRINE));
                } elseif (tmpDestroy == 50) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_TELEVISION));
                } elseif (tmpDestroy == 51) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_THEATER));
                } elseif (tmpDestroy == 52) {
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_UNIVERSITY));
                }
                if (tmpRichter == 8) { // if quake is 8, city walls will be destroyed if they exist
                // at this magnitude something should go
                DestroyBuilding(tmpCity, BuildingDB(IMPROVE_CITY_WALLS));
                }
                }
                } else { // no city at epicenter
                Event:CutImprovements(disasterLoc); // destroy tile improvements if found at epicenter
                tmpnumberUnits = UnitsInCell(disasterLoc); // number of units in cell
                if (tmpnumberUnits > 0) {
                QuakeDamage (disasterLoc, tmpnumberUnits, tmpRichter);
                }
                for (i = 0; i < tmpRichter; i = i + 1) {
                // the higher the Richter number the more likely a tile improvement will be destroyed
                // can be up to 8 tile improvements destroyed surrounding epicenter
                GetRandomNeighbor(disasterLoc, disasterLoc2); // find a random tile one tile from epicenter
                Event:CutImprovements(disasterLoc2); // destroy tile improvements if found
                tmpnumberUnits = UnitsInCell(disasterLoc2); // number of units in cell
                if (tmpnumberUnits > 0) {
                QuakeDamage (disasterLoc2, tmpnumberUnits, tmpRichter);
                }
                // possible that it will use the same tile 8 times or other combos, ex. 1 twice, another once, another 3 times
                // losing all tile impr. around epicenter should be rare
                }
                }
                }
                }

                EQ_func.slc


                ///////////////
                // Functions //
                ///////////////

                // Damages all units in location
                void_f QuakeDamage (location_t tmpLoc, int_t tmpNum, int_t tmpNum2)
                {
                int_t i;
                unit_t tmpUnit;

                for (i = 0; i < tmpNum; i = i + 1) {
                GetUnitFromCell(tmpLoc, i, tmpUnit);
                if (tmpUnit.hp > 8) {
                DamageUnit(tmpunit, tmpNum2); // Subtract tmpNum2 hit points from the specified unit
                }
                }
                }

                Comment


                • #53
                  quote:

                  Originally posted by Radical_Manuvr on 01-07-2001 07:03 PM
                  AW, please type your email address so I can send you the files. I'll post here but figured it would be eaiser for you if I sent them. I'll also send to Locutus and Herdie if his addy is here. Your addy came up strange when I clicked on the email icon.


                  CTPAlphaWolf@aol.com

                  When I setup that account on aol i set it up as CTP Alpha Wolf forgetting that the email address would freak out on the spaces. Took me a few days of harrassing poor Dan and Mark in order to figure out that my actual email address didnt have the spaces. Now I'm afraid to touch it in my profile....LOL

                  I think i remember seeing that buildings are assigned a number as its read into the database. If so, you can just do a loop thru the number of buildings and would save a ton of code.

                  Something like:

                  if (tmpRichter > 4) { // if quake is 5, 6, 7, or 8 buildings have a chance to be destroyed
                  // if the building doesn't exist nothing happens to buildings

                  for(b = 0; Building.Type[b] <> ""; b = b + 1)
                  { //assuming this is how to identify the end of the array
                  if random(tmpRichter * 3) > 12 {
                  //chance any building will be destroyed
                  DestroyBuilding(tmpCity, Building.Type[b])
                  }
                  }


                  Also, depending on how SLIC does there rounding, tmpRichter = Random(8); will most likely give you a range of 0 to 7. Most of the randomizers i've seen over the years simply drop fractional values so getting the 8 would be so rare that in essence it would never happen. However, if SLIC's randomizer rounds then you can get 8 more often.
                  ------------------
                  History is written by the victor.
                  [This message has been edited by Alpha Wolf (edited January 07, 2001).]
                  [This message has been edited by Alpha Wolf (edited January 07, 2001).]

                  Comment


                  • #54
                    Great work!

                    I'll force that together with my code and see what happens. This should be good

                    Comment


                    • #55
                      What is

                      #include "EQ_func.slc" // Functions ????


                      I put the code into scenario.slc but the game crashes on that line.

                      ------------------
                      History is written by the victor.

                      Comment


                      • #56
                        EW_FUNC
                        Code:
                          ///////////////
                         // Functions //
                        ///////////////
                        
                        // Damages all units in location
                        void_f QuakeDamage (location_t tmpLoc, int_t tmpNum, int_t tmpNum2)
                        {
                        int_t	i;
                        unit_t tmpUnit;
                        
                        	for (i = 0; i < tmpNum; i = i + 1) {  
                        		GetUnitFromCell(tmpLoc, i, tmpUnit);
                        		if (tmpUnit.hp > 8) {	
                        			DamageUnit(tmpunit, tmpNum2);		// Subtract tmpNum2 hit points from the specified unit
                        		}
                        	}
                        }

                        Comment


                        • #57
                          So close to getting this work..
                          Okay now
                          I added this

                          ################################################## ##########

                          IMPROVE_DROUGHT {
                          DefaultIcon ICON_IMPROVE_GRANARY
                          Description DESCRIPTION_IMPROVE_GRANARY
                          EnableAdvance ADVANCE_AGRICULTURE
                          ProductionCost 0
                          Upkeep 0
                          FoodPercent -0.25
                          }

                          ################################################## ##########

                          IMPROVE_GREATWEATHER {
                          DefaultIcon ICON_IMPROVE_GRANARY
                          Description DESCRIPTION_IMPROVE_GRANARY
                          EnableAdvance ADVANCE_AGRICULTURE
                          ProductionCost 0
                          Upkeep 0
                          FoodPercent 0.25
                          }

                          ################################################## ##########

                          ANd it crashed saying
                          'buildings.txt:727: Record does not start with name'

                          not how can I fix this?

                          Comment


                          • #58
                            quote:

                            Originally posted by heardie on 01-08-2001 12:17 AM

                            'buildings.txt:727: Record does not start with name'

                            not how can I fix this?


                            i got that error when i tried to add some wonders to the end of the wonders file. I moved them all to the top and the error went away. Made no other changes.

                            ------------------
                            History is written by the victor.

                            Comment


                            • #59
                              Thanks Alpha. More errors here though and i havent even tried adding radical's eq code.

                              i dont know how or why but the line

                              for(m = 0; m <= player.cities; m = m + 1){

                              is being flagged as an wrror, because 'player is not a structure'. This must work,, shouldnt it?

                              NOTE: I will be gone most likly till friday from the forums, but when i return I hope to have it all done bar floods

                              Comment


                              • #60
                                On a scale of 1 to 10 (expert), my SLIC is about a 2, but that sure looks right to me. I assume that you declared "int_t m"? As I've been trying to implement Rad's code (so far unsuccessfully) I've noticed some of the error messages are misleading. So now when I get an error on a line, I mostly ignore the message itself and concentrate on the entire line. But according to the SLIC doc player.cities is valid.

                                Oh crud....while i was looking at valid flags I realized that we could code for labor strikes if a city riots and remove a percentage of PW. Someone turn my brain off before I have any more ideas....LOL

                                We probably want to use the "AddCenter(loc)" to center on the quake also. OMG, the examples show how to make a city immune to riots and revolts. I was so tired when I read thru this stuff the first time that I didnt realize how many things we can do.

                                And i wonder if we could use SLIC to have the AI build an effective army. Interesting that there is an unit.name but not an army.name. We could have had units join specific armies and when those armies = 12 units, off they go to war, like a blitzkrieg. I wonder how to tell which units are grouped.

                                whew, i finally switched the brain off for the night or I'll be up all night coming up with new ideas.

                                ------------------
                                History is written by the victor.

                                Comment

                                Working...
                                X