Create a battle in state 'initiating' for attackers and defenders to join.
- <attacking faction>
- <planet id>
Assault is valid when:
- The assaulted planet is in reach. This is the case when
- the attacking faction governs a planet of this sun system or
- there are one or more sun systems connected to the planets sun system where attacking faction has 100% influence.
- Planets government must be different from attacking faction.
SELECT COUNT(*) FROM planets AS destination JOIN planets AS source
ON destination.fk_sun_system = source.fk_sun_system AND destination.id = source.id
WHERE destination.id = <planet id> AND
( SELECT winning_faction FROM battle WHERE fk_planet = source.id ORDER BY ended_at DESC LIMIT 1 ) = <attacking faction>
(SELECT( SELECT winning_faction FROM battles WHERE fk_planet = outer_planets .id ORDER BY ended_at DESC LIMIT 1 ) FROM planets AS outer_planets WHERE outer_planets .fk_sun_system = links.fk_sun_system_from)
SELECT COUNT(id) FROM planets AS outer_planets_total WHERE outer_planets_total .fk_sun_system = links.fk_sun_system_from
JOIN quantum_gate_links AS link
ON planets.fk_sun_system = links.fk_sun_system_to
WHERE planets.id = <planet id>
SELECT winning_faction FROM battle WHERE fk_planet = planets.id ORDER BY ended_at DESC LIMIT 1
Store winning_faction in <defending faction>
ASSERT THAT <attacking faction> != <defending faction>
INSERT INTO battles (fk_planet, status, intiated_at, attacking_faction, defending_faction), (<planet id>, 'I', NOW(), <attacking_faction>, <defending faction>)