[Change] Missions increase/lower faction standing. Fixed bug with factions.

This commit is contained in:
Allanis 2013-05-23 16:17:53 +01:00
parent d6f266323f
commit 71b68003f9
8 changed files with 66 additions and 1 deletions

View File

@ -47,13 +47,16 @@ function create()
i = rnd.int(6) i = rnd.int(6)
if i < 4 then -- Cargo delivery. if i < 4 then -- Cargo delivery.
misn_type = "Cargo" misn_type = "Cargo"
misn.faction = rnd.int(2)
i = rnd.int(3) i = rnd.int(3)
misn.setTitle(string.format(title[i+1], planet)) misn.setTitle(string.format(title[i+1], planet))
elseif i < 6 then-- Rush delivery. elseif i < 6 then-- Rush delivery.
misn_type = "Rush" misn_type = "Rush"
misn.faction = rnd.int(5)
misn.setTitle(string.format(title[11], planet)) misn.setTitle(string.format(title[11], planet))
else -- People delivery :P else -- People delivery :P
misn_type = "People" misn_type = "People"
misn.faction = rnd.int(1)
carg_mass = 0 carg_mass = 0
i = rnd.int(5) i = rnd.int(5)
if i < 2 then if i < 2 then
@ -132,6 +135,18 @@ function land()
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))
-- Modify the faction standing.
if player.getFaction("Merchant") < 70 then
player.modFaction("Merchant", misn_faction)
end
if player.getFaction("Independent") < 30 then
player.modFaction("Independent", misn_faction/2)
end
if player.getFaction("Empire") < 10 then
player.modFaction("Empire", misn_faction/3)
end
misn.finish(true) misn.finish(true)
else else
tk.msg(miss_title, string.format( miss_msg, carg_mass, carg_type)) tk.msg(miss_title, string.format( miss_msg, carg_mass, carg_type))

View File

@ -49,6 +49,7 @@ function land()
-- 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)
player.modFaction("Empire", 3)
misn.finish(true) misn.finish(true)
end end
end end

View File

@ -73,6 +73,7 @@ function land()
if misn_stage == 1 and planet == misn_base then if misn_stage == 1 and planet == misn_base then
tk.msg(title[3], string.format(text[3],misn_target)) tk.msg(title[3], string.format(text[3],misn_target))
player.modFaction("Empire", 5)
misn.finish(true) misn.finish(true)
end end
end end

View File

@ -99,6 +99,11 @@ function land()
var.push("es_misn", 1) var.push("es_misn", 1)
end end
-- Increase faction.
if player.getFaction("Empire") < 50 then
player.modFaction("Empire", rnd.int(5))
end
misn.finish(true) misn.finish(true)
else else
tk.msg(miss_title, string.format( miss_msg, carg_mass, carg_type)) tk.msg(miss_title, string.format( miss_msg, carg_mass, carg_type))

View File

@ -103,6 +103,17 @@ void faction_modPlayer(int f, int mod) {
} }
} }
int faction_getPlayer(int f) {
if(faction_isFaction(f)) {
if(faction_isFaction(f)) {
return faction_stack[f].player;
}
} else {
DEBUG("%d is an invalid faction/alliance", f);
return -1000;
}
}
// Return 1 if Faction a and b are enemies. // Return 1 if Faction a and b are enemies.
int areEnemies(int a, int b) { int areEnemies(int a, int b) {
Faction* fa, *fb; Faction* fa, *fb;

View File

@ -9,6 +9,7 @@ char* faction_name(int f);
// Player stuff. // Player stuff.
void faction_modPlayer(int f, int mod); void faction_modPlayer(int f, int mod);
int faction_getPlayer(int f);
// Works with only factions. // Works with only factions.
int areEnemies(int a, int b); int areEnemies(int a, int b);

View File

@ -128,6 +128,8 @@ static int player_addCargo(lua_State* L);
static int player_rmCargo(lua_State* L); static int player_rmCargo(lua_State* L);
static int player_pay(lua_State* L); static int player_pay(lua_State* L);
static int player_msg(lua_State* L); static int player_msg(lua_State* L);
static int player_modFaction(lua_State* L);
static int player_getFaction(lua_State* L);
static const luaL_reg player_methods[] = { static const luaL_reg player_methods[] = {
{ "name", player_getname }, { "name", player_getname },
{ "ship", player_shipname }, { "ship", player_shipname },
@ -136,6 +138,8 @@ static const luaL_reg player_methods[] = {
{ "rmCargo", player_rmCargo }, { "rmCargo", player_rmCargo },
{ "pay", player_pay }, { "pay", player_pay },
{ "msg", player_msg }, { "msg", player_msg },
{ "modFaction", player_modFaction },
{ "getFaction", player_getFaction },
{ 0, 0 } { 0, 0 }
}; };
@ -768,6 +772,32 @@ static int player_msg(lua_State* L) {
return 0; return 0;
} }
static int player_modFaction(lua_State* L) {
MIN_ARGS(2);
int f, mod;
if(lua_isstring(L, -2)) f = faction_get(lua_tostring(L, -2));
else MISN_INVALID_PARAMETER();
if(lua_isnumber(L, -1)) mod = (int)lua_tonumber(L, -1);
else MISN_INVALID_PARAMETER();
faction_modPlayer(f, mod);
return 0;
}
static int player_getFaction(lua_State* L) {
MIN_ARGS(1);
int f;
if(lua_isstring(L, -1)) f = faction_get(lua_tostring(L, -1));
else MISN_INVALID_PARAMETER();
lua_pushnumber(L, faction_getPlayer(f));
return 1;
}
// -- RND. -- // -- RND. --
static int rnd_int(lua_State* L) { static int rnd_int(lua_State* L) {
int o; int o;

View File

@ -322,7 +322,8 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer) {
// Someone should let the ai know it's been attacked. // Someone should let the ai know it's been attacked.
if(!pilot_isPlayer(p)) { if(!pilot_isPlayer(p)) {
if((player_target == p->id) || (RNG(0,2) == 0)) { if((player_target == p->id) || (RNG(0,2) == 0)) {
if(pilot_isFlag(p, PILOT_HOSTILE) || (RNG(0, 2) == 0)) if((w->parent == PLAYER_ID) &&
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNG(0, 2) == 0)))
faction_modPlayer(p->faction, -1); // Slowly lower faction. faction_modPlayer(p->faction, -1); // Slowly lower faction.
ai_attacked(p, w->parent); ai_attacked(p, w->parent);
} }