Week 2
Game Options - Morale Makes The World Go 'Round
Before we try making more units, let's make those game options do stuff, okay?
Morale
There are a few ways to change morale settings.
TethysGame::FreeMoraleLevel(player); // Set morale to unsteady
TethysGame::ForceMoraleGreat(player); // Set morale to Excellent (99)
TethysGame::ForceMoraleGood(player); // Set morale to Good (75)
TethysGame::ForceMoraleOK(player); // Set morale to Fair (50)
TethysGame::ForceMoralePoor(player); // Set morale to Poor (25)
TethysGame::ForceMoraleRotten(player); // Set morale to Terrible (0)
Now, let's change morale settings based on whether or not the Morale Steady option was enabled
We'll start by freeing morale (in case MS is off), then check if the option was enabled, and force morale good if it was.
TethysGame::FreeMoraleLevel(-1); // -1 = all players
if (TethysGame::UsesMorale() == 0) // Check if Morale Steady is enabled
{
TethysGame::ForceMoraleGood(-1); // Set morale to 75 for all players if so
}
That wasn't too bad, was it? Two things to keep in mind:
1) If you want to set morale for individual players, rather than all of them at once, you need to do it twice.
2) You CANNOT change the morale level after the game starts or OP2 will assume you're cheating and tell you so.
We're done with morale.
Day/Night
Daylight settings are pretty much the same in that we check if a setting is enabled and act accordingly.
Here's what you'll need for adjusting daylight:
TethysGame::SetDaylightEverywhere(0 or 1); // Enables/disables permaday. 0 is off. 1 is on.
TethysGame::SetDaylightMoves(0 or 1); // Enables/disables movement of the "band" of daylight. 0 = off; 1 = on.
TethysGame::UsesDayNight(); // Use this to check if Day/Night is enabled
GameMap::SetInitialLightLevel(value); // Use this to set the starting position of the daylight "band"
So, how do we use this? Pretty much the same way we use morale.
TethysGame::SetDaylightEverywhere(0); // Assume day/night is on; disable permanoon
TethysGame::SetDaylightMoves(1); // Enable movement of the band of light
if (TethysGame::UsesDayNight() == 0) // Now check if Day/Night is enabled
{
TethysGame::SetDaylightEverywhere(1); // Enable permanoon if D/N is off
}
A really neat thing I like to do is randomly determine where the daylight strip starts everytime the mission is played.
Figure out the length of the map (if you're using La Corrida, it's 128) and do this:
GameMap::SetInitialLightLevel( TethysGame::GetRand(128) ); // Set random light level
Note: TethysGame::GetRand(value) returns a random number between 0 and (value - 1).
You would insert this line of code before that if statement above.
Initial Vehicles
We will not be covering Initial Vehicles at this time as we'll need to use a few things the tutorial hasn't covered yet. Be patient.
Disasters
We will discuss disasters when we talk about triggers. Again, be patient.
Keep in mind that you can be creative with the usage of these settings. For example, I once used the "Morale Steady" option to enable the production of combat units in a special mission!
Okay, now onto base design.
Building a Full Base: All Your Base Are Belong To Us
Okay, so you've got a couple of structures and some vehicles. That's really not enough for a base though...
Before we really get into it, here's some odds and ends you may want.
Player[#].GoEden(); Â // Forces a player to play as Eden
Player[#].GoPlymouth(); Â // Forces a player to play as Plymouth
Player[#].SetColorNumber(0 - 5); // Forces a player to play using the specified color
0 = blue
1 = red
2 = green
3 = yellow
4 = cyan
5 = magenta
6 = black (unused)
These should probably only be used in single player games or for multiplayer AIs since humans
generally pick their colony and color for a reason.
We are now going to cover:
-Creating Tubes and Walls
-Creating Mines
-Setting up Initial Resources
-Resource Settings
Let's start nice and easy. Tubes and walls are pretty simple.
TethysGame::CreateWallOrTube(X, Y, ?, type)
X/Y are the x and y position of the wall/tube (obviously). Don't forget the offsets!
? is unknown, to my knowledge. Leave it at -1.
Type is the type of wall/tube you're making.
mapTube  // Tube
mapWall  // Concrete Wall
mapLavaWall // Plymouth Lava Wall
mapMicrobeWall // Eden Microbe Wall
Of course, you don't want to have to do these things one at a time, right? Luckily, we can create lines at a time:
CreateTubeOrWallLine(xStart, yStart, xEnd, yEnd, type);
Again, this should be pretty self-explanitory. On to mines.
Mining beacons. The bane of my existence. The problem isn't that they're hard. The problem is there are so many of the darned things! Finding good locations and placing them takes forever!
Anyways, here's the code:
TethysGame::CreateBeacon(Beacon Type, x, y, Ore Type, Bar Level, Variant);
You may be confused by the presence of a "Beacon Type" and an "Ore Type" setting. Don't worry, you won't be for long.
Beacon Type: Is this a mining beacon, a magma vent, or a fumarole? Valid options are mapMiningBeacon, mapMagmaVent, and mapFumarole.
Ore Type: Sets whether the mine is common or rare ore. 0 = common, 1 = rare. -1 = random.
Bar level: Sets mine's yield. 0 = 3 bar, 1 = 2 bar, 2 = 1 bar. -1 = random.
Variant: Not all mines are the same. There are 3 variants of each type of mine. I usually just set this to random though, so each game is a bit different. 0 = low-yield variant, 1 = regular-yield variant, 2 = high-yield variant. -1 = random
IMPORTANT NOTE: For magma vents and fumaroles set ore type, bar level, and variant to -1.
For aesthetic reasons, Magma Vents should only be placed on dark gray terrain. Convention dictates that fumaroles aren't found on sandy terrain, but this isn't a rule.
Here are some examples:
TethysGame::CreateBeacon(mapMiningBeacon, 93+31, 12-1, 0, 0, -1);
TethysGame::CreateBeacon(mapMiningBeacon, 14+31, 119-1, 1, 2, -1);
TethysGame::CreateBeacon(mapFumarole, 64+31, 4-1, -1, -1, -1);
Okay, it's time to put it all to work! Go make a full base! I want it to have at least:
1 Command Center
1 Structure Factory
1 Agridome
1 Tokamak
1 Common Ore Smelter
1 Mining Beacon (Common Ore)
1 Common Ore Mine (place directly above the mining beacon. Beacon must be placed first!)
1 Robo-Miner
1 Robo-Surveyor
1 Earthworker
1 Robo-Dozer
3 Cargo Trucks
3 ConVecs
1 Guard Post
Some concrete walls
Make sure everything that needs to be is connected to the CC via tubes. Come back when you're done.
Okay, we've got ourselves a base, but it still needs something. People, food, ore, and technology, maybe?
Player[#].SetKids(amount); Â // Sets number of children
Player[#].SetWorkers(amount); Â // Sets number of workers
Player[#].SetScientists(amount); // Sets number of scientists
Player[#].SetFoodStored(amount); // Sets amount of food stored
Player[#].SetOre(amount); Â // Sets amount of common metal stored (must have storage capacity)
Player[#].SetRareOre(amount); Â // Sets amount of rare metal stored (must have storage capacity)
Player[#].MarkResearchComplete(techID); // Marks specified technology as completed
Most of that is pretty self-explanitory, though you may be wondering how you can find out what a tech's tech ID is. Open up the techtree you're using in a text editor (notepad, for example). It'll be the 5 digit number next to the tech's name. Make sure not include any leading zeroes, however (example: If a tech's ID is 01234, you would write MarkResearchComplete(1234) )!
What about resource settings or difficulty level? Just do this:
  short i;
  for (i = 0; i < TethysGame::NoPlayers(); i++)
  {
    switch (Player[i].Difficulty() )
    {
      case 0:
        Player[i].SetKids(22);
        Player[i].SetWorkers(30);
        Player[i].SetScientists(19);
        Player[i].SetOre(4500);
        Player[i].SetFoodStored(1900);
        break;
      case 1:
        Player[i].SetKids(19);
        Player[i].SetWorkers(26);
        Player[i].SetScientists(16);
        Player[i].SetOre(3000);
        Player[i].SetFoodStored(1500);
        break;
      case 2:
        Player[i].SetKids(17);
        Player[i].SetWorkers(22);
        Player[i].SetScientists(14);
        Player[i].SetOre(3000);
        Player[i].SetFoodStored(1200);
        break;
    }
}
That will iterate through all players and set their starting resources based on their Resource Setting. These are just some recommended settings. Feel free to modify the values as you see fit.
Looking good! Again, feel free to ask question and post your results. If anyone notices any errors, feel free to point them out!
Until next time, good luck!
Next week: Basic Triggers/Intro to Disasters
Player[#].GoEden(); // Forces a player to play as Eden
Player[#].GoPlymouth(); // Forces a player to play as Plymouth
Player[#].SetColorNumber(0 - 5); // Forces a player to play using the specified color
0 = blue
1 = red
2 = green
3 = yellow
4 = cyan
5 = magenta
6 = black (unused)
These should probably only be used in single player games or for multiplayer AIs since humans
generally pick their colony and color for a reason.
This is something that is really easy to do that Hidiot thought of and I use now. A random color for the player each time they start the game for single player games.
Player[#].SetColorNumber(TethysGame::GetRand(5));
That should be
Player[#].SetColorNumber(TethysGame::GetRand(6));
Otherwise you'll never get Magenta, because GetRand(x) generates a random number from 0 through (x-1).
Personally, I don't recommend this (what if you have an AI or two and all players end up with the same color? Good luck figuring out who's who!).