Hot answers tagged

77

Now how does the game handle those 30 Projectile and 70 units by handling them on 100 different threads No, never do that. Never create a new thread per resource, this doesn't scale in networking, neither does it in updating entities. (Anyone remember the times when you had one thread for reading per socket in java?) 1 thread that moves all of them ...


52

Go with the second approach, simply due to the fact that you can introduce new resource types or items at any time without having to rewrite or update code (data driven development). Edit: To elaborate a bit more on why this is in general good practice, even if you're 100% sure some value won't ever change. Let's take the console game example mentioned ...


38

Rule number one of multithreading is: Don't use it unless you need to parallelize on multiple CPU cores for performance or responsiveness. A requirement "x and y should happen simultaneously from the users point of view" is not yet sufficient reason to use multithreading. Why? Multithreading is hard. You have no control over when each thread gets executed ...


36

*Edit: Fixed error in javascript that caused error on firefox * Edit: just added ability to scale hexes to the PHP source code. Tiny 1/2 sized ones or 2x jumbo, it's all up to you :) I wasn't quite sure how to put this all into writing, but found it was easier to just write the code for a full live example. The page (link and source below) dynamically ...


30

A rule of thumb is that you use different classes when objects require different code and instances of the same class when the objects only require different values. When the resources have different game mechanics which are unique to them, it might make sense to represent them with classes. For example, when you have Plutonium which has a half-life time ...


27

The other answers have handled the threading and power of modern computers. To address the bigger question though, what you are trying to do here is avoid "n squared" situations. For example if you have 1000 projectiles and 1000 enemies the naive solution is to just check them all against each other. This means you end up with p*e = 1,000*1,000 = 1,000,000 ...


26

At first you see that your commands are in the form of a list, so your first instinct might be to recreate that structure, and each dwarf will run through that list in sequence. What I suggest though is to break the list into steps, with each step having prerequisite(s), and then you run the entire command in reverse. Let me demonstrate with an example: ...


23

What you do depends on the nature of the achievement. Unless your achievements all fit a simple pattern (collect X number of Ys), you're going to have to special-case them to some degree. Using a message-based communication system, you can provide hooks that makes the special-case coding localized. You can have certain actions fire messages to listeners who ...


18

From left field: Don't allow the player to give direct orders to his units The idea is that you give the player's troops the same AI capabilities as the enemy, and then provide him with a goal setting system and a state toggle system. The player can set goals/objectives attached to enemy units or map locations, such as: Destroy this Guard area Clear ...


18

The only similar system I know is OGame. In OGame, players are protected from other players until the have a certain amount of points (I think it is 50.000). It makes more sense to protect players based on their score instead of time, as score gives you a better aproximation on how powerful players are. The theory is that with that many points, players are ...


17

Do not create threads per resource/object but per section of your program logic. For example: Thread to update units and projectiles - logic thread Thread for rendering the screen - GUI thread Thread for network (eg. multiplayer) - IO thread The advantage of this is that your GUI (eg. buttons) does not necessarily get stuck if your logic is slow. User ...


14

I would like to add there are two extra options: Interface: you can consider it if the resource class would be just a "storage" for 5 integers and each other entity would have different logic regarding resources (e.g. player spend/loot, city produces resource). In that case you might not want a class at all - you merely wanted to expose that some entity has ...


12

Rule number one of multithreading: Don't even think about it, unless you really need to use multiple CPU cores for performance reasons*. Multithreading opens up a whole can of worms of obscure and impossible to reproduce bugs: Race conditions! Because you have no control over the thread scheduling of the OS, you have no control over the order in which ...


12

Your goal of synchronizing 50 events per second in real-time sounds to me like it is not realistic. This is why the lock-step approach talked about in the 1500 archers article is, well, talked about! In one sentence: The only way to synchronize too many items in too short time over a too slow network is to NOT synchronize too many items in too short time ...


11

Whilst I agree with DampeS8N's opening paragraph (i.e. game AI only needs to be smart enough to make the player think that it's smart), I feel that this question needs a little more elaboration. The data structures in use could be FSMs for all levels, but that doesn't really answer the question as to how the individual systems work. Disclaimer: I have ...


11

You should write a small javascript tile layout engine that maps the database tile coordinates into a view on the web page, because this lets you outsource the cpu processing time to the players computer. It's not hard to do and you can do it in few pages of code. So essentially you'll be writing a thin layer of PHP of which only purpose is to deliver ...


10

If you can make sequences pretty general, there's not much of a spaghetti code. In case of deliveries e.g.: WorkTask operates with a WorkPlan. Workplan says what kind of resource unit must pick, from what kind of house, using which walk animation, using which work animation, time to work and all such details. So in the end WorkTask might look like: Find %...


9

I'd throw away the first two of your bullet points. It might be a good idea to get some units designed, but isn't going to really help you for balancing. Really what you're going to have to do is just play the game a lot and keep a analytical mind (or set of minds) looking at the problem at all times. Design is a very soft art, there is no iterative way ...


8

In general AI in games shouldn't be thought of as 'complex' it is all about getting what you want with the least possible effort. The name of the game is Emergence. In this case, your fundamental conceptualization is wrong. These 4 systems do not need to work together at all. They just need to look like they do. They can also be a lot more stripped down ...


8

Don't allow it. Give the player a specific role, and that's it. The guy who gives the orders to attack a group of enemies to the north isn't sitting there at the fight telling each guy who to shoot, he's back at base giving more orders to other soldiers. For a more realistic/immersive experience, and to discourage/prevent micromanagement, allow the player (...


8

I agree with thedaian but would like to expand upon his point. Most micromanagment is done to make up for the AI being inefficient. When I micro its usually because either: my troops won't kill weak units before targeting stronger ones, they won't target high dps units before lower dps units, they won't concentrate fire to take out individual units (kind of ...


8

Summary: Depict differing world-views and perspectives in a value-neutral, non-judgmental way In order to deal with prejudices, biases, and bigotry, I would focus away from artificial "This is a minority in the galaxy. It's wrong to hurt them!" style methods. It's not that it's inappropriate, but that it would be ineffective at doing anything but "...


8

Reduce progression in your game mechanics. Avoid making players stronger in a game-mechanical sense based on how far they progressed in the game. That way an experienced player has no unfair advantage over an inexperienced player except for their game knowledge, which a new player can also acquire when they do their research. Herd your players. When a player ...


7

The first step is to have design goals. Figure out what kind of features your game will have, so you know where to focus your efforts and what designs to look out for. Will it be graph heavy? Will it be minimal and have panels upon panels hidden away? Will most of the action take place in the UI or in the game world? Will it be animated? Does it have a theme ...


6

Most games centre around a 'game step' loop. Things happen in discrete pacels of time. It is straightforward to have a queue of future events and to consume those events for each game step. More about game time-steps on the gafferongames blog.


6

Our life is frittered away by detail . . . simplify, simplify. (Henry David Thoreau) My answer is similar to those that suggest picking a clear role for the player. What they're really saying is to simplify I think. The reason micromanagement happens is because there are very many choices to make during play, and in general they only really matter in ...


6

every action the player takes is deterministic, however, there are events that happen on scheduled intervals I think there's your problem; your game should only have one timeline (for gameplay-affecting things). You say that certain things grow at a rate of X per second; find out how many game steps are in a second and convert that to a rate of X per Y ...


5

Just record your game time, add it to a variable, once the variable gets to a certain amount, fire your event.


5

http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php This is still how networking is done in RTS games. P2P is also the normal way of handling connections. Using a lock timestep model however results in the irritating case of desync and cheating handling. There is good way of recovering when a desync happens and all RTS games ...


5

TL;DR A simple List<int> is enough to store all the information you need. Read on for the details. Context I'll drop in a little trick here then. Are you aware that when working with 2D matrices there's a way to index them with a single number, instead of having to provide a (x,y) pair? For instance, where is the letter d in the following matrix? ...



Only top voted, non community-wiki answers of a minimum length are eligible