Announcement

Collapse
No announcement yet.

creating natural disasters via SLIC????

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

  • #61
    Heardie and AW, if you try to run my code remember that it only works on a specific tile at the moment. Locutus said he'd take a look at it to add random locations.

    AW when you get the error about EQ_func.slc...did you create the EQ_func.slc file and enter the code? It was near the bottom of the code posting. Counting up from the bottom }, go up 19 lines including blanks. Everything below that line (EQ_func.slc) goes in EQ_func.slc. I probably should have made it more clear that you need 2 files.

    I would have liked to use a for loop for the buildings but didn't see numbers for them anywhere. I didn't look real hard though. That wasn't the part that took long to do and I don't know whether it would make the game run slower. Maybe if the random number was for the bldg near the end of the list???

    Random - I was assuming that Random(8) would give me a chance at 0,1,2,3,4,5,6,7,8. From this site:

    · INT Random(range)
    Return a random number from 0 to range.

    I didn't think I'd get something like 2.37 and have it rounded. I'm pretty sure I got an 8 on my 18th turn in one test. I can't say for sure since I felt pressured and didn't get to make the message I had intended "reports of a magnitude 8 earthquake have come in from sector 3, 47". Anyway, I think random(any number) gives you "any number" + 1 (for zero).

    On the last Heardie msg about structures - I found that sometimes you have to use your own variable instead of the built-in variables. In this case tmpPlayer.cities or something. I have no idea when or whatever, I just experiment when I get errors.

    I'm stepping away from this for a few days. I'm helping playtest the Alex scenario and I need to play. I also wanted to look more closely to see if any of the other stuff in scenario.slc can be put into functions. When I get the msg or any other changes to the EQ mod I'll post them. Probably before Friday, shouldn't take long for the msg.

    Comment


    • #62
      Heardie,
      Use player[0] instead of player. Don't use tmpPlayer or whatever, that won't work, SLIC will think it's a number instead of a player.

      AW,
      An Eyepointer is better than AddCenter, 'cause another AddCenter event might occur and you loose the center on the earthquake. An eyepointer is that button with an eye on it you sometimes see. Clicking on it centers on a location (or unit or city).

      Using SLIC to improve AI will prove extremely difficult in practive (though a little 'push in the back' here and there will be possible). Checking if a units are in the same army is simple: cycle through all units in an army (using a for loop and army.size and GetUnitFromArmy) and compare.

      Radical,
      Random(x) should work from 0 to x-1. I tried Random(3) a couple of dozen times and never got anything but 0, 1, 2. Are you sure you got an 8 once? We should both try again if you are to double check our findings.

      Here's fixed code from Radical. The weird thing is, it basicly works but a call to a random function seems to crash the game without an error message. I'm fairly sure it's the Random fuction causing the problem, but I have no idea what the problem is. This is very weird 'cause I've used it often enough in the past without problems. Maybe it can't handle values larger then 60 or something? I tested it on a 48x96 maps and I think Random(52) isn't causing any problems, so if there is a problem with large numbers, the critical number is between 52 and 96. AW, you're an expert now, could you figure this out? I'm gonna be very busy for the next two days at least, so I won't have time to figure it out, but I will ASAP, this affects everyone working with SLIC and the Random code including yours truly.

      Note that there are no comments with this code, it crews up the thread so I just left them out. Shouldn't be too hard to understand anyway (all code can go in 1 file).

      Code:
      int_t	humanPlayer;
      int_t	turnCount;
      int_t	turnMax;
      location_t	disasterLoc;
      location_t	disasterLoc2;
      int_t	maxX;
      int_t	maxY;
      
      void_f QuakeDamage (location_t tmpLoc, int_t theNum, int_t theNum2) {
      int_t	i;
      int_t	tmpNum;
      int_t	tmpNum2;
      unit_t	tmpUnit;
      	tmpNum = theNum;
      	tmpNum2 = theNum2;
      
      	for (i = 0; i < tmpNum; i = i + 1) {  
      		GetUnitFromCell(tmpLoc, i, tmpUnit);
      		if (tmpUnit.hp > 8) {
      			DamageUnit(tmpunit, tmpNum2);
      		}
      	}
      }
      
      HandleEvent(BeginTurn) 'EQStart_F' pre {
      	if(IsHumanPlayer(player[0])) {
      		humanPlayer = player[0];
      	}
      	turnMax = 600;
      	turnCount = 0;
      	DisableTrigger('EQStart_F');
      	maxX = GetMapWidth();
      	maxY = GetMapheight();
      }
      
      HandleEvent(BeginTurn) 'EQEachTurn2_F' post {
      city_t	tmpCity;
      int_t	i;
      int_t	tmpPlayer;
      int_t	tmpRichter;
      int_t	tmpDestroy;
      int_t	tmpnumberUnits;
      int_t	tmpXloc;
      int_t	tmpYloc;
      
      	tmpPlayer = player[0];
      
      	if (tmpPlayer == 0) {	// && Random(2) == 1
      		tmpXloc = Random(maxX);
      		tmpYloc = Random(maxY);
      //		value[0] = tmpXloc;
      //		value[1] = tmpYloc;
      //		Message(1, 'EQTest');
      		turnCount = turnCount + 1;
      		if (turnCount > turnMax) {
      			if (humanPlayer == 1) {
      				Event:GiveMap(2,1);
       			}
      		}
      		MakeLocation(disasterLoc, tmpXloc, tmpYloc);
      		tmpRichter = Random(8);
      		tmpDestroy = Random(52);
      
      		GetCityByLocation(disasterLoc, tmpCity);
      		if (CityIsValid(tmpCity)) {
      			tmpnumberUnits = UnitsInCell(disasterLoc);
      			if (tmpnumberUnits > 0) {
      				QuakeDamage (disasterLoc, tmpnumberUnits, tmpRichter);
      			}
      			for (i = 0; i < tmpRichter; i = i + 1) {
      				GetRandomNeighbor(disasterLoc, disasterLoc2);
      				Event:CutImprovements(disasterLoc2);
      				tmpnumberUnits = UnitsInCell(disasterLoc2);
      				if (tmpnumberUnits > 0) {
      					QuakeDamage (disasterLoc2, tmpnumberUnits, tmpRichter);
      				}
      			}
      			if (tmpRichter > 5) {
      				if (tmpDestroy <= 50) {
      					DestroyBuilding(tmpCity, tmpDestroy);
      				}
      				if (tmpRichter == 8) {
      					DestroyBuilding(tmpCity, BuildingDB(IMPROVE_CITY_WALLS));
      				}
      			}
      			if (tmpCity.owner == 1) {
      				value[0] = tmpRichter;
      				city[0] = tmpCity;
      				location[0] = disasterLoc;
      				Message(1, 'EQCityHit');
      			}
      		} else {
      			Event:CutImprovements(disasterLoc);
      			tmpnumberUnits = UnitsInCell(disasterLoc);
      				if (tmpnumberUnits > 0) {
      					QuakeDamage (disasterLoc, tmpnumberUnits, tmpRichter);
      				}
      			for (i = 0; i < tmpRichter; i = i + 1) {  	
      				GetRandomNeighbor(disasterLoc, disasterLoc2);
      				Event:CutImprovements(disasterLoc2);
      				tmpnumberUnits = UnitsInCell(disasterLoc2);
      				if (tmpnumberUnits > 0) {
      					QuakeDamage (disasterLoc2, tmpnumberUnits, tmpRichter);
      				}
      			}
      			if (CellOwner(disasterLoc) == 1) {
      				value[0] = tmpRichter;
      				location[0] = disasterLoc;
      				Message(1, 'EQNoCityHit');
      			}
      		}
      	}
      }
      
      Messagebox 'EQCityHit' {
      	Show();
      	Text(ID_EQ_CITY_HIT);
      	EyePoint(location[0]);
      }
      
      // in textfiles: EQ_CITY_HIT	"Sire, a horrible thing has happened! An earthquake of size {value[0]} on the scale 
      // of Richter struck in the center of the  city of {city[0].name}. People are hiding or fleeing in panic 
      // and the damage is enormous!"
      
      Messagebox 'EQNoCityHit' {
      	Show();
      	Text(ID_EQ_NO_CITY_HIT);
      	EyePoint(location[0]);
      }
      
      Messagebox 'EQTest' {
      	Show();
      	Text(ID_TEST_EQ);
      }
      
      // in textfiles: EQ_NO_CITY_HIT	"Sire, a report just came in. An earthquake of size {value[0]} on the scale 
      // of Richter struck our empire. Luckily no large cities were at the epicenter, so damage is limited."
      [This message has been edited by Locutus (edited January 08, 2001).]
      [This message has been edited by Locutus (edited January 08, 2001).]
      Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

      Comment


      • #63
        Thats right player[0]! I did figure that out after looking inn the ND Slic!

        Now I have yet another problem. It doesn't seem to read any of the code in thee 'If's' after the message, because no buildings get created. This is what should work
        Code:
        if (DisasterType == 1)
        	{
        		Message (g.player, 'DroughtBegin'); //doesn't read after here
        		for(m = 0; m <= player[0].cities; m = m + 1)		
        		{
        			Event:CreateBuilding(city[0], BuildingDB(IMPROVE_DROUGHT));
        		} 
        isDrought = 3;  //Three turns of drought
        
        	}
        I'm sure it doesnt read after the message because isDrought never gets set to 3, because it never goes back to zero witht the code up the top


        Uggh!
        [This message has been edited by heardie (edited January 08, 2001).]

        Comment


        • #64
          Thanks for all the help. I hadnt realized at first that it was 2 files. I tried leave it all as one and took out the reference to eq_func, but it didnt like that so I'll try 2 files tonight. I think we have enough of a start to be able to work it all out including the randomized location. I was reading the SLIC doc last night so now I'm an expert And tomorrow I will win the lottery....LOL

          I'm going to try to swipe the "general" code from the shipped scenarios and see if i can get that too work too.

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

          Comment


          • #65
            Here's a break from posting code to posting an article on disasters. Science is only beginning to realize that, in recorded history, the earth has been hit by some natural disasters that make an ordinary earthquake or volcano small potatoes in comparison. Below is an article about one such disaster. I've looked into this alot, and the prime culprit generally seems to be comets, which in turn can trigger large earthquakes or volcanoes. The article below doesn't mention it, but odds are good based on other evidence that the volcanic explosion mentioned below was triggered by a comet.

            So I think having the occasional mega disaster that effects the whole world some and one part of it alot would be a good thing to have in the game. I'll try to dig up more info on mega-disasters, if people are interested. I highly recommend reading the book Catastophe mentioned below, btw. Lots of eyewitness accounts and records from just about every culture on major natural upheaval in the 500s AD, yet history books have completely overlooked this and other such episodes so far. Only in the past few years with greater advancement in the study of tree rings and ice core samples, plus the hitting of Jupiter by a large comet, has science found these ideas acceptable and really gotten into researching them. Before Shoemaker-Levy hitting Jupiter, the common wisdom was that it was impossible for a comet to hit a planet, even though there can be no other explanation for the large impact in Siberia in 1908. Its literally just in the last year or two that a flood of books and reseach has been finished on this, with Catastophe being one example, so we're all still learning a lot about history.


            The Dark Ages May Have Really Been Dimmer

            LOS ALAMOS, N.M., Dec. 17, 2000 -- The beginning of the Dark Ages may have been literal, as well as figurative, as the result of a massive volcanic eruption in the 6th century, according to a volcanologist at the Department of Energy's Los Alamos National Laboratory.

            Ken Wohletz said an eruption in the Indonesian archipelago could have produced a 150-meter-thick cloud layer over the entire Earth, triggering a chain of climatic, agricultural, political and social changes that ushered in the Dark Ages.

            Evidence supporting the catastrophe includes tree-ring and ice-core measurements, indications of a huge underwater caldera, and ash and pumice in the same area, said Wohletz, who discusses his work modeling such an eruption today (Dec. 17) at the fall meeting of the American Geophysical Union.

            The 6th century was a turbulent, unsettling period in human history. The Roman Empire began to fall; nomads of central Asia migrated to Europe and the Near East; civilizations in Persia, Indonesia and South America collapsed; major religions experienced considerable change as natural events were viewed as omens.

            Many of these social transformations resulted from widespread crop failures and the explosion of plague around the globe, which in turn were caused by major climatic changes, Wohletz said. Beginning in about the year 535, according to historical and archeological records, the weather was colder and drier, sunlight diminished, snow fell in summer and regions of persistent drought suffered floods.

            Wohletz was a resource for a book postulating that the climate changes resulted from a huge volcanic eruption. The book, "Catastrophe: A Quest for the Origins of the Modern World" by David Keys, was published earlier this year.

            Wohletz said he worked with Keys to try to identify a volcano that could produce such dramatic climate change. "We came up with an eruption that would certainly be the largest in recorded history, some four or five times bigger than the (1815) eruption of Tambora, which is usually considered the biggest eruption in the past few millennia," he said.

            Such an explosion, he said, would eject some 200 cubic kilometers of material, and one-third to one-half of it would be lofted into the stratosphere, where it would remain suspended for months to years while being carried around the globe.

            "It would have produced enough dust and water vapor (in the form of ice crystals) to form a cloud layer 150 meters thick over the entire globe, and that's a conservative estimate," he said, adding that a cloud of particles that thick may have diminished the transmission of sunlight by as much as 50 percent.

            Wohletz said tree-ring data collected around the world and ice-core measurements in Greenland and Antarctica support the possibility of a huge eruption in the 6th century. Ocean depth measurements between Sumatra and Java ­ where Krakatoa exploded in a well known 1883 eruption ­ indicate the presence of a caldera up to 50 kilometers in diameter, and a recent survey uncovered evidence of ash and pumice layers formed in the area during the appropriate time frame.

            Under a likely scenario, a large volcano, which Wohletz calls proto-Krakatoa, connected the islands of Sumatra and Java. When it erupted and then subsided, it created the Sundra Strait and left a ring of smaller volcanoes, including the present day Krakatoa. The ash, dust and water vapor blown into the stratosphere would disperse across both the Northern and Southern Hemispheres.

            "This volcano would have had the potential to be a major player in destabilizing the climate around the world," he said. "An eruption that could produce a caldera 50 kilometers across would have been big enough."

            Although definitive evidence for such a catastrophic eruption has not been discovered, the possibility deserves a full-scale field study, Wohletz said, in part because of the potential impact on the world if another such catastrophe happens.

            "(Key's book) is the first detailed account of how closely humanity is linked to the natural world," he said. "If the natural world goes through some large upheaval, we'll all be affected."


            Comment


            • #66
              Heardie,
              Well, that's because you have a variable m, you make it zero, you create a building in city[0] (let's say city[0] happens to be Rome at that point), then you make m one, then you create another building in Rome, then you make m two, make another building in Rome, etc. You create all the buildings in the same city. city[0] is not much different from a regular variable, it stores a values and stays the same until you manually change it. The only catch is that these built-in variables might change if a certain event happens (or another eventhandler executed at the same time changes it), but you can't control those events. The events you invoke from within an EventHandler or function are put in a queue and executed one at a time at CtP2's leasure, outside your control. So unless an event happens to occur just as you cycle through your cities, city[0] will remain the same throughout the eventhandler or function your code is in (unless you manually change it of course).

              You must insert the line "GetCityByIndex(player[0], m, tmpCity);" between the for line and the CreateBuilding line and declare tmpCity higher up in the code and use it instead of city[0] in CreateBuilding (so that tmpCity actually cycles through all cities). Maybe you can use city[0] directly as well but whenever possible it's safer to use a user-defined variable like tmpCity so if another event happens that changes the value of city[0], you're screwed - I'm not sure if it's possible for this to happen in CtPII but it was in CtPI and I for one think it's better to be safe than sorry.

              Harlan/wheatin,
              Yeah, I'm aware of such stories, it would indeed be cool to implement, though I'll leave the details on how to do that to others, unless my help is needed for the 'technical' part of course.
              Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

              Comment


              • #67
                Locutus,

                I cut and pasted your last code in and got a delightful crash that required a reboot in order to load the game again. I broke it down to test if it was the Random() causing a crash by making my own slic file with just parts of the code posted. I was able to Random() any number I chose and display it in a message box without any crashes or errors. I included further pieces of your code and encountered a slic error (I have debugslic=yes in my profile.txt) in "object testingthis function_GetCityByLocation. Wrong type of arguement." I could close the little warning window and go back to playing though. It didn't crash the game. Anyways, from what I have seen Random() isn't causing problems.

                *Edit*

                Ignore the wrong type of arguement thing, I used int_t instead of city_t. Stupid me.

                *Edit again*
                Through trial and error (and a number of reboots) I found the troublesome part that was causing it to crash:
                Event:CutImprovements(disasterLoc);
                Commenting them out kept the game from crashing. Maybe we have to check if there are improvments there to pilliage first. If that doesn't work I guess we can terraform it to the same terrain type. (I think that would kill the improvements)

                [This message has been edited by Jerk (edited January 11, 2001).]
                [This message has been edited by Jerk (edited January 11, 2001).]

                Comment


                • #68
                  Yeah,
                  The Black Sea flood is another stunning example that's just been discovered. Pretty astounding, the few things they've come across so far as they start to explore. The Black Sea is a complete biological dead zone once you get below about 100 meters, so they've already found a ship from BC times looking basically like it did when it went down, even with the mast still standing! So far they've only come across one house from pre-flood times, but if they do find whole towns, it could be some of the most astounding discoveries of all time. The theory is the flood came slowly, about a mile a day. Fast enough so that everyone had to flee, but slow enough so that the buildings would all still be standing.

                  Still, that was such a wierd disaster its hard to see how it could be implemented in the game. Its a good example though of how the catastophists are getting the upper hand over the gradualists (those who think that large natural disasters almost never happen) through new revelations.

                  A reason why the gradualists have had the upper hand is because apparently the last 1500+ years have been unusually quiet. But that's just luck: an analysis of the ice cores shows there's a big comet hit about once every 1000 years. If the comet (or pieces of it, sometimes it breaks up entering the atmosphere) hits water, the effects are very different than if it hits land. Meteor hits are apparently much less common, but that did take care of the dinosaurs.

                  One implementation issue I don't know if you've all addressed. In the game the years per turn is always different from one age to the next. But natural disaster occurances shoudn't speed up like technological advancement does. So the odds of a disaster occurring if there's 1 turn per 10 years should be ten times as great as if there's 1 turn per 1 year.

                  Comment


                  • #69
                    Good point about the time frame. But the difference in turn length (from one to 20?) means that a disaster that might occur three or four times before 1500 (5500 years) might never occur in the rest of the game (800 years).


                    Note that minor disasters have been *very* regular, if only because of El Nino. Two years ago there was a book about all the El Ninos, and their effects on history, including some of the worst famines and floods in history, as well as other "unexplained" events, such as the destruction of the first colony in Virginia at Roanoke (a spectacularly severe winter they were unprepared for).

                    Comment


                    • #70
                      You're right Wheathin, but that's okay. Once turns start coming 1 year per turn, things get pretty hot and heavy in other areas so I doubt people would mind not getting whacked by disasters as often. Anyways, if you do have an average of 1 major disaster per 1000 years, the odds are good it will happen in the last 800 years of play, and it would be a real doozie if it hit a fully populated and developed planet.

                      I think El Nino is too minor of an effect to include in the game though. Cities get 3 year starvation protection as default, and El Ninos rarely last that long. But a prolonged drought would be really interesting to play through. I wonder if SLIC can handle it well though, since Wouter says its weak in the food dept.

                      Comment


                      • #71
                        Similarly, there is a lot of interesting research over the last three years or so about the "Great Flood." The flood of Noah is repeated in hundreds of other cultural myths from southern europe and the middle east, but only recently have scientists identified it: the massive expansion of the Black Sea about 7,000-9,000 years ago.

                        The Black Sea had been a small lake in a large depression, but the Bosporous was closed off by a large natural dam - part of the mountains in the area. Eventually, the dam broke and flooded the basin. The lake, now a sea, rose hundreds of feet, covering what had been hills, marshes, and plains that supported small early human communities. Those communities fled into Southern Europe, the Causasus, and Anatolia, taking with them an oral history of the flood, which was steadily incorporated into their origin myths and creation stories.

                        Linguists and Anthropologists first identified the possibility based on the prevalence of flood myths. Recent examinations of the floor of the black sea have revealed the outlines of structures and tools on the sea bed - encampments or villages.

                        Comment


                        • #72
                          Thanks again Locutus, but I am still having prollems

                          *heardie sighs and bangs head against table again!*

                          I did wait you said and go tthis error

                          In object EveryTurn, function _GetCityByIndex: Value out of bounds

                          What does it mean?

                          Comment


                          • #73
                            Okay figureed that out, just remove the '=' from the for loops. Now i problem that i cant work out because it is not flagged as an error. When the drought building is built isdrought is set to three. then each turn it is decremented by 1 and then when it gets to zero the drought building is removed yet this doesnt work!

                            Have a look at the code. Can you tell me why not?

                            Comment


                            • #74
                              Guess I should have looked at the code more closely earlier, I could have picked out most of the bugs fairly quickly if I wanted to. This is the perfect example of why some people are against using a lot of comments in code, it make you loose the overview of the actual logic. I don't agree with these people, but this *is* a classic. Here's part of the code with the comments removed:

                              Code:
                              	isDrought = -1;
                              	if (isDrought > 0) {
                              		isDrought = isDrought - 1;
                              	}
                              You see? isDrought is always -1! You should make it a global variable instead of local (move the declaration out of the eventhandler and place it at the very top of the file, right above '#include msg.slc') and initialize it to -1 (or 0, doesn't really matter here) in a seperate eventhandler that only gets executed once (FirstTurn will do the trick). Now the code *should* work, or at least I can't spot any other obvious bugs in the drought part of the code (the isWeather part has similar bugs but I guess you can figure those out yourself now).
                              [This message has been edited by Locutus (edited January 13, 2001).]
                              Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                              Comment


                              • #75
                                hmmm, I am a fool. It's always the simpilest errors that get you. It's the same with c++, they're a ***** to track down and when you see them, it is so obviouos.

                                Thanks a ton Locutus

                                What would have been really cool was a debug window in the game where you cacn track variable values
                                [This message has been edited by heardie (edited January 14, 2001).]

                                Comment

                                Working...
                                X