C++ Game Programming (Roller Coaster Tycoon)

Hello everyone!!
I am not a very experience programmer and I don’t know DirectX/OpenGl or Win32 yet, but I am willing to learn if all this is possible. I would like, though, to make a computer game similar to roller coaster tycoon (or any of the tycoons for that matter). Now before I waste many hours of my time I would like to have a few questions answered.

First, in the tycoons they usually involve people. For example, in roller coaster tycoon, you have guests that come your park and to keep them happy you must feed them and have bathrooms. So what would be the best way to store data for hundreds of “guests” all of which have several variables (hunger, thirst, name, ect.)? Don’t forget that “guests” come and go constantly. Would a class work with functions for when a guest is hungry or needs a bathroom?

Also, how would you animate the guests to run smoothly? If you figure that there will be hundreds and they are always moving, would it be efficient to move each of them one frame at a time? Is it possible to run a thread for each person?

Next, how would you store the data of your park? If your park is 100 “squares” by 100 “squares” (each square can hold one building type of thing just like in most construction games). Is there an easier way than storing the properties of each square and the type of building it holds?

What game engine do you think would be the best for this type of game?

Lastly, is there any way to open up .exe and .dat files to view the source code? This would allow me to see the source code for the game.

Thanks in advance. You don’t have to answer all the questions either. I understand that it is a lot. If anything is unclear or you have other questions fell free to ask. You don’t have to supple the source code just the concepts be hide it. Thanks again.
Last edited on
You should have good knowledge about C/C++ before thinking about Game programming. The better you know, the easier you work.
Good luck
An executable is mostly written in ASM, to read the source code, you would have to go on about a painful process of bringing it back to C++. It will really take some time.
First, in the tycoons they usually involve people. For example, in roller coaster tycoon, you have guests that come your park and to keep them happy you must feed them and have bathrooms. So what would be the best way to store data for hundreds of “guests” all of which have several variables (hunger, thirst, name, ect.)? Don’t forget that “guests” come and go constantly. Would a class work with functions for when a guest is hungry or needs a bathroom?


Classes would work perfect for this.and it's the only way i would consider doing it.just make a class with some private variables like name, hunger and happyness then some functions to read/write to them.
so in your code each time want to make a guest just call
Guest guest1(name,hunger,happyness); // add more vars to the constructor this just example

Then something like this to edit them
if(guest1.hunger >= 70 && !guest1.iseating())
{
guest1.happyness -=1;
}
you get the idea so if want to make another guest call it again Guest guest2(Vars);.if you got to make lots of guests just make a guestcounter and iterate it each time you make a guest.


Also, how would you animate the guests to run smoothly? If you figure that there will be hundreds and they are always moving, would it be efficient to move each of them one frame at a time? Is it possible to run a thread for each person?


I don't quite understand what you mean here but if you think about it how gonna have couple hundred on screen wouldn't your screen be wall to wall people.Most likely you will have less then a hundred on screen at a time,and if you did have more it would most likely mean you are zoomed out so you could set up a LOD system depending on how far you are currently zoomed out.but that's all i can say unless you clarify your question more.

Next, how would you store the data of your park? If your park is 100 “squares” by 100 “squares” (each square can hold one building type of thing just like in most construction games). Is there an easier way than storing the properties of each square and the type of building it holds?

Easier then what?My suggestion is to make a simple map format such as...

map extension = 3 bytes//Just a certain value so you know its your map type.
mapname = 27 bytes
map width = 1 byte //will give you up to 256 you said only need 100 * 100
map height = 1 byte
background sound = 1 byte//have something in your code like(if map.backgroundsound == 4 {playsound(rand.mp3)})
then for each layer have something like this
tilesinlayer = 2 byte
{
position = 3 bytes?//idk it late or early however you look at it.
type/modelid = 2 byte
.//
.//just keep going position/type till done with this layers loop.
}
So depending on how may layers you need just add more loops.

What game engine do you think would be the best for this type of game?

idk there so many,throw a rock you'll hit 10 of them.I would personally suggest using none of them you will learn a lot more in the process and feel a better sense of achievement.

Lastly, is there any way to open up .exe and .dat files to view the source code? This would allow me to see the source code for the game.

short answer is no,and contrary to what kyon said it was most likely not written in ASM that might be the output of a dissembler but cpus don't understand ASM they understand machine code.
Thank you all for replying so fast!!
When i said

Also, how would you animate the guests to run smoothly? If you figure that there will be hundreds and they are always moving, would it be efficient to move each of them one frame at a time? Is it possible to run a thread for each person?

I ment that is was unsure if the game would lag a lot. This is only because whenever i would animate in comand promt or on my calculator, you had to move each pixle on at a time so animations would lag if you had several animations. Is there still this problem with game engines?

Also, time is not an issue because i am willing to spend a year or more on this.

Now, is there a way to use a string in the name of a varriable or create variables in a loop like this (I don't know if that is allowed in c++):
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main()
{
    for(int i = 0; i < 10; i++)
    {
            int guest_i; //How could this create varibles that incroment in names?
            int hunger_i //ie guest_0 would be created the first time throw the loop
                         //guest_1 the second time, ect
    }
}  

Or would vectors be a better option.

Would the game lag a lot if I would run like 10 if statements per guest (ie if (hunnger < 20){getFood();}) for every guest (lets say 200)? Thats 2000 if statements that get checked every time the computer runs the game loop. Is there a more efficent way to do this?

Thanks again.

Now, is there a way to use a string in the name of a varriable or create variables in a loop like this? [..some code..]

Use arrays or vectors

Would the game lag a lot if I would run like 10 if statements per guest (ie if (hunnger < 20){getFood();}) for every guest (lets say 200)? Thats 2000 if statements that get checked every time the computer runs the game loop. Is there a more efficent way to do this?

Don't worry about performance until it's an issue.
Last edited on
R0mai wrote:
Don't worry about performance until it's an issue.

I disagree. Despite the power of today's computers, performance is not (and likely never will be) a non-issue. While simplicity, clarity and code-correctness are more important, performance is still something that must be taken into consideration. Having said that, simplicity, clarity and code-correctness go hand-in-hand with fast code - poorly written code is far more likely to cause a performance hit (particularly in the issue of scalability ( here's a post I made recently about a particle simulator which scales REALLY badly: http://cplusplus.com/forum/general/28019/page2.html#msg151369 ).

Anyway, my point is that when designing algorithms you should be thinking about scalability and how they will handle different quantities of data - an algorithm that runs incredibly fast on small sets may slow down horribly on larger ones.
Last edited on
Thanks for the information and the quick replies!!
int guest_i; //How could this create varibles that incroment in names?

a simple way of incrementing a name of an object would be to do this

int GuestCounter = 0; //This will change the name of each object.
string GuestName = "guest";
stringstream GuestStream;
GuestStream << GuestName << GuestCounter;
GuestName = GuestStream.str();
Guest GuestName();//GuestName now has the string guest + a number after it
GuestCounter++;//Every time you make a new guest iterate GuestCounter.

So basicaly evertime you make a guest it will just add 1 to the GuestCounter variable.So if it ran 5 times you would have 5 guest objects.
guest0
guest1
guest2
guest3
guest4
Im sure there are other ways to do it but this is the way i have done it and know it works.

Would the game lag a lot if I would run like 10 if statements per guest (ie if (hunnger < 20){getFood();}) for every guest (lets say 200)? Thats 2000 if statements that get checked every time the computer runs the game loop. Is there a more efficent way to do this?

ya but it not entering every if everytime.Maybe you could have the guest "sleep" when your not viewing them. so if your on otherside of the park it could suspend there actions until they where in view.Idk something to look into.I dont think it would be an issue anyway the way you said.
One more question: Will the program, more so the animations, lag if i use if statements at move each person one at a time?

The code might look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int number_of _guests = 100;

for(int i = 0; i<number_of_guests; i++) //This runs the loop for all the guests
{
        if(guest_i.hunger <20)          //This checks for the guests if their hunger and increments to all the guests
        {                               
                guest_i_x_location++;   //If they are hungery then they move one place closer to the store
                if(at_store)            //If they are that the store then do these this:
                {
                            money--;  //they pay for food
                            hunger++; //they get food
                            guest_i_x_location++; // they move away from the stand
                            }            //This would be repeated several times for other things like thirst, ect.
                }
        else{
                quest_i_x_position++;
}
        }

Would this still run fast if its again for 200 people? Or is there a better way to do this?
chrisname: Premature optimization is the root of all evil. Until most of the code is laid down, it's very hard to know which parts are the ones that are worthwhile optimizing. Optimizing something that didn't need optimization is a waste of time and, worse still, can obfuscate the parts that do need optimization.

yuropa: Setting aside the fact that you haven't written a single line of code for this game and thus your worry about how long it will take to animate something is more than disproportionate, the path the code takes to decide how to draw something is rarely as important as how you draw it. The method you're thinking about is going to take forever no matter how many decisions you add.
You're approaching this the completely wrong way. From your posts I can tell that you don't even know how modern computer graphics work. I suggest that, instead of spending time thinking about how you'll draw sprites in a game that doesn't even exist yet, you grab a DirectX/OpenGL tutorial/book and start properly: from the bottom. You have to crawl before you can walk.
I'm not trying to bring you down, I just don't want you throwing away a lot of time before realizing that you have no idea how to continue.
Last edited on
@helios,
That's what I'm saying. Although code correctness is more important, speed is still something you should think about. I'm not talking about micro-optimizations, I'm talking about code quality. Good quality code will usually be faster than bad quality code - there is less of it, it is easier to read and maintain, and when you know what parts need optimizing (using your profiler) then you can set about optimizing it to make it faster without breaking the readability.

I just don't think you should put taking performance into account aside until you have to, I think you should always be thinking about performance. But as I said, clear and concise code is more important (I did say that in the firstsecond sentence of my previous post).
Last edited on
Topic archived. No new replies allowed.