RTS Problems

Non-platform specific questions.

RTS Problems

Postby png1045 » Tue May 06, 2008 2:14 pm

Hi! I am new to GE so this is one of my first pojects. I am making a RTS game in wich I have , at the begining, a worker that can build various buildings from wich I can train more workers and an army. Things I want to do in this game and need your help:
1. Enemies. I would like to add an enemy base, wich can train the enemy army and build some buildings, but this base to be built like in Warcraft,Cossacks etc.(at the begining some workers that will build the base step-by-step)
2. Enemy AI and attacks. For example, if the enemy troops are enough, they will come and attack me and I will try to defend. If I attack them, they will also try to defend.
3. Unit Levels. Another example. Let's say I have an unit with 30 Attack Points, 30 Defence Points and a total of 60 Points. An enemy unit with 20 Attack Points, 20 Defence Points and a total of 40 Points will come and attack my unit. Obviously, my unit will destroy the enemy unit.
4. Save Game.
5. World Map. I would like to know if I can have a world map in wich some blue dots will be my units and buildings and some red dots will be the enemy units and buildings.

I think this is hard, but hopefuly someone will know :D
png1045
 
Posts: 11
Joined: Mon Mar 24, 2008 1:31 pm
Score: 0 Give a positive score

Re: RTS Problems

Postby DST » Tue May 06, 2008 8:16 pm

actually, this isn't that hard. I will explain these things in general, the syntax and exact code will be up to you. (but you can still ask for help)

1. making a base or building works like this:
Clicking the (completed) base will bring a menu panel for that base either to the top (zdepth) of a stack of menus, or from offscreen to onscreen (at speed 999 it appears instantly).
Clicking a 'make unit' button in that menu can start a timer, which when finishes, the unit is created. (you can use for/while loops to do that for upgraded unit production, but a timer will work while you figure out the basics of your game structure).
When you create a foundation, and send workers to build it, the workers could start timer (build) and every time it hits, they add lets say 10 points to the building (per worker). The building's animpos could equal (points/100) so for every 100 pts added to building, its animation increases one frame, and so on until the building is finished.
2. You can have a repeating timer (try 60 seconds). Every 60 seconds, the enemy checks how many attack points it has, and if its over a certain number, or more than yours, it sends players to attack.
For the enemy to defend, you create a wireframe region around its territories. If any of your players touch that wireframe actor, the enemy sends troops to defend.
3. Each unit will have a set of variables. Hp, Attack, Damage, Defend etc. When an enemy and a unit are in battle, each has an attack timer or event. (collide.hp-=damage;) etc. etc. Simple math will make the stronger unit win, but all units still get hurt when they fight.
4. saveVars("game.sav", "High Score"); and loadVars("game.sav", "High Score");
you can save and load all the variables you wish. saving cloned actors can be a bit more difficult....my bro and i are working on a method for that as I type.
5. The simplest way (its not all that simple) to make a world map (i assume like AOM where its always displayed in the corner of the screen) is to build an array; the playfield as a whole is divided into pieces and unit/buildings identify their position in the array; then that array is used to define the locations of the red and blue dots on the map. It sounds difficult but once you get the hang of arrays you will love them! Save this part for last, perhaps?
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: RTS Problems

Postby png1045 » Fri May 09, 2008 8:52 am

thanx, that definitely helped me. but still, i have some problems :oops: :
1.I don't know how to make the enemy units come to attack me :oops: I thought about something like this(but I'm not sure)
Code: Select all
if(AttackPoints>100){
MoveTo("Event Actor",blabla"worker", "");}

2.
1. making a base or building works like this:
Clicking the (completed) base will bring a menu panel for that base either to the top (zdepth) of a stack of menus, or from offscreen to onscreen (at speed 999 it appears instantly).
Clicking a 'make unit' button in that menu can start a timer, which when finishes, the unit is created. (you can use for/while loops to do that for upgraded unit production, but a timer will work while you figure out the basics of your game structure).
When you create a foundation, and send workers to build it, the workers could start timer (build) and every time it hits, they add lets say 10 points to the building (per worker). The building's animpos could equal (points/100) so for every 100 pts added to building, its animation increases one frame, and so on until the building is finished.
This is better that what I've did, but I wanted to know how to make the enemy build his own base.
3.I want to know how to make my units attack the enemy units if I right-click them. :oops: :oops: :oops:
4. :? I don't know how to do that array things...can you send me an example? And what means Animpos?

Thank you for understanding that I am a beginer and helping me :D
png1045
 
Posts: 11
Joined: Mon Mar 24, 2008 1:31 pm
Score: 0 Give a positive score

Re: RTS Problems

Postby DST » Sat May 10, 2008 12:55 am

There is a lot of complex things that go into making an rts game; its not so much about how to program it as it is understanding exactly what you want to happen; Age of Mythology is setup basically like Age of Empires but it's also much different. There are 10 million things to consider when making an rts.

Before you read thru this nightmare of a post, keep in mind three things;
1. Rome wasn't built in a day. It takes time to learn all these things;
2. We are here to help. You can always ask more questions, and if no one can answer them, work on it for a couple weeks and ask again; we're all learning new things every day! Maybe you'll figure it out and end up telling US!
3. If this seems complex, just take a look at the ending credits for a game like AOE or AOM. Look at how many people it took to make those games!

Now, for the enemy building his own buildings: he's gonna do it basically the same way you're gonna do it.
The only things you have to decide for him are: when to build a building, that is, which order does it build them in?
Obviously a granary comes first; and then other economic buildings, then a barracks and temple; then an armory; right?
and secondly, how many ppl will he devote to building?

You do this with ActorCount;
First i would make a variable that tells the cpu what the current building needed is;
and a case switch based off that; you'll use actor count to tell the enemy which buildings he already has;
Code: Select all
switch (buildingtype){
case 0://make granary
break;
case 1://make wood shed
break;
case 2://make gold mine
break;
case 3: //make barracks
break;
}


So the enemy has a timer like this;
Code: Select all
if (ActorCount("granary")> 1){buildingtype+=1;}

the building type will never make it to 1 until he's got at least one granary.
Does that make sense?

You can then use ActorCount to tell him how many ppl to devote to the building;
For instance, you could tell him to devote 1/4 of his workforce to building. Just count the number of peasants and divide by four. Instructing the individual peasants can be a lot harder; you can use cloneindex to tell it which peasants to send.
I'll tell you more on that after i do some testing.

Attacking the enemy based on a right click...well once again, that won't be too much different than telling the enemy to attack you; Some variable is checked (like attackpoints) and a decision is made to attack; however you don't want too much code in the individual units;
Basically you'll use the same code for each of them; their different animations will make them look like they are doing different things; so all infantry/cavalry will be one type of unit, with one type of script;
all archers/catapults will be another type of unit, with a different type of script.
And there will be a single enemy actor, the 'brain' which does all the actorcounts, comparisons, timers that decide what the enemy should be doing. All the individual units need to do is move to enemies, and attack them.

This being said, the difficulty lies not in making a unit do something; but making him do as LITTLE as possible!
So i could tell you A way to do it but its not the best way, and all i'll be doing is starting you down the wrong path.
Since i've never made an RTS myself, I am exploring methods as i tell you these things.

But here are the basic variables a unit needs to attack;
A target and
a movement to the target;
A simple collision takes care of the attack itself.

YOu can use 'moveto' but you could also use angle/directional velocity;
Code: Select all
angle = direction(x, y, targetx, targety);
directional velocity=whatever this unit's speed is;

you can then designate an animation change based of which direction the unit is facing;
Code: Select all
animationnumber=angle/90;

This would give him 4 possible animations (360/90=4); animationnumber is a variable i made up; for complex animations, you'd have a case switch to tell him which animation corresponds with which animationnumber.
since his angle will always be toward the target, this takes care of animation when walking; Of course there will be an animation change when he collides with the enemy...his attack animation. And of course this is only for infantry...archers will change animation upon being with a certain DISTANCE of a target rather than colliding with them.....More on this later.

animpos designates which frame of the animation is currently being shown; in order to use it, you first have to stop the current animation;
Building>createactor>
Code: Select all
ChangeAnimationDirection("Event Actor", STOPPED);
animpos=0;//that's the basic animation frame before workers have done anything to it;


Then create a timer for that building (lets say 5 sec, repeat);
ON timer 5 sec:
Code: Select all
animpos=pts/250;//now for every 250pts added to the structure the animpos will increase by one


We do this on a timer to save cpu; 'draw actor' events check every frame (30-60 times per second!) which is a waste of cpu for a building that only changes animation 4 times in 30 seconds or a minute (depends on how many workers are on it).

Here is a ged file that shows the basics of the array; If you look in script>global code you will see the line of code that created the array ('choose' on the lower left hand side of the global script editor).

Now the blocks were part of another experiment, but the important thing is to drag pacman around; you will see his 'cell' number change; that shows the screen is divided into a grid and fed into the array; You can put pacman over the moving block and notice that they will then be in the same array cell!

You can look inside pacman's script to see how i told pacman to tell the array which cell he was in.

Then the simple thing to do on the map screen is to have pacman, on his creation, create a dot on the map; and the dot will translate pacman's value into the map value; It may seem complex, But it will make more sense once you feel comfortable with arrays. A side note on arrays.....every time you create anything its stored in an array. Arrays are used everyday in every single program you've ever used!
Attachments
arraytest.zip
(199.92 KiB) Downloaded 113 times
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: RTS Problems

Postby png1045 » Sat May 10, 2008 3:22 pm

sorry for wasting your time and thanks for helping!
png1045
 
Posts: 11
Joined: Mon Mar 24, 2008 1:31 pm
Score: 0 Give a positive score

Re: RTS Problems

Postby DST » Sat May 10, 2008 6:37 pm

wasting who's time?
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: RTS Problems

Postby png1045 » Sun May 11, 2008 6:10 pm

well, I thought that you have better things to do...and thanx again :D
png1045
 
Posts: 11
Joined: Mon Mar 24, 2008 1:31 pm
Score: 0 Give a positive score

Re: RTS Problems

Postby DST » Sun May 11, 2008 6:21 pm

There is nothing better to do than make games with GE!!!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron