Faction initiates assault

Submitted by Brutus5000 on Fri, 07/22/2016 - 09:29
Goal

Create a battle in state 'initiating' for attackers and defenders to join.

Input data
  • <attacking faction>
  • <planet id>
Preconditions

Assault is valid when:

  1. 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.
  2. Planets government must be different from attacking faction.

 

CHECK 1.a)

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>

 

CHECK 1.b)

SELECT (

(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


)
FROM planets
JOIN quantum_gate_links  AS link
ON planets.fk_sun_system = links.fk_sun_system_to
WHERE planets.id = <planet id>

 

CHECK 2.)

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>

 

Database transaction

INSERT INTO battles (fk_planet, status, intiated_at, attacking_faction, defending_faction), (<planet id>, 'I', NOW(), <attacking_faction>, <defending faction>)

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.