Announcement

Collapse
No announcement yet.

Spawning units possible?

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

  • Spawning units possible?

    ..on a related issue to scenario I am working on...

    I was wondering if it would be possible..say..to spawn a free tank in each city...

    Would I need a trigger of some sort...SLIC induced perhaps??

    Let me know..thought it would be neat...say your in the middle of a heated battle and got say 50 tanks because you had 50 cities!!

    or... all your ai civs came up with 40 + tanks then you have that to contend with!!

    Me be thinking outloud and outta da box!!

    Peace

    Grandpa "Posting-whilst-EYE-B-Thinking" Troll
    Attached Files
    Hi, I'm RAH and I'm a Benaholic.-rah

  • #2
    Spawning units is one of the easiest things to do in SLIC -- one example is the Settlers code I linked to a few days ago. What should trigger the spawn?
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

    Comment


    • #3
      Originally posted by Locutus
      Spawning units is one of the easiest things to do in SLIC -- one example is the Settlers code I linked to a few days ago. What should trigger the spawn?
      Great!

      I was hoping that say once a civilization discovered say Mass Production every city built gets a free marine.

      Then again on Tanks same deal.

      I see where you had it for the beginning, would it be hard to simply spawn a unit in each city once the tech is discovered?

      In regards to the other post on spawing additional settlers...say each city you have built when you hit year 50 BC every city spawns a settler...
      Then maybe again in turn 1000 AD


      Question:

      I dont remember, does the computer track "turns"...like I allways start Renaissance in MP games, most of the time. That is turn 75.

      I was wondering if a trigger say..when you hit turn 75 each city gets a settler then again in say turn 150.

      Thanks for the response...


      I have my Uncle below in case I (WE) accidently create bugs..
      Grandpa Troll
      Attached Files
      Hi, I'm RAH and I'm a Benaholic.-rah

      Comment


      • #4
        Okay, I made example for the case of Tanks: as soon as Tank Warfare is discovered, you get a free Tank in every city (note that this code is untested but based on the Militia code for the MedMod, so it should work).

        Note that you have to use the index for advances, you can't call them by name in CtP1 as you can do with units. The index is simply its location in advance.txt: ADVANCE_AGRICULTURE is 0, ADVANCE_TOOLMAKING is 1, etc (in the original game).

        Code:
        trigger 'SpawnTank' when (player.1 && discovery.type == 55) { 	// 55 = tank warfare
        	i = 0;
        	while (i < player.1.cities) {	// loop through all cities
        		SetCityByIndex(1, player.1, i);
        		CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0);	// create a tank
        		i = i + 1;
        	}
        }
        Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

        Comment


        • #5
          Thanks..I been working some 16 hour days..hopefully can try out tommorrow!
          Ill post back!

          'Preciate it!
          Attached Files
          Hi, I'm RAH and I'm a Benaholic.-rah

          Comment


          • #6
            Originally posted by Locutus
            Okay, I made example for the case of Tanks: as soon as Tank Warfare is discovered, you get a free Tank in every city (note that this code is untested but based on the Militia code for the MedMod, so it should work).

            Note that you have to use the index for advances, you can't call them by name in CtP1 as you can do with units. The index is simply its location in advance.txt: ADVANCE_AGRICULTURE is 0, ADVANCE_TOOLMAKING is 1, etc (in the original game).

            Code:
            trigger 'SpawnTank' when (player.1 && discovery.type == 55) { 	// 55 = tank warfare
            	i = 0;
            	while (i < player.1.cities) {	// loop through all cities
            		SetCityByIndex(1, player.1, i);
            		CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0);	// create a tank
            		i = i + 1;
            	}
            }
            Worked like a charm...

            I have the years per turn slowed down so that I have plenty of years of growth and Battle with the latest technology...

            I discovered Tanks at turn 52 and each of my cities got a free tank!

            Works great!

            I will continue to work with the model SLIC you wrote to work on my scenario!

            Now..to resolve the settler-spawn issue...

            Peace

            Grandpa "Voting-Locutus-4-Prez"Troll
            Attached Files
            Hi, I'm RAH and I'm a Benaholic.-rah

            Comment


            • #7
              Originally posted by Locutus
              Okay, I made example for the case of Tanks: as soon as Tank Warfare is discovered, you get a free Tank in every city (note that this code is untested but based on the Militia code for the MedMod, so it should work).

              Note that you have to use the index for advances, you can't call them by name in CtP1 as you can do with units. The index is simply its location in advance.txt: ADVANCE_AGRICULTURE is 0, ADVANCE_TOOLMAKING is 1, etc (in the original game).

              Code:
              trigger 'SpawnTank' when (player.1 && discovery.type == 55) { 	// 55 = tank warfare
              	i = 0;
              	while (i < player.1.cities) {	// loop through all cities
              		SetCityByIndex(1, player.1, i);
              		CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0);	// create a tank
              		i = i + 1;
              	}
              }
              Question Oh Great Locutus

              Say I decide upon something like a Blitzkreig (a.k.a. Lightning War) type scenario..where I would say create maybe 4 tanks per city or whatever the number may be..

              What number in the above code would I change?

              I was thinking it was i=i + 1;..change the "1" to a "2" to read the following i=i + 2

              Would this be correct?

              I am trying to teach myself this and would greatly appreciate any assistance...


              I forget..maybe it was Big Dave..years ago..or maybe JByethway..at any rate....

              they responded in a post...something like this:

              EDIT:

              TEST:

              EDIT:

              TEST:

              and it dawned on me..DUH!...try and if it works..great if not dont..

              Point in case..I had my PW trigger..set at 60 pw per citizen..seems great but very quickly you have far to much pw......

              I backed down to 16 per citizen and maybe..will back that down..soon..

              I have a hamster wheel spinning around in me head..I am just trying N tweaking to make some enjoyable scenarios...



              HEY BLACKICE!!!!!! GUESS WHAT..I CAN PLAY SCENARIOS THE WAY I WANT SO AS NO ONE IS EXPOSED TO MY EXCLUDED UNITS!!!

              Whoa...This makes me sooooo happy!!


              Peace

              Grandpa Troll
              Attached Files
              Hi, I'm RAH and I'm a Benaholic.-rah

              Comment


              • #8
                Originally posted by Grandpa Troll
                Say I decide upon something like a Blitzkreig (a.k.a. Lightning War) type scenario..where I would say create maybe 4 tanks per city or whatever the number may be..

                What number in the above code would I change?

                I was thinking it was i=i + 1;..change the "1" to a "2" to read the following i=i + 2

                Would this be correct?
                Nope, doing that would make it create a tank in every other city, rather than in every city. The simplest way to do what you want is to duplicate the CreateUnit(...) line, if there are two of them it will make two units. A slightly more elegant way would be something like this:

                Code:
                trigger 'SpawnTank' when (player.1 && discovery.type == 55) { 	// 55 = tank warfare
                	i = 0;
                	while (i < player.1.cities) {	// loop through all cities
                		SetCityByIndex(1, player.1, i);
                		j=0;
                		while (j < 4) {
                			CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0);	// create a tank
                			j = j + 1;
                		}
                		i = i + 1;
                	}
                }
                Which should create 4 tanks in each city. The number 4 there is the one you want to change. This creates the tanks and at the same time counts with j from 0 to 3 (as I said, we tend to count from 0 here...), creating a tank at each value of j, and thus producing 4 tanks.

                (Usual disclaimers apply: untested, etc.)

                Comment


                • #9
                  I just tried the repeating the create unit line and it works like a champ!

                  Another question...

                  Lets say I wanted to have an ocean game..and had a trigger to add sol's and later battleships...

                  I am taking it that only ocean or lake front tiles would create them..

                  My concern is a game crashing if the loop was for all cities but not all cities could produce them?

                  Thanks

                  GT
                  Attached Files
                  Hi, I'm RAH and I'm a Benaholic.-rah

                  Comment


                  • #10
                    I think there might be a function that checks whether a city is coastal or not - have a look at the function reference and see if you can spot anything useful.

                    In fact, though, I think you won't have any problems - if the game cannot create the unit it will probably simply carry on without crashing. A more likely problem is that you'll end up with landlocked ships.

                    Anyway, give it a try and see what happens - experimentation is the best way to learn .

                    Comment


                    • #11
                      ..I will thanks

                      Problem now......

                      I went and tried then above mentioned idea of copying the create unit for a unit

                      I got 4 marines in some cities no marines in other cities

                      repeat for tanks..the exact cities that got the 4 marines got 4 tanks

                      I did fortify the marines outside of city so as to make room for the tanks

                      I have 51 cities...

                      I got 52 marines

                      then 52 tanks

                      Any reason you can think of?
                      I am going to copy the triggers..maybe you can see where I failed...

                      trigger 'SpawnTank' when (player.1 && discovery.type == 55) { // 55 = tank warfare
                      i = 0;
                      while (i < player.1.cities) { // loop through all cities
                      SetCityByIndex(1, player.1, i);
                      CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0); // create a tank
                      i = i + 1;
                      CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0); // create a tank
                      i = i + 1;
                      CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0); // create a tank
                      i = i + 1;
                      CreateUnit(player.1, UnitType("UNIT_TANK"), city.location, 0); // create a tank
                      i = i + 1;
                      }
                      }
                      trigger 'SpawnMarines' when (player.1 && discovery.type == 59) { // 59 = Mass Production
                      i = 0;
                      while (i < player.1.cities) { // loop through all cities
                      SetCityByIndex(1, player.1, i);
                      CreateUnit(player.1, UnitType("UNIT_MARINES"), city.location, 0); // create a marine
                      i = i + 1;
                      CreateUnit(player.1, UnitType("UNIT_MARINES"), city.location, 0); // create a marine
                      i = i + 1;
                      CreateUnit(player.1, UnitType("UNIT_MARINES"), city.location, 0); // create a marine
                      i = i + 1;
                      CreateUnit(player.1, UnitType("UNIT_MARINES"), city.location, 0); // create a marine
                      i = i + 1;
                      }
                      }

                      Thanks

                      GT
                      Attached Files
                      Hi, I'm RAH and I'm a Benaholic.-rah

                      Comment


                      • #12
                        Originally posted by J Bytheway
                        I think there might be a function that checks whether a city is coastal or not - have a look at the function reference and see if you can spot anything useful.

                        In fact, though, I think you won't have any problems - if the game cannot create the unit it will probably simply carry on without crashing. A more likely problem is that you'll end up with landlocked ships.

                        Anyway, give it a try and see what happens - experimentation is the best way to learn .
                        Actually, I do love finding a city with a tile or two of water.then i often create a 9 stack of Battleships..

                        this way, in effect, you have a possibility of 18 units...

                        awesome bombardment capabilities, plus if your city gets attacked you now have 9 to replace units with....


                        OR

                        U can take that 9 stack and use them to help build an improvement by disbanding them within the city...to help "rush-buy" something like an oil refinery or drug store....


                        Peace

                        GT
                        Attached Files
                        Hi, I'm RAH and I'm a Benaholic.-rah

                        Comment


                        • #13
                          ..just studying the code..was I supposed to copy the whole text..and then it makes a unit in each city?

                          As in maybe 2 + duplicates of "all" the trigger..

                          or as asked above..simply the line "creat unit....."??

                          Thanks..just grabbing some..well...
                          Attached Files
                          Hi, I'm RAH and I'm a Benaholic.-rah

                          Comment


                          • #14
                            You shouldn't copy the i = i + 1 lines - that's making it skip some of your cities. Just copy the CreateUnit lines.

                            Comment


                            • #15
                              Originally posted by J Bytheway
                              You shouldn't copy the i = i + 1 lines - that's making it skip some of your cities. Just copy the CreateUnit lines.
                              thx a bunch!

                              GT
                              Attached Files
                              Hi, I'm RAH and I'm a Benaholic.-rah

                              Comment

                              Working...
                              X