From d246c2cbe275c74e3fc8500588b7d55c3d61308b Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 13 Mar 2013 22:39:52 +0000 Subject: [PATCH] [Add] More thingies.. Factions!! --- dat/faction.xml | 26 +++++++++++++++++--- dat/fleet.xml | 24 +++++++++++++++--- dat/ssys.xml | 23 +++++++++++++++++ scripts/ai/collective.lua | 52 +++++++++++++++++++++++++++++++++++++++ src/map.c | 3 ++- src/space.c | 6 ++++- src/space.h | 2 ++ 7 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 scripts/ai/collective.lua diff --git a/dat/faction.xml b/dat/faction.xml index 3391bc3..2db1e22 100644 --- a/dat/faction.xml +++ b/dat/faction.xml @@ -10,20 +10,40 @@ + + + + Independent Merchant Militia + + Empire + Merchant + - Neutral - Pirate - + Collective + Neutral + + + Collective + Player + + + Neutral + Pirate + + Empire United Pirate + + + Pirate Player diff --git a/dat/fleet.xml b/dat/fleet.xml index 082ed17..43a29de 100644 --- a/dat/fleet.xml +++ b/dat/fleet.xml @@ -25,10 +25,7 @@ merchant Merchant - Merchant Ship - Merchant Ship - Merchant Mule - Merchant Mule + Merchant Ship @@ -40,4 +37,23 @@ Leapard + + collective + Collective + + Drone + + + + collective + Collective + + Drone + Drone + Drone + Drone + Drone + Drone + + diff --git a/dat/ssys.xml b/dat/ssys.xml index f667698..dd775ed 100644 --- a/dat/ssys.xml +++ b/dat/ssys.xml @@ -94,6 +94,29 @@ NCG-7291 + C-59 + + + + + 90 + 50 + + + 200 + 0 + 0 + + + + + Collective Drone + Collective Drone + Collective Drone + Collective Sml Swarm + + + NCG-7292 diff --git a/scripts/ai/collective.lua b/scripts/ai/collective.lua new file mode 100644 index 0000000..6bdc98a --- /dev/null +++ b/scripts/ai/collective.lua @@ -0,0 +1,52 @@ +-- Required control rate. +control_rate = 2 + +function control() + if ai.taskname() == "none" then + enemy = ai.getenemy() + + if enemey ~= 0 then + ai.pushtask(0, "attack", enemy) + end + end +end + +-- Required "attacked" function. +function attacked(attacker) + task = ai.taskname() + if task ~= "attack" then + -- Now pilot fights back. + ai.pushtask(0, "attack", attacker) + + elseif task == "attack" then + if ai.targetid() ~= attacker then + ai.pushtask(0, "attack", attacker) + end + end +end + +function attack() + target = ai.targetid() + + -- Make sure pilot exists. + if not ai.exists(target) then + ai.poptask() + return + end + + dir = ai.face(target) + dist = ai.dist(ai.pos(target)) + second = ai.secondary() + + if ai.secondary() == "Launcher" then + ai.settarget(target) + is.shoot(2) + end + + if dir < 10 and dist > 300 then + ai.accel() + elseif dir < 10 and dist < 300 then + ai.shoot() + end +end + diff --git a/src/map.c b/src/map.c index 84deca4..63e2d30 100644 --- a/src/map.c +++ b/src/map.c @@ -152,7 +152,8 @@ static void map_render(double bx, double by, double w, double h) { // Draw the system. if(sys == cur_system) COLOUR(cRadar_targ); - else if(sys->nplanets == 0) COLOUR(cInert); + else if(sys->nplanets==0) COLOUR(cInert); // TODO: dependant on planet type. + else if(areEnemies(player->faction, sys->faction)) COLOUR(cRed); else COLOUR(cYellow); gl_drawCircleInRect(x + sys->pos.x*map_zoom, diff --git a/src/space.c b/src/space.c index 7389d3d..5adc680 100644 --- a/src/space.c +++ b/src/space.c @@ -479,7 +479,11 @@ static StarSystem* system_parse(const xmlNodePtr parent) { MELEMENT(flags&FLAG_ASTEROIDSSET, "asteroids"); // Can be 0. MELEMENT(flags&FLAG_INTEFERENCESET, "inteference"); #undef MELEMENT - + + // Post processing. + if(tmp->nplanets > 0) + // TODO: Make dependant on overall planet faction. + tmp->faction = tmp->planets[0].faction; return tmp; } diff --git a/src/space.h b/src/space.h index e3ce525..a8bf050 100644 --- a/src/space.h +++ b/src/space.h @@ -67,6 +67,8 @@ typedef struct StarSystem_ { int stars, asteroids; // Un numero! double interference; // Un uh.. Percentage. + Faction* faction; // Overall faction. + Planet* planets; // Planets. int nplanets; // Total number of planets.