SteemNova is based on 2Moons Open Source Browsergame Framework. The framework's goal is to be as much similar to Ogame mechanics as possible. Most important here is battle engine which is very simplified and inaccurate to online Ogame calculators. This contribution describes how it is rewritten from the scratch for SteemNova uses.
True random shots and 1v1 fights
What original engine lacked most was the randomness of each fire and how it penetrates enemy hulls. The units were grouped to each ship class like Cruisers, Little Fighters, Battleships etc. Then this whole group shot at enemy group of ships, calculating damage as firepower - (shield + armor).
New engine takes each ship independent. It chooses true rand() enemy unit and proceed to next ship. This way every battle has a little random factor and can result different.
$victimFleetId = array_rand($defenders)
$victimShipId = rand(0, count($victimFleet['units'])-1)
The radomness grows high enough so that attack power doesn't vary +/-20% of initial anymore. This improves the calculation speed also.
Separating units from groups is a nerf of shielding system. Right now shields does break for each ship instead of "big summarized shield". It is intended and works much better than in original framework.
For example: old fights needed to destroy shield of EVERY enemy ship to start damaging its' hull. New fights comes with possibility to damage ship just after it's single shield pops!
Armor did regenerate each turn (bug)
There was huge flaw in combat round results. If the ship armor wasn't destroyed completely it regenerated fully into next round fight. This was a huge problem, because if ship wasn't destroyed in one turn, it comes back as fully repaired unit! That flaw is a big advantage to big ships. The bigger the ship, the bigger its armor and the harder it is to destroy it. Top players were flying the galaxies with advantage over younger fleets.
Bounced shots
Vanilla Ogame had something like "bounced shots". If the attack power of assault unit is less than 1% of enemy target ship, then it is considered a miss or a bounce. In the result it does not do any damage. This is best to seen in fights of Little Fighters or Cruisers versus Death Star. They are just too weak to even scratch big giant.
if ($unit['att'] * 100 > $victimShip['shield'])
{
...
}
// else bounced hit (Weaponry of the shooting unit is less than 1% of the Shielding of the target unit)
Chance of exploding damaged unit
The feature of exploding ships is another new one here. It is something hardly anyone Ogame player knows of, but it is specified in combat rules. If ship is damaged for over 30% health, it has chance of exploding in probability of 1 - H/H_i (H_i initial armor). It still can shoot to other units until round ends.
if ($unit['armor'] < 0.7 * $initialArmor)
{
$ran = rand(0, $initialArmor);
if ($ran > $unit['armor'])
{
// explode unit
...
Combat reports doesn't cut randomly (bugfix)
It was common that combat reports didn't show its full history. Sometimes it ended round or a two too early showing bad results. Reports sometimes didn't produce 6th round or final standings after whole fight which was weird. It appeared simple fix had to be given.
foreach($player['unit'] as $ShipID => $Amount)
{
if ($Amount <= 0) {
// $Destroy['def']++; << comment this
continue;
}
Combat engine optimization
All above needed some improvements. Many foreach in foreach consumes a lot of server resources. I was looking for something more efficient than php arrays[]. I have found php-ds extension. It is set of libraries of many data structures for PHP 7. Ds\Map and Ds\Vector was the ones I needed. These structures improved code execution by about 10x factor.
New code engine was tested at up to 500k units battles with success (1 core cpu, <128MB ram usage). For bigger battles better server is needed or improve combat engine optimization.
Install php-ds extension:
apt-get install php-pear php7.0-dev- pecl install ds
- create file
30-ds.iniwith contentextension=ds.soand put in/etc/php/7.0/apache2/conf.d/source
Information
steemnova/steemnova project is fork of jkroepke/2Moons Open Source Browsergame Framework. The goal is to fix bugs and develop the engine in the direction of maximum Steem integration.
Links
- [Pull request] https://github.com/steemnova/steemnova/pull/50
- [Issue] https://github.com/jkroepke/2Moons/issues/334
- [Formulas] http://ogame.wikia.com/wiki/Combat
Posted on Utopian.io - Rewarding Open Source Contributors