[Add] Improved xml #define magic stuff.

This commit is contained in:
Allanis 2013-05-08 18:49:24 +01:00
parent 3a8a9028d3
commit c609780acc
7 changed files with 144 additions and 108 deletions

View File

@ -66,7 +66,7 @@ function create()
misn_setTitle(string.format(title[i+21], carg_type, planet)) misn_setTitle(string.format(title[i+21], carg_type, planet))
end end
-- More mission specifics -- More mission specifics.
if misn_type == "Cargo" or misn_type == "Rush" then if misn_type == "Cargo" or misn_type == "Rush" then
carg_mass = rnd.int(10, 30) carg_mass = rnd.int(10, 30)
i = rnd.int(12) -- Set the goods. i = rnd.int(12) -- Set the goods.
@ -104,18 +104,18 @@ function create()
misn.setReward(string.format(misn_reward, reward)) misn.setReward(string.format(misn_reward, reward))
end end
-- Mission is accepted -- Mission is accepted.
function accept() function accept()
if player.freeCargo() < carg_mass then if player.freeCargo() < carg_mass then
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo())) tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo()))
elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
carg_id = player.addCargo(carg_type, carg_mass) carg_id = player.addCargo(carg_type, carg_mass)
tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type)) tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type))
-- Set the hooks -- Set the hooks.
hook.land( "land" ) -- Only hook after accepting hook.land("land") -- Only hook after accepting.
if misn_type == "Rush" then -- Rush needs additional time hook if misn_type == "Rush" then -- Rush needs additional time hook.
hook.time("timeup") hook.time("timeup")
end end
else else
@ -123,7 +123,7 @@ function accept()
end end
end end
-- Land hook -- Land hook.
function land() function land()
if space.landName() == planet then if space.landName() == planet then
if player.rmCargo(carg_id) then if player.rmCargo(carg_id) then
@ -136,7 +136,7 @@ function land()
end end
end end
-- Time hook -- Time hook.
function timeup() function timeup()
if time.get() > misn_time then if time.get() > misn_time then
player.msg(misn_time_msg) player.msg(misn_time_msg)

View File

@ -1,7 +1,7 @@
lang = lephisto.lang() lang = lephisto.lang()
if lang == "es" then if lang == "es" then
-- Not translated atm -- Not translated atm.
else -- Default english else -- Default english.
misn_title = "Empire Recruitment" misn_title = "Empire Recruitment"
misn_reward = "%d credits" misn_reward = "%d credits"
misn_desc = "Deliver some parcels for the Empire to %s." misn_desc = "Deliver some parcels for the Empire to %s."
@ -20,23 +20,23 @@ You aren't too sure of what to make of your encounter with the Empire, only time
end end
function create() function create()
-- Intro text -- Intro text.
tk.msg(title[1], text[1]) tk.msg(title[1], text[1])
if tk.yesno(title[1], text[2]) if tk.yesno(title[1], text[2])
then then
misn.accept() misn.accept()
dest = space.getPlanet("Empire"); dest = space.getPlanet("Empire");
-- Mission details -- Mission details.
reward = 3000 reward = 3000
misn.setTitle(misn_title) misn.setTitle(misn_title)
misn.setReward(string.format(misn_reward, reward)) misn.setReward(string.format(misn_reward, reward))
misn.setDesc(string.format(misn_desc,dest)) misn.setDesc(string.format(misn_desc,dest))
-- Flavour text and mini-briefing -- Flavour text and mini-briefing.
tk.msg(title[2], string.format( text[3], dest)) tk.msg(title[2], string.format( text[3], dest))
-- Set up the goal -- Set up the goal.
parcels = player.addCargo("Parcels", 0) parcels = player.addCargo("Parcels", 0)
hook.land("land") hook.land("land")
end end
@ -46,7 +46,7 @@ function land()
if space.landName() == dest then if space.landName() == dest then
if player.rmCargo(parcels) then if player.rmCargo(parcels) then
player.pay(reward) player.pay(reward)
-- More flavour text -- More flavour text.
tk.msg(title[3], string.format(text[4], dest)) tk.msg(title[3], string.format(text[4], dest))
var.push("es_cargo", true) var.push("es_cargo", true)
misn.finish(true) misn.finish(true)

View File

@ -1,7 +1,7 @@
lang = lephisto.lang() lang = lephisto.lang()
if lang == "es" then if lang == "es" then
-- Not translated atm -- Not translated atm.
else -- Default english else -- Default english.
misn_title = "Collective Scout" misn_title = "Collective Scout"
misn_reward = "" misn_reward = ""
misn_desc = {} misn_desc = {}
@ -23,7 +23,7 @@ else -- Default english
end end
function create() function create()
-- Intro text -- Intro text.
if tk.yesno(title[1], string.format(text[1], player.name())) if tk.yesno(title[1], string.format(text[1], player.name()))
then then
misn.accept() misn.accept()
@ -34,12 +34,12 @@ function create()
misn_base = "Omega Station" misn_base = "Omega Station"
misn_base_sys = "NCG-7291" misn_base_sys = "NCG-7291"
-- Mission details -- Mission details.
misn.setTitle(misn_title) misn.setTitle(misn_title)
misn.setReward(misn_reward) misn.setReward(misn_reward)
misn.setDesc(string.format(misn_desc[1],misn_nearby)) misn.setDesc(string.format(misn_desc[1],misn_nearby))
-- Flavour text and mini-briefing -- Flavour text and mini-briefing.
tk.msg(title[2], string.format(text[2], misn_nearby, misn_base, misn_base_sys)) tk.msg(title[2], string.format(text[2], misn_nearby, misn_base, misn_base_sys))
hook.enter("enter") hook.enter("enter")
@ -50,8 +50,8 @@ end
function enter() function enter()
sys = space.system() sys = space.system()
-- Additional fleets -- Additional fleets.
if sys == "NCG-7291" then -- Increase action for realism if sys == "NCG-7291" then -- Increase action for realism.
pilot.add("Empire Sml Defense") pilot.add("Empire Sml Defense")
pilot.add("Collective Sml Swarm") pilot.add("Collective Sml Swarm")
elseif sys == misn_target then elseif sys == misn_target then
@ -61,7 +61,7 @@ function enter()
end end
end end
-- update mission -- update mission.
if misn_stage == 0 and sys == misn_target then if misn_stage == 0 and sys == misn_target then
misn.setDesc(string.format(misn_desc[2],misn_base,misn_base_sys)) misn.setDesc(string.format(misn_desc[2],misn_base,misn_base_sys))
misn_stage = 1 misn_stage = 1

View File

@ -1,7 +1,7 @@
lang = lephisto.lang() lang = lephisto.lang()
if lang == "es" then if lang == "es" then
-- Not translated atm -- Not translated atm.
else -- Default english else -- Default english.
misn_desc = "The Empire needs to ship %d tons of %s to %s in the %s system by %s (%s left)." misn_desc = "The Empire needs to ship %d tons of %s to %s in the %s system by %s (%s left)."
misn_reward = "%d credits" misn_reward = "%d credits"
title = {} title = {}
@ -20,30 +20,30 @@ else -- Default english
miss_timeup = "MISSION FAILED: You have failed to deliver the goods to the Empire on time!" miss_timeup = "MISSION FAILED: You have failed to deliver the goods to the Empire on time!"
end end
-- Empire shipping missions are always timed, but quite lax on the schedules -- Empire shipping missions are always timed, but quite lax on the schedules.
-- pays a bit more then the rush missions -- Pays a bit more then the rush missions.
-- Create the mission -- Create the mission.
function create() function create()
-- Target destination -- Target destination.
local i = 0 local i = 0
repeat repeat
planet = space.getPlanet(misn.factions()) planet = space.getPlanet(misn.factions())
i = i + 1 i = i + 1
until planet ~= space.landName() or i > 10 until planet ~= space.landName() or i > 10
-- Infinite loop protection -- Infinite loop protection.
if i > 10 then if i > 10 then
misn.finish(false) misn.finish(false)
end end
system = space.getSystem( planet ) system = space.getSystem( planet )
misn_dist = space.jumpDist(system) misn_dist = space.jumpDist(system)
-- Mission generics -- Mission generics.
misn_type = "Cargo" misn_type = "Cargo"
i = rnd.int(1) i = rnd.int(1)
misn.setTitle(string.format(title[i+1], planet)) misn.setTitle(string.format(title[i+1], planet))
-- More mission specifics -- More mission specifics.
carg_mass = rnd.int(10, 30) carg_mass = rnd.int(10, 30)
i = rnd.int(12) i = rnd.int(12)
if i < 5 then if i < 5 then
@ -68,28 +68,28 @@ function create()
misn.setReward(string.format( misn_reward, reward)) misn.setReward(string.format( misn_reward, reward))
end end
-- Mission is accepted -- Mission is accepted.
function accept() function accept()
if player.freeCargo() < carg_mass then if player.freeCargo() < carg_mass then
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo())) tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo()))
elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
carg_id = player.addCargo(carg_type, carg_mass) carg_id = player.addCargo(carg_type, carg_mass)
tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type)) tk.msg(accept_title, string.format( accept_msg, carg_mass, carg_type))
hook.land( "land" ) -- Only hook after accepting hook.land("land") -- Only hook after accepting.
hook.time("timeup") hook.time("timeup")
else else
tk.msg(toomany_title, toomany_msg) tk.msg(toomany_title, toomany_msg)
end end
end end
-- Land hook -- Land hook.
function land() function land()
if space.landName() == planet then if space.landName() == planet then
if player.rmCargo(carg_id) then if player.rmCargo(carg_id) then
player.pay(reward) player.pay(reward)
tk.msg(finish_title, string.format(finish_msg, carg_type)) tk.msg(finish_title, string.format(finish_msg, carg_type))
-- Increase empire shipping mission counter -- Increase empire shipping mission counter.
n = var.peek("es_misn") n = var.peek("es_misn")
if n ~= nil then if n ~= nil then
var.push("es_misn", n+1) var.push("es_misn", n+1)
@ -104,7 +104,7 @@ function land()
end end
end end
-- Time hook -- Time hook.
function timeup() function timeup()
if time.get() > misn_time then if time.get() > misn_time then
player.msg(miss_timeup) player.msg(miss_timeup)

View File

@ -29,7 +29,7 @@ int pilots = 0;
static int mpilots = 0; static int mpilots = 0;
extern Pilot* player; extern Pilot* player;
extern unsigned int combat_crating; extern unsigned int player_crating;
// Stack of fleets. // Stack of fleets.
static Fleet* fleet_stack = NULL; static Fleet* fleet_stack = NULL;
@ -261,7 +261,7 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
if(!pilot_isFlag(p, PILOT_DEAD)) { if(!pilot_isFlag(p, PILOT_DEAD)) {
pilot_dead(p); pilot_dead(p);
// Adjust the combat rating based on pilot mass. // Adjust the combat rating based on pilot mass.
if(shooter == PLAYER_ID) combat_crating += MAX(1, p->ship->mass/50); if(shooter == PLAYER_ID) player_crating += MAX(1, p->ship->mass/50);
} }
} }

View File

@ -44,7 +44,7 @@ static char** player_lstack = NULL; // Names of the planet the ships are at.
static int player_nstack = 0; static int player_nstack = 0;
// Player global properties. // Player global properties.
char* player_name = NULL; // Player name. char* player_name = NULL; // Player name.
int combat_crating = 0; // Ze rating. int player_crating = 0; // Ze rating.
unsigned int player_flags = 0; // Player flags. unsigned int player_flags = 0; // Player flags.
// Input.c // Input.c
double player_turn = 0.; // Turn velocity from input. double player_turn = 0.; // Turn velocity from input.
@ -197,8 +197,8 @@ static void player_newMake(void) {
// MONIEZZ!!!! -- We call these SCred AKA SaraCred. Lame right? // MONIEZZ!!!! -- We call these SCred AKA SaraCred. Lame right?
tmp = cur->children; tmp = cur->children;
do { do {
if(xml_isNode(tmp, "low")) l = xml_getInt(tmp); xmlr_int(tmp, "low", l);
else if(xml_isNode(tmp, "high")) h = xml_getInt(tmp); xmlr_int(tmp, "high", h);
} while(xml_nextNode(tmp)); } while(xml_nextNode(tmp));
} }
else if(xml_isNode(cur, "system")) { else if(xml_isNode(cur, "system")) {
@ -207,18 +207,16 @@ static void player_newMake(void) {
// System name. TODO: Chance based on percentage. // System name. TODO: Chance based on percentage.
if(xml_isNode(tmp, "name")) snprintf(system, 20, xml_get(tmp)); if(xml_isNode(tmp, "name")) snprintf(system, 20, xml_get(tmp));
// Position. // Position.
else if(xml_isNode(tmp, "x")) x = xml_getFloat(tmp); xmlr_float(tmp, "x", x);
else if(xml_isNode(tmp, "y")) y = xml_getFloat(tmp); xmlr_float(tmp, "y", y);
} while(xml_nextNode(tmp)); } while(xml_nextNode(tmp));
} }
else if(xml_isNode(cur, "combat_crating")) xmlr_int(cur, "player_crating", player_crating);
combat_crating = xml_getInt(cur); if(xml_isNode(cur, "date")) {
else if(xml_isNode(cur, "date")) {
tmp = cur->children; tmp = cur->children;
do { do {
if(xml_isNode(tmp, "low")) tl = xml_getInt(tmp); xmlr_int(tmp, "low", tl);
else if(xml_isNode(tmp, "high")) th = xml_getInt(tmp); xmlr_int(tmp, "high", th);
} while(xml_nextNode(tmp)); } while(xml_nextNode(tmp));
} }
} while((cur = cur->next)); } while((cur = cur->next));
@ -387,13 +385,13 @@ static char* player_ratings[] = {
}; };
const char* player_rating(void) { const char* player_rating(void) {
if(combat_crating == 0) return player_ratings[0]; if(player_crating == 0) return player_ratings[0];
else if(combat_crating < 50) return player_ratings[1]; else if(player_crating < 50) return player_ratings[1];
else if(combat_crating < 200) return player_ratings[2]; else if(player_crating < 200) return player_ratings[2];
else if(combat_crating < 500) return player_ratings[3]; else if(player_crating < 500) return player_ratings[3];
else if(combat_crating < 1000) return player_ratings[4]; else if(player_crating < 1000) return player_ratings[4];
else if(combat_crating < 2500) return player_ratings[5]; else if(player_crating < 2500) return player_ratings[5];
else if(combat_crating < 10000) return player_ratings[6]; else if(player_crating < 10000) return player_ratings[6];
else return player_ratings[7]; else return player_ratings[7];
} }

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "libxml/parser.h" #include "libxml/parser.h"
#include "libxml/xmlwriter.h"
#include "log.h"
#define XML_NODE_START 1 #define XML_NODE_START 1
#define XML_NODE_TEXT 3 #define XML_NODE_TEXT 3
@ -20,3 +23,38 @@
#define xml_getInt(n) (atoi((char*)(n)->children->content)) #define xml_getInt(n) (atoi((char*)(n)->children->content))
#define xml_getFloat(n) (atof((char*)(n)->children->content)) #define xml_getFloat(n) (atof((char*)(n)->children->content))
// Reader crap.
#define xmlr_int(n,s,i) \
if(xml_isNode(n,s)) { i = xml_getInt(n); continue; }
#define xmlr_float(n,s,f) \
if(xml_isNode(n,s)) { f = xml_getFloat(n); continue; }
// Writer crap.
// Encompassing element.
#define xmlw_startElem(w, str) \
if(xmlTextWriterStartElement(w, str) < 0) { \
ERR("xmlw: Unable to create start element"); return -1; }
#define xmlw_endElem(w) \
if(xmlTextWriterEndElement(w) < 0) { \
ERR("xmlw: Unable to create end element"); return -1; }
// Other stuff.
#define xmlw_elem(w, n, str, args...) \
if(xmlTextWriteFormatElement(w, n, str, ## args) < 0) { \
ERR("xmlw: Unable to write format element"); return -1; }
#define xmlw_attr(w, str, val) \
if(xmlTextWriteAttribute(w, str, val) < 0) { \
ERR("xmlw: Unable to write element attribute"); return -1; }
// Document level.
#define xmlw_start(w) \
if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) { \
ERR("xmlw: Unable to start document"); return -1; }
#define xmlw_done(w) \
if(xmlTextWriterEndDocument(w) < 0) { \
ERR("xmlw: Unable to end document"); return -1; }