Jump to content
  • Advertisement
Sign in to follow this  
Overwatch

Browser Based Games: Back-end for battles

This topic is 892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I am a new member here. I'm also part of a team that is currently trying to develop a browser-based game like Tribal Wars 2 or Travian.

 

There are actually a few things that I want help but my number one question right now is about how we should approach executing battles or attacks to an empire in the game real-time.

 

Right now, we currently execute the battles every 1 minute using a cron job. It works pretty much fine but along the way we realized a few things:

  1. Attacks are time-based so if we execute the battle every minute there will be delay in completing the battle job.
  2. Attacks are also simultaneous, so a particular empire can be attacked many times at the same time.
  3. There will be waiting time for a battle to complete (around 3-5 seconds), so when an attack to the same empire that is just 1-2 seconds behind the previous attack will also have to be delayed.

We'll really appreciate all the help you guys will give. We've been looking into many forums already. Thank you in advance. :blink:

Share this post


Link to post
Share on other sites
Advertisement

Well I'm certainly no expert when it comes to structuring a RTS game, but why every minute? 

 

I would imagine you would organize all of your empires in some kind of construct, and iterate through them. Instead of having a pre-allocated job run once every minute, empires should attack at any time their AI determines that they have enough soldiers, artillery, and morale based upon the correct (or incorrect) information gathered from their scout unit. 

while (true)
{
    for (int i = 0; i < empires.size(); i++)
        empires.at(i).update(/*some delta value, and other necessary arguments*/); 
}

I could be misunderstanding the question. But, if your saying what I think your saying; it would seem odd to limit offensives from enemy empires based upon some arbitrary one minute delimiter. 

 
Marcus Hansen
Edited by markypooch

Share this post


Link to post
Share on other sites

Any particular reason why you can't run a continuous process that handles battles (or waits if there are none)? Would firing the battle job every second do the trick, for example?

 

 

Note that you didn't state how you want it handled, ie what is the desired behaviour that you want to have?

Deriving desired behaviour from disadvantages of a current solution is a bit hard :)

Share this post


Link to post
Share on other sites
How to handle this depends somewhat on the server technology. Sometimes a cron job is used because it has to be done via a web request, eg. for PHP games, or if the server is entirely event-driven. Knowing what language is being used would help here.

I think the issue around simultaneous attacks goes away as long as you resolve each attack in the order they appear, one after the other. If that is a problem, it implies some other constraint or requirement that isn't specified above. Either way, it's probably simplest to push attacks onto a queue and have some other process pull attacks off the queue to process them in order. How to implement the queue again depends on the technology (although a simple DB table usually suffices).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!