1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. To chat with the GameOgre community, you need to have at least 15 posts. Once you have the 15 posts, post at Become A New Ogre
    Dismiss Notice

any 1 can help me in battle system

Discussion in 'Online Game Development' started by rtkwar, May 31, 2011.

Thread Status:
Not open for further replies.
  1. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    any 1 can help me in battle system
    if ihave 10 tank and 10 soldier and 10 f16
    and my enemy have
    5 tank and 15 soldier and 4 f16
    how ican make battle system
    if iattack on my enemy how ican culculate how much ilost and how much he lost
    thank you
     
  2. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    What kind of losses do you want to have?

    Realistic losses?
     
  3. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    The total hitpoints of each army are compared in a fight, to determine the casualties.
    If the number of total hitpoints of the attacker is higher than the defender, then the attacker wins the battle,
    else the defender wins the battle.

    The loser of the battle often gets the highest relative casualties.

    Code:
    $yourplanes = 10;
    $yourtanks = 10;
    $yoursoldiers = 10;
    
    $enemyplanes = 4;
    $enemytanks = 5;
    $enemysoldiers = 15;
    
    I'm assuming you know how to select those values from the table. In this example they are given.

    Next we calculate total hitpoints of both armies.
    For example, say F16 is worth 10 points, and tank is worth 5 points, and soldier is worth 1 point.

    Code:
    $yourhitpoints = ($yourplanes * 10) + ($yourtanks * 5) + ($yoursoldiers * 1);
    $enemyhitpoints = ($enemyplanes * 10) + ($enemytanks * 5) + ($enemysoldiers * 1);
    
    In this example the strongest army always wins. You could change the default value,
    if you use something like battlefield terrain and use different values for each type of terrain.
    That way armies which are normally weaker, can sometimes win, if they fight on good terrain (in the equation they are seen as stronger).

    Now we compare both armies and see who wins.

    Code:
    if ($yourhitpoints >$enemyhitpoints){
    $THW = $yourhitpoints;
    $THL = $enemyhitpoints;
    $victory = 1;
    }
    else {
    $THW = $enemyhitpoints;
    $THL = $yourhitpoints;
    $victory = 0;
    }
    
    Here is how you calculate the default relative casualties of the winner:

    Code:
    $WC = (1 - (($THL / $THW) * ($THL / $THW))) / 2;
    
    Where:
    THL = total hitpoints of loser's army
    THW = total hitpoints of winner's army
    WC = relative casualties of the winner's army


    Here is how you calculate the default relative casualties of the loser:

    Code:
    $LC = (1 - (($THL / $THW) * ($THL / $THW)));
    
    Where:
    THL = total hitpoints of loser's army
    THW = total hitpoints of winner's army
    LC = relative casualties of the loser's army

    Now to calculate casualties.

    Code:
    if ($victory ==1){
    $yourplanecasualties = round(($yourplanes * $WC));
    $yourtankcasualties = round(($yourtanks * $WC));
    $yoursoldiercasualties = round(($yoursoldier * $WC));
    $enemyplanecasualties = round(($enemyplanes * $LC));
    $enemytankscasualties = round(($enemytanks * $LC));
    $enemysoldiercasualties = round(($enemysoldiers * $LC));
    }
    else {
    $yourplanecasualties = round(($yourplanes * $LC));
    $yourtankcasualties = round(($yourtanks * $LC));
    $yoursoldiercasualties = round(($yoursoldier * $LC));
    $enemyplanecasualties = round(($enemyplanes * $WC));
    $enemytankscasualties = round(($enemytanks * $WC));
    $enemysoldiercasualties = round(($enemysoldiers * $WC));
    }
    
    
    The trick here is to round the number, or else you get a half killed off tank for example and that is no good of course.

    We can use casualties for a battle report, but what we really want of course is the remaining forces after the battle.

    Code:
    $yourremaininglanes = $yourplanes - $yourplanecasualties;
    $yourremainingtanks = $yourtanks - $yourtankcasualties;
    $yourremainingsoldiers = $yoursoldiers - $yoursoldiercasualties;
    $enemyremainingplanes = $enemyplanes - $enemyplanecasualties; 
    $enemyremainingtanks = $enemytanks - $enemytankscasualties; 
    $enemyremainingplanes = $enemysoldiers - $enemysoldiercasualties;
    
    Next we update both armies, to show the new state after the battle.

    Code:
    mysql_query("UPDATE Armies SET Planes ='$yourremaininglanes', Tanks ='$yourremainingtanks', Soldiers ='$yourremainingsoldiers' WHERE Army ='$yourarmy'");
    mysql_query("UPDATE Armies SET Planes ='$enemyremainingplanes', Tanks ='$enemyremainingtanks', Soldiers ='$enemyremainingplanes' WHERE Army ='$enemyarmy'");
    
    And there ya go!
     
    Last edited by a moderator: May 31, 2011
  4. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    This is a really simple and basic battle system. You can expand on it of course.

    Say for example you want the loser to have higher casualties if he's been ambushed, then all you do is add that number. Say for example you want 10% more casualties, then all you have to do is add 0.1 to the equation of the loser.

    I hope you know how to select from an sql table or else you will not be able to use this example on your armies.
     
  5. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    In this example, here is what the result will be.

    Your remaining army:
    F16 = 6
    tanks = 6
    soldiers = 6

    Enemy remaining army:
    F16 = 1
    tanks = 1
    soldiers = 4

    This is because in this example the total strength of the enemy army is exactly half of the total strength of your army.
     
    Last edited by a moderator: May 31, 2011
  6. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    Now how realistic is this equation?

    The data is roughly based on empirical data, of ancient armies. Rome versus the barbarians.

    It turned out that if the size of the barbarian army is 60% of the roman army, then it would get about 64% casualties.

    (1 - (0.6 * 0.6)) = 0.64

    Likewise if the size of the barbarian army is 80% of the roman army, then it would get about 36% casualties.

    (1 - (0.8 * 0.8)) = 0.36

    Again if the size of the barbarian army is 90% of the roman army, then it would get about 19% casualties.

    (1 - (0.9 * 0.9)) = 0.19


    Likewise the Roman army would get half of those barbarian casualties.

    There was a small discrepancy in this rule, Rome usually got about 1% less casualties, which I think is due to use of armor and technology.

    I haven't tried this rule yet on modern armies, but if I were to calculate the use of modern armor (i.e. tanks and technology) into the equation, then my hypothesis is that a similar rule would come out of it, but the discrepancy would be a lot higher, because of the increased effectiveness of modern armor and technology.

    I have however been able to prove from the empirical data collected, that the army who gets the highest relative casualties in battle, always loses the battle!

    So say for example your army gets 10% casaulties and the enemy 11% casualties, then you win.


    What I don't know is how high the discrepancy is for modern army and technology!

    extremes

    I did take out the extremes in the collection of the empirical data with a boxplot and interquartile distance.

    One extreme was the battle of Carrhae, where a Persian army of inferior numbers (about 25% size of the Roman army), fought and won and caused more than 45% casualties to the Roman army and yet another 25% captured. The extreme is best explained through the use of composite bows by the Persian army.

    So in other words, size is not all. You have to determine the worth of the units in the army.

    theory

    I do have a theory on how to determine the worth of tanks and F16's versus soldiers. It is similar to the cost to build, equip and train them.

    So say it costs 18 million dollar to build an F16 and 2 million dollar to train the pilot, then the total cost would be about 20 million.

    So say it costs 4 million dollar to build a tank and 1.5 million to train the soldiers seated in the tank, and there are 4 soldiers in the tank, then the total cost would be about 10 million.

    So say it costs about 1 million to train and equip a soldier, then the total cost would be about 1 million.


    That makes the F16 worth 20 hitpoints, the tank worth 10 hitpoints and the soldier worth 1 hitpoint.

    So your army would fight at the equivalent strength of 200 + 100 + 10 = 310 men, while the enemy would fight at the equivalent strength of 80 + 50 + 15 = 145 men.

    That makes the enemy army fight at about 47% strength.

    So the casualties of the enemy army will be about: 78%
    while your casualties will be about: 39%

    Why divide by 2?

    This may be explained by guerilla warfare, so if the two armies are unequal in every way, the casualties of the better army should also be higher.

    The benefit of this in the game is that it makes the player less inclined to attack opponents who are incredibly weak.

    It is not realistic, but a good way to ensure fair play.

    Perhaps more realistic would be this:

    Code:
    if ($LC <0.8) {
    $WC = $LC / 2;}
    else {
    $WC = 1 - $LC;}
    
    With that equation, the winner would get less casualties with unequal armies, and casualties will never be higher than 40%.
     
    Last edited by a moderator: May 31, 2011
  7. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    thank you very much my friend iam don't know whats iam must say,thank you very much iam try your battle system in my new game and iam tell you
    you can tell me iam want use javascript and ajax in my new game idon't know if this good or bad idea?
     
  8. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    ajax is a good idea, but it is difficult to script, especially if you are new to javascript and php.
     
  9. awesomedrako

    awesomedrako Clubbed

    Messages:
    2,704
    Likes Received:
    445
    Trophy Points:
    0
    Credit:
    2,802.14
    Jeez, you are really good at the technical side of these battle systems shugo, sooo in-depth :O

    And I've been thinking, Python has always seemed like an easy scripting language, and I know it can be used in web development, but how? If it can be used for a game, it might be a good choice for this person as well.
     
  10. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    Python is an excellent language, it is incredibly stable.

    Unfortunately I wouldn't be able to tell you how. I know python is used with python class files, in the same way a javascript uses js files, but I don't know how it communicates with sql. And sql is what you need to make a relational database. And you need such a database to make an interactive game.

    Unfortunately I've only used python once for a small script that I used for arcgis (a geographical map editor). Last time I used that was about 3 years ago I think.

    I do know that it can be used for a game, I've seen people use it, the trouble is I don't have any experience in it.
     
    Last edited by a moderator: May 31, 2011
  11. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    I think, I made an error in that script.

    If armies are equal, casualties would be zero.

    So the solution is to:

    Code:
    if ($yourhitpoints >$enemyhitpoints){
    $THW = $yourhitpoints;
    $THL = $enemyhitpoints;
    $victory = 1;
    }
    elseif ($yourhitpoints ==$enemyhitpoints){
    $THW = $enemyhitpoints + 1;
    $THL = $yourhitpoints;
    $victory = 0;
    }
    else {
    $THW = $enemyhitpoints;
    $THL = $yourhitpoints;
    $victory = 0;
    }
    
    That difference may be explained by the defender's initiative.
     
    Last edited by a moderator: May 31, 2011
  12. awesomedrako

    awesomedrako Clubbed

    Messages:
    2,704
    Likes Received:
    445
    Trophy Points:
    0
    Credit:
    2,802.14
    It seems you need a framework like Flask or Django. But all this SQL stuff is pretty daunting to me, so it'll probably be quite daunting to this person as well :(. Still, you probably have to learn SQL to do any kind of web development of that sort.

    Or, maybe he could develop single-player flash games and skip SQL?
     
  13. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    Django or Flask, yeah could be, though like I said, don't have any experience there

    I find single player flash games to be quite boring actually
     
  14. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    I discovered the disadvantages of this system

    I discovered the disadvantages of this system:
    if you have=10 planes
    enemy have=5 planes
    planes hitpoint=128

    your total hitpoint=10*128=1280
    enemy total hitpoint=5*128=640

    your casualties=(1-((640/1280)*(640/1280)))/2=0.37
    enemy casualties=(1-((640/1280)*(640/1280)))=0.75

    your planes casualties=10*0.37=3.7
    enemy planes casualties=5*0.75=3.75

    now we Suppose ihv 100 planes

    your total hitpoint=100*128=12800
    enemy total hitpoint=5*128=640

    your casualties=(1-((640/12800)*(640/12800)))/2=0.49
    enemy casualties=(1-((640/12800)*(640/12800)))=0.99

    your planes casualties=100*0.49=49 !!!!!!!!!!!!!!!!!!
    enemy planes casualties=5*0.99=4.9



    now we Suppose ihv 5555 planes

    your total hitpoint=5555*128=711040
    enemy total hitpoint=5*128=640

    your casualties=(1-((640/711040)*(640/711040)))/2=0.49
    enemy casualties=(1-((640/711040)*(640/711040)))=0.99

    your planes casualties=5555*0.49=2721 !!!!!!!!!!!!
    enemy planes casualties=5*0.99=4.9

    thats mean if player send more troops in attack he will lost more
     
  15. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    yes you're absolutely right there

    the solution would be to not make it percentage based, but based on say hitpoints, then in absolute terms, the one with the bigger army would never lose more planes than his enemy.
     
  16. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    lets say for example this:

    you have 10
    enemy has 5
    planes hitpoint 128

    enemy casualties is 0.75
    which is 4 enemy planes
    your casualties is 4 enemy planes * 0,37 = 1,48

    so percentage wise on firepower

    that would make it better for the bigger army

    second example:
    enemy army 5 casualties
    5 * 0.49 = 2.45 = 3 casualties

    again that would make it better for the bigger army


    unfortunately it would make it totally unfair for the small armies, you could wipe them out in an instant. While you are absolutely right with your calculations, your system wouldn't exactly be newbie friendly.

    Also if you base it on hitpoints, because like you said, you don't want to have the bigger army lose more planes than the smaller army, that wouldn't exactly be realistic either.

    Here is why!

    Art of War by SunTzu [SunZi] -English Hypertext point 36 (chapter 7)

    Art of War by SunTzu [SunZi] -English Hypertext point 1, point 10, point 14 (chapter 11)

    What you do, is make a desperate situation, the small army cannot win! Hence in reality it will choose to fight to the death! Armies that are in that kind of situation are like a cat in distress, they will lose with certainty, but they will take a lot of casualties with them for the bigger army. It is a rule that is still valid in the 21st century. One famous warlord that understood why not to fight a desperate army is Laurent Nkunda. He was most dangerous to his enemies, because he kept an escape route open for weak enemy armies and then hammered at those armies, causing great casualties to such armies. He understood that when a weak army can flee, it will flee (and hence get shot in the back), but when fleeing is not an option, such armies will make a desperate and obstinate fight and cause a lot of casualties to the ultimately victorious army. Hence there is point 36 in chapter 7 of Sun Tzu the art of war.

    Now back to what it does in your game. If you always let the big army win, with few casualties, then what happens is that newbies quit your game! Why do you ask? Because the only way they can flee, is to leave your game! Hence it is better to let big armies not attack very small armies and one way to do that, is to not make it interesting. There are 2 ways not to make it worthwile for you to attack a seriously unequal opponent. 1) have the big army get lots of casualties, or 2) have few casualties but also very little gains in resources for the victorious army. That way the big guy will try to attack opponents who are more or less equally matched.
     
    Last edited by a moderator: Nov 6, 2011
  17. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    ok anyway iwill use my old battle system ithink its more realistc in my battle system if you have 5550 planes and enemy have 130 plane
    you lost 5 planes only and enemy will lost 130
    ithink thats more reall
    (imagine that hetler hv 5550 planes and u hv only 130 in sky who should win! ithink hetler)
     
  18. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    well, you could stop a situation like that, by disallowing battles where the smallest army has less than say 10% of the hitpoints of the biggest army...

    unfortunately that may also have disadvantages
     
  19. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    you can make research page
     
  20. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,301.21
    lol yeah I should, but there are already a lot of such sites
     
Thread Status:
Not open for further replies.

Share This Page