Author Topic: Battle Script the 2nd  (Read 939 times)

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Battle Script the 2nd
« on: March 14, 2007, 03:33:44 PM »
Okay, here's my problem:

I'm trying to expand my battle script. Right now all it does is calculating the casualties on both sides and it determines the winner. Really just a placeholder. It even uses just 3 types of units.

Now, my new battle systems is a lot bigger.

First off, there are more types of units.
Units have the following attributes:
- Live (How much damage one unit can take before it dies)
- Offensive Damage (How much damage is dealt when attacking)
- Defensiv Damage (How much damage is dealt when defending)
- Damage type (what kind of damage is dealt, possible types are blade, pierce, impact, fire and ice)
- Resistance (Precentage of damage received by each damage type, example: 100% Blade, 80% Pierce = + 20% pierce damage)

Now, there are different types of units:
- Infantry (low pierce damage)
- Archers (low offensive, high defensive pierce damge)
- Swordmed (high blade offensive damage)
- Catapults (high offensive impact damage, can destroy buildings)
- Cavalry (high blade/pierce offensive damage)
- Militia (medium impact damage)
- Pikemen (high defensive pierce damage)
and others to come (this is just to illustrate what I'm trying to do)

The defender has in addition to his units some buildings, such as:
- Castle (Defense bonus)
- Towers (Units can be stationed in)
- Walls (Units can be stationed above)
- Traps (Might kill off enemy units)

Units in towers take much less damage (60%), units on walls take a bit less damage(80%) and units on the ground take full damage.

Now, an attacker can specify an attacking force and sends them on its way to the target.
The target has the possibilty to call for reinforcements from other players. Reinforcements are units that are placed at the targets castle until they get withdrawn. These units can't be placed in towers or on walls (just for simplicity in the database).

Now, here comes my actual question:
How should I divide up the damage taken by each group of units? By group I mean the units in towers, the ones on the walls and the ones on the ground.
Should i just divide the whole attacking damage by each type and distribute it accordinlgy to group size?

Maybe some numbers help:
Attacker:
100 Units with each 10 pierce damage => 1000 pierce dmg total
50 Units with each 15 blade damage => 750 blade dmg total
20 Units with each 50 impact damage => 1000 impact dmg total
------------------------------------------------------------------------
170 units with 2750 dmg total

Defender:
(own)
20 Units with each 15 pierce dmg in tower
50 Units with each 15 pierce dmg on walls => 1050 pierce dmg total
50 Units with each 10 blade dmg on ground
(reinforcements)
10 Units with each 20 blade dmg on ground => 700 blade dmg total
--------------------------------------------------------------------------
130 units with 1750 dmg total

Now, my first idea was to get the damage per units, which here would be:
Defender receives:
7.7 pierce dmg per unit
5.8 blade dmg per unit
7.7 impact dmg per unit

Attacker receives:
6.2 pierce dmg per unit
4.1 blade dmg per unit

Now for the casualties:
Defenders casualties:
(7.7 + 5.8 + 7.7) * 20 * 0.6 => 254 dmg total received in tower
(7.7 + 5.8 + 7.7) * 50 * 0.8 => 848 dmg total received on walls
(7.7 + 5.8 + 7.7) * 50 =>1060 dmg total received on ground

Attacker casualties:
(6.2 + 4.1) * 100 => 1030 dmg received
(6.2 + 4.1) * 50 => 515 dmg received
(6.2 + 4.1) * 20 => 206 dmg received

Hmm, while I'm typing this I begin to think this isn't too bad of an idea... maybe a bit unrealistiv but certainly useable.
As a sidenote: Resistance for each type aren't included. They would be applied inside the brackets to the corresponding damage type.

But I still got some more questions:
How should the database look like?
Should I just make a table called 'attacks' with one field for each possible unit and the amount of units therein? What if I wanted to add research levels to boost the units? So for 6 units I would need 6 unit fields plus 6 research fields (one for each unit).
Probably the same for defending units, hm? Yeah, most probably.

How should I store differen units in the tower?
This still concerns the database-structure: How should I store my units in the tower, on the wall and on the ground?
Should I make a table called 'locations' which includes the fields 'player', 'location', 'unit', 'amount'? And then just loop through each entry for the corresponding player?

Well another question:
What should the flow of battle look like?
I figured:
- Get amount of units killed in the traps (maybe let traps do damage instead of killing whole units)
- Get supporting units
- Get defending units
- Get attacking units
- Get offensive strength
- Get defensive strength
- Calculate casualties for defending units
- Calculate casualties for supporting units
- Calculate casualties for attacking units
- Get winner
- Get spoils
- Make battle-report
- Send battle-repost

Or would you suggest any other battle-cycle?

Ow, another question: How should the winner be determined? The one with more power is the winner?
And how should the spoils be calculated? Winner takes it all, dependant on the power-difference, or maybe each unit can carry a certain amount?
And should there be a random element? For example attacking and defending power can vary between +12.5% and -12.5%?

Yeah, I'd really appreciate comments on this and some input.

- Sinzygy

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Battle Script the 2nd
« Reply #1 on: March 18, 2007, 08:54:58 AM »
Quote
How should I divide up the damage taken by each group of units?
This is really is up to you.. I would go with what you have and then tweak as necessary in alpha/beta testing. Just get the system working and start tweaking from there.

Quote
How should the database look like?
Without really knowing more details and off the top of my head I would say this would call for a 1 to many table relationship. For each player they would have many entries in the attack table with the research units ect. Now when a battle is fought you may want a "snapshot" of what went on, not only for your players but for yourself so you can see what each player had at the time of the attack. So you would add up all your research units for each side then create a table called attack_log and summerize the data gathered in the attack log there. Then when the attack is over and either the defender or attacker changes something (gets more units or whatever) the attack_log will still show the correct information.

Quote
How should I store differen units in the tower?
Yup, sounds about right. If you are just adding a sum of a field or fields instead of looping you could execute a GROUP BY query to perform the sums via the database.. As an example

SELECT SUM(amount) FROM player_units WHERE playerid = $playerid GROUP BY units

Quote
What should the flow of battle look like?
Looks good.. Might not be correct from a player stand point but nonetheless at this point its a solid battle flow. Once you release it to real players though they may have some better ideas they would like to see ;)

The last few questions have to deal with outcomes of a battle and how to calculate them.. This is something I've personally struggled with since I started writing online games back in the old BBS days :) You name a battle system give it the old D&D formula, advance D&D, d20, fudge dice system, you name it I've tried it. Finding that perfect formula for a battle outcome is not easy. Personally I like a little random, without a random what you'll get is the king of the hill scenario.. Where the first one out of the gate, that gets the most powerful will stay the most powerful though out the game. Adding a little random allows for a fudge factor so maybe a person can battle a person a little more powerful and win. On the flip side player's don't like a lot of random either so this is the tight rope to walk when designing a battle system.. Lately I've been using a simple odds engine that seems to be working pretty well.

Attacker is 100% more powerful then defender: 95% chance attacker wins
Attacker is 50% more powerful then defender: 75% chance attacker wins
Attacker is more powerful then defender: 65% chance attacker wins
Attacker is equal to defender: 50% chance win
Attacker is less powerful then defender: 35% chance attacker wins
Attacker is 50% less powerful then defender: 25% chance attacker wins
Attacker is 100% less powerful then defender: 5% chance attacker wins

Hope this helps ya out a bit...
« Last Edit: March 18, 2007, 08:59:12 AM by codestryke »
Creating online addictions, one game at a time:

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Battle Script the 2nd
« Reply #2 on: March 18, 2007, 03:46:32 PM »
Quote
How should I store differen units in the tower?
Yup, sounds about right. If you are just adding a sum of a field or fields instead of looping you could execute a GROUP BY query to perform the sums via the database.. As an example

SELECT SUM(amount) FROM player_units WHERE playerid = $playerid GROUP BY units

Oooh...nice. I didn't know that GROUP BY command. I will try this as soon as I'm back to coding.

Quote
What should the flow of battle look like?
Looks good.. Might not be correct from a player stand point but nonetheless at this point its a solid battle flow. Once you release it to real players though they may have some better ideas they would like to see ;)

The last few questions have to deal with outcomes of a battle and how to calculate them.. This is something I've personally struggled with since I started writing online games back in the old BBS days :) You name a battle system give it the old D&D formula, advance D&D, d20, fudge dice system, you name it I've tried it. Finding that perfect formula for a battle outcome is not easy. Personally I like a little random, without a random what you'll get is the king of the hill scenario.. Where the first one out of the gate, that gets the most powerful will stay the most powerful though out the game. Adding a little random allows for a fudge factor so maybe a person can battle a person a little more powerful and win. On the flip side player's don't like a lot of random either so this is the tight rope to walk when designing a battle system.. Lately I've been using a simple odds engine that seems to be working pretty well.

Attacker is 100% more powerful then defender: 95% chance attacker wins
Attacker is 50% more powerful then defender: 75% chance attacker wins
Attacker is more powerful then defender: 65% chance attacker wins
Attacker is equal to defender: 50% chance win
Attacker is less powerful then defender: 35% chance attacker wins
Attacker is 50% less powerful then defender: 25% chance attacker wins
Attacker is 100% less powerful then defender: 5% chance attacker wins

This might even work out quite well. I think I'll give it a try.
Are you doing this simply with if/else (or switch) statements, or are you using a "pseudo-weighted" script? (Sorry, too tired to think atm)

Hope this helps ya out a bit...

It sure does! Thanks a lot.

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Battle Script the 2nd
« Reply #3 on: March 18, 2007, 07:08:15 PM »
I'm using just a  if/elseif statement to handle it.. If you wanted to further "fine tune" that logic like say add another 4-6 conditionals then I would make it a switch statement.
Creating online addictions, one game at a time:

Offline Shapulin

  • Level 9
  • *
  • Posts: 50
  • Reputation: +2/-4
    • View Profile
Re: Battle Script the 2nd
« Reply #4 on: May 08, 2007, 10:42:29 AM »
and something like an "atack strategy".... some rutine like

defense = 2 turns              "list box"
atack = 3 turns                  "list box"
evasive action = 2 turns     "list box"

and of course the player can chose the turns destined to each stage of a battle...

with this not only the power can interfer...some weak oponent can equal forces with a powerfull enemy if the strategy doesnt work

in the inform the "battle modes" can be seen so i can say "damn....I pick the wrong strategy...this puny human won a battle i got for sure"

and with this is made the ciclic rutine....

if a player star with defense and other with attack, the attack cause least damage....

and evasive action made that and attack cause more damage than with defense but least than in attack mode...

something like "han ken pon"

while I got resources and energy, i mantaine the cycle


so....the player can be knowned by his battle strategies

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal