Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (582)
Games in Android Showcase (163)
games submitted by our members
Games in WIP (633)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to build a 4x game  (Read 5131 times)
0 Members and 1 Guest are viewing this topic.
Offline Gornova

Senior Devvie

Medals: 1
Projects: 3

« Posted 2011-11-25 13:37:30 »

I'm trying to study how succefully implement a 4x game.

Area of interest:

1) map data: how to store stellars systems (graphs?), how to generate them and so on.. 2) multiplayer: how to organize code in a non graphical server and a client to display it 3) command system: what are patters to catch user and ai decisions and handle them, adding at first "explore" and "colonize" then "combat", "research", "spy" and so on (commands can affect ships, planets, research, etc..) 4) ai system: ai can use commands to expand, upgrade planets and ship

I know is a big questions, so help is appreciated Cheesy

1) Map data

Best choice is have a graph to model a galaxy. A node is a stellar system and every system have a list of planets. Ship cannot travel outside of predefined paths, like in Ascendancy:

Every connection between two stellar systems have a cost, in turns.

Generate a galaxy is only a matter of: - dimension: number of stellar systems, - variety: randomize number of planets and types (desertic, earth, etc..), - positions of each stellar system on game space - connections: assure that exist a path between every node, so graph is "connected" (not sure if this a matematically correct term)

2) Multiplayer

Game is organized in turns: player 1, player 2, ai1, ai2. Server take care of all data and clients just diplay it and collect data change. Because is a turn game, latency is not a problem Cheesy

3) Command system

I would like to design a hierarchy of commands to take care of this aspect:

abstract Genericcommand (target) ExploreCommand (Ship) extends genericcommand colonizeCommand (Ship) buildcommand(planet, object)

and so on.

In my head all this commands are stored in a queue for every planets, ships or reasearch center or spy, and each turn a command is sent to a server to apply command and change data state

4) ai system

I don't have any idea about this. Is a big topic and what I want is a simple ai. Something like "expand and fight against everyone". I think about a behaviour tree to control ai moves, so I can develop an ai that try to build ships to expand and then colonize planets, upgrade them throught science and combat enemies. Could be done with a finite state machine too ?

any ideas, resources, article are welcome!

Blog | Last game Drone Defense 0.2 | In progress Drone Defense
Offline loom_weaver

JGO Coder

Medals: 17

« Reply #1 - Posted 2011-11-25 22:37:51 »

How much Java do you know?
Offline Gornova

Senior Devvie

Medals: 1
Projects: 3

« Reply #2 - Posted 2011-11-26 13:43:01 »

I have good knowledge of Java

Blog | Last game Drone Defense 0.2 | In progress Drone Defense
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline delt0r

JGO Knight

Medals: 33
Exp: 18 years

Computers can do that?

« Reply #3 - Posted 2011-11-26 14:24:32 »

Don't start with a 4X. Start with just the first X. Get the first bit working without multiplayer. Don't worry about things like command details at the start. You are going to be wrong every time. You will only get a good idea of what is needed once you have something up and running.

Basically start with a very small playable core. Get that playable. Then go from playable state to playable state.

Trust me. I have been writing a RTS for years. Now i have started again and got something playable in the first weekend. It is what i should have done in the first place. Then you focus on the game, not the code.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline loom_weaver

JGO Coder

Medals: 17

« Reply #4 - Posted 2011-11-26 16:33:46 »

I have good knowledge of Java

Okay just checking because your question is similar to one that asks how do I create an MMO?

delt0r's advice is good and so I have nothing else to add.
Offline Gornova

Senior Devvie

Medals: 1
Projects: 3

« Reply #5 - Posted 2011-11-26 19:49:14 »

thanks for tips Cheesy

Explore is for sure first thing to do!

Now keeping on creating a graph with a decent galaxy to explore!

Blog | Last game Drone Defense 0.2 | In progress Drone Defense
Offline Grunnt

JGO Kernel

Medals: 95
Projects: 8
Exp: 5 years

Complex != complicated

« Reply #6 - Posted 2011-11-30 08:12:58 »

For generating a galaxy, I found it very difficult to generate a galaxy of a specific shape. One approach that worked quite well was to use a "probability map" kind of approach.

To get an evenly distributed starmap I'd use the following approach:
1. Select a random position on the map
2. Check if any other star is too close
3. If not, place the star, otherwise go to 1
Repeat until you got enough stars.

Very simple, but usually works just fine. Now, the "probability map" makes this a bit more complicated. For this you need an image file of the shape of the galaxy you want. For example, a 128x128 image with a black background and the galaxy shape in shades of grey and white. Each pixel of the map then represents the probability that a star will be present in the area of the map covered by the pixel (i.e. black pixels = no stars, white pixels = many stars, grey pixels = some stars).

Generating a star map would then rougly go as follows:
1. Select a random position on the map
2. Get a normalized R,G or B value (i.e. 0f to 1f) of the pixel that corresponds to the selected position. We'll call this the "pixel value"
3. If (random.nextFloat() < pixelValue) check for close stars and place the star
Repeat until you got enough stars.

Ofcourse this is not an efficient algorithm at all, but map generators do not need to be. And you'll still need to add space lanes and stuff. But I don't really like wormholes or space lanes anyway (is it a co├»ncidence that the Master of Orion series went down the drain as soon as space lanes appeared?), so that's not a problem for me   

Anyway, using this approach (and some toying with it was quite easy to generate all kind of complex galaxy shapes, from clusters to spirals. And it didn't requite too fancy mathematics. Maybe it gives you some ideas.

Offline Skarion

Senior Devvie

Medals: 2
Projects: 1

« Reply #7 - Posted 2011-11-30 12:51:47 »

Was considering taking how I made my game into my grave, though as I know it's nothing new I guess I can share the basics I've figured out when creating a 4x.

1, Map data

As to have the quickest generation I think a HashMap<Point, Star> is the best data set. It's slow to add new stars in though it's never a problem if you generate the stars only once. The O(1) complexity to pick up a star from a position is so worth it.

The graph can be a abstract graph within each star, though picking out for example a LinkedList just as to symbolize the graph is too slow to be properly used.

Generating a galaxy depends on what kind of galaxy you wish to create. I prefer randomized galaxies and then add weights which gathers the galaxy into clusters.

Randomization  generation is usually as simple as:

Random rand = new Random();
Point p = new Point(rand.nextInt(UNIVERSE_WIDTH), rand.nextInt(UNIVERSE_HEIGHT));
starMap.add(p, new Star());

The graph creation is just  a "Breadth-first search" with weights problem.

2, There exist thousands of different suggestions.

If going turn based then going the easiest fashion with mailboxes make each player send in orders, make server do orders and then let server send out results.

If RTS then if someone do something, send said order to everyone. When everyone has said that they have recieved said order they do said order. All random factors should be set to a SEED. Making sure everyone's games are constantly identical.

3, Your idea of a functional approach isn't how you should do it in Java. Just do it OOP as you should do it in Java.

4, I preferred a randomized there events (colonization, research &:c) affects the options and then let the AI go nuts.

In my game it became quite nicely lethal but still simple.
Offline lordberzerker97

Senior Newbie

« Reply #8 - Posted 2011-12-13 01:29:16 »

What do you mean by a core game? I also want to create a 4x game, but i don't know where to start... Sad Sad Sad
Offline Skarion

Senior Devvie

Medals: 2
Projects: 1

« Reply #9 - Posted 2011-12-13 09:23:14 »

A core game meant that you should implement one simplest functionality to be considered a game (a starship following the mouse on the screen or whatever) and then add functionality from there until you got a whole game. Kind of a simple agile production.

If 4x sci-fi then I'd say to begin by randomizing a bunch of points into a data structure.

Then paint said points as JLabels on a JPanel.

And voila, you got the basics for the simplest kind of 4x game! Smiley

If you want some other kind of 4x then you need to specify which to let me help you.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline impaler

Senior Newbie

« Reply #10 - Posted 2011-12-13 11:11:00 »

For generating galaxies I worked out a pretty basic algorithm but gives good results.

I have a 2 dimensional array. The distance between two adjacent elements is 1.
I pass in a minimum distance to the algorithm, meaning the minimum distance between the stars. If it's 2, then at least 2 spaces around a star must remain empty.

I take the first row, pick a random position, place the star and fill in the surrounding minDistance cells with "occupied". I also fill in on the Y axis.
Pick a random position from the remaining available positions and randomly select one available space, fill in the occupied and continue until there is no more space left. Do this for each row.

For shaping the galaxy, use a probability map as mentioned before.

The distances after is finished are calculated by using simple 2D math and the graph can be built.

Hope it helps someone.
Offline lordberzerker97

Senior Newbie

« Reply #11 - Posted 2011-12-14 00:19:54 »

 What should i use for a 4x game. Swing or Applet
Offline lordberzerker97

Senior Newbie

« Reply #12 - Posted 2011-12-14 00:50:13 »

Another question i have is for a 4x game is it more GUI or UI...
Offline Skarion

Senior Devvie

Medals: 2
Projects: 1

« Reply #13 - Posted 2011-12-14 07:42:24 »

What should i use for a 4x game. Swing or Applet
Another question i have is for a 4x game is it more GUI or UI...

Now you are just trolling right?

1, Doesn't matter. I prefer desktop platforms in Swing as I consider such games more real, others prefer Applets.

2, Isn't GUI and UI the same thing? Or do you mean text based versus graphical? In such a case it's whatever you prefer. I'd say graphical as a text based 4x feels quite a few decades old.
Offline Gornova

Senior Devvie

Medals: 1
Projects: 3

« Reply #14 - Posted 2011-12-14 07:49:33 »

same problem for me, need to fine some gui tool to design a good gui for my 4x game without doing by myself

Blog | Last game Drone Defense 0.2 | In progress Drone Defense
Offline lordberzerker97

Senior Newbie

« Reply #15 - Posted 2011-12-15 04:39:57 »

 Where did you place that code. Did you place it in the constructor or the paint method... Never mind i found another way.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Ralphanese (18 views)
2015-05-29 13:07:55

Gibbo3771 (15 views)
2015-05-29 06:54:17

Ralphanese (23 views)
2015-05-28 16:52:52

theagentd (31 views)
2015-05-27 22:21:17

theagentd (35 views)
2015-05-27 22:21:08

CopyableCougar4 (25 views)
2015-05-27 19:24:50

MrMapcom (24 views)
2015-05-23 20:26:16

MrMapcom (32 views)
2015-05-23 20:23:34

Waterwolf (37 views)
2015-05-20 15:01:45

chrislo27 (44 views)
2015-05-20 03:42:21
Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!