17#include "nlua_faction.h"
22#include "nlua_colour.h"
27static LuaFaction luaL_validfactionSilent( lua_State *L,
int ind );
128 const char *s = luaL_checkstring(L,1);
164 lua_rawseti( L, -2, i+1 );
193 return *((LuaFaction*) lua_touserdata(L,ind));
196static LuaFaction luaL_validfactionSilent( lua_State *L,
int ind )
200 else if (lua_isstring(L,ind))
202 luaL_typerror(L, ind, FACTION_METATABLE);
215 int id = luaL_validfactionSilent( L, ind );
217 return NLUA_ERROR(L,_(
"Faction '%s' not found in stack."), lua_tostring(L,ind) );
230 LuaFaction *f = (LuaFaction*) lua_newuserdata(L,
sizeof(LuaFaction));
232 luaL_getmetatable(L, FACTION_METATABLE);
233 lua_setmetatable(L, -2);
247 if (lua_getmetatable(L,ind)==0)
249 lua_getfield(L, LUA_REGISTRYINDEX, FACTION_METATABLE);
252 if (lua_rawequal(L, -1, -2))
275 lua_pushboolean(L, a == b);
391 double n = luaL_checknumber(L,2);
410 double n = luaL_checknumber(L,2);
430 double n = luaL_checknumber(L,2);
447 double n = luaL_checknumber( L, 2 );
468 if (!lua_isnoneornil(L,2))
469 n = luaL_checknumber(L,2);
472 lua_pushnumber( L, n );
488 lua_pushnumber( L, n );
511 lua_rawseti(L,-2,i+1);
536 lua_rawseti(L,-2,i+1);
617 int b = lua_toboolean(L, 2);
669 lua_pushstring(L, tags[i]);
670 lua_pushboolean(L,1);
689 LuaFaction fac, newfac;
690 const char *name, *display, *ai;
691 const glColour *colour;
692 int clear_allies, clear_enemies;
696 if (!lua_isnoneornil(L, 1))
697 fac = luaL_validfactionSilent(L,1);
700 name = luaL_checkstring(L,2);
701 display = luaL_optstring(L,3,name);
708 return NLUA_ERROR(L,_(
"Trying to overwrite existing faction '%s' with dynamic faction!"),name);
715 if (lua_istable(L,4)) {
716 lua_getfield(L,4,
"ai");
717 ai = luaL_optstring(L,-1,NULL);
720 lua_getfield(L,4,
"clear_allies");
721 clear_allies = lua_toboolean(L,-1);
724 lua_getfield(L,4,
"clear_enemies");
725 clear_enemies = lua_toboolean(L,-1);
728 lua_getfield(L,4,
"player");
729 if (lua_isnumber(L,-1)) {
730 player = lua_tonumber(L,-1);
735 lua_getfield(L,4,
"colour");
736 if (lua_isstring(L,-1))
737 colour = col_fromName( lua_tostring(L,-1) );
775 LuaFaction fac, ally;
779 return NLUA_ERROR(L,_(
"Can only add allies to dynamic factions"));
781 remove = lua_toboolean(L,3);
799 LuaFaction fac, enemy;
803 return NLUA_ERROR(L,_(
"Can only add allies to dynamic factions"));
805 remove = lua_toboolean(L,3);
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
const char * faction_longname(int f)
Gets the faction's long name (formal, human-readable).
const glColour * faction_getColour(int f)
Gets the colour of the faction based on it's standing with the player.
int faction_exists(const char *name)
Checks to see if a faction exists by name.
const int * faction_getEnemies(int f)
Gets the list of enemies of a faction.
int faction_dynAdd(int base, const char *name, const char *display, const char *ai, const glColour *colour)
Dynamically add a faction.
void faction_rmAlly(int f, int o)
Removes an ally from the faction's allies list.
int faction_isKnown(int id)
Is the faction known?
const glTexture * faction_logo(int f)
Gets the faction's logo (ideally 256x256).
void faction_clearEnemy(int f)
Clears all the enemies of a dynamic faction.
void faction_rmEnemy(int f, int o)
Removes an enemy from the faction's enemies list.
void faction_setPlayer(int f, double value)
Sets the player's standing with a faction.
int areEnemies(int a, int b)
Checks whether two factions are enemies.
const char * faction_name(int f)
Gets a factions "real" (internal) name.
const char * faction_shortname(int f)
Gets a factions short name (human-readable).
double faction_getPlayer(int f)
Gets the player's standing with a faction.
int faction_isDynamic(int id)
Is faction dynamic.
const int * faction_getAllies(int f)
Gets the list of allies of a faction.
void faction_modPlayerRaw(int f, double mod)
Modifies the player's standing without affecting others.
int faction_usesHiddenJumps(int f)
Checks to see if a faction uses hidden jumps.
int faction_isInvisible(int id)
Is the faction invisible?
const char * faction_getStandingTextAtValue(int f, double value)
Gets the player's standing in human readable form.
void faction_clearAlly(int f)
Clears all the ally of a dynamic faction.
void faction_modPlayer(int f, double mod, const char *source)
Modifies the player's standing with a faction.
const char ** faction_tags(int f)
Gets the tags the faction has.
double faction_getPlayerDef(int f)
Gets the player's default standing with a faction.
int * faction_getAll(void)
Returns all faction IDs in an array (array.h).
void faction_modPlayerSingle(int f, double mod, const char *source)
Modifies the player's standing without affecting others.
int faction_setKnown(int id, int state)
Sets the factions known state.
void faction_addAlly(int f, int o)
Adds an ally to the faction's allies list.
int faction_isStatic(int id)
Is the faction static?
void faction_addEnemy(int f, int o)
Adds an enemy to the faction's enemies list.
int faction_get(const char *name)
Gets a faction ID by name.
int areAllies(int a, int b)
Checks whether two factions are allies or not.
Header file with generic functions and naev-specifics.
glColour * lua_tocolour(lua_State *L, int ind)
Lua bindings to interact with colours.
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
static int factionL_setplayerstanding(lua_State *L)
Sets the player's standing with the faction.
static int factionL_modplayerraw(lua_State *L)
Modifies the player's standing with the faction.
static int factionL_longname(lua_State *L)
Gets the faction's translated long name.
static int factionL_tags(lua_State *L)
Gets the tags a faction has.
static int factionL_playerstandingdefault(lua_State *L)
Gets the player's default standing with the faction.
static int factionL_getAll(lua_State *L)
Gets all the factions.
static int factionL_dynAlly(lua_State *L)
Adds or removes allies to a faction. Only works with dynamic factions.
static int factionL_exists(lua_State *L)
Lua bindings to deal with factions.
static int factionL_colour(lua_State *L)
Gets the faction colour.
static int factionL_allies(lua_State *L)
Gets the allies of the faction.
static int factionL_areenemies(lua_State *L)
Checks to see if f is an enemy of e.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
LuaFaction luaL_validfaction(lua_State *L, int ind)
Gets faction (or faction name) at index, raising an error if type isn't a valid faction.
static int factionL_logo(lua_State *L)
Gets the faction logo.
static int factionL_dynEnemy(lua_State *L)
Adds or removes enemies to a faction. Only works with dynamic factions.
static int factionL_playerstanding(lua_State *L)
Gets the player's standing with the faction.
static int factionL_areallies(lua_State *L)
Checks to see if f is an ally of a.
int nlua_loadFaction(nlua_env env)
Loads the faction library.
static int factionL_setKnown(lua_State *L)
Sets a faction's known state.
static int factionL_usesHiddenJumps(lua_State *L)
Gets whether or not a faction uses hidden jumps.
static int factionL_dynAdd(lua_State *L)
Adds a faction dynamically. Note that if the faction already exists as a dynamic faction,...
static int factionL_nameRaw(lua_State *L)
Gets the faction's raw / "real" (untranslated, internal) name.
static int factionL_name(lua_State *L)
Gets the faction's translated short name.
static int factionL_enemies(lua_State *L)
Gets the enemies of the faction.
static int factionL_modplayersingle(lua_State *L)
Modifies the player's standing with the faction.
int lua_isfaction(lua_State *L, int ind)
Checks to see if ind is a faction.
static const luaL_Reg faction_methods[]
LuaFaction lua_tofaction(lua_State *L, int ind)
Gets faction at index.
static int factionL_isInvisible(lua_State *L)
Checks to see if a faction is invisible the player.
static int factionL_isStatic(lua_State *L)
Checks to see if a faction has a static standing with the player.
static int factionL_eq(lua_State *L)
__eq (equality) metamethod for factions.
static int factionL_modplayer(lua_State *L)
Modifies the player's standing with the faction.
static int factionL_isKnown(lua_State *L)
Checks to see if a faction is known by the player.
static int factionL_get(lua_State *L)
Gets the faction based on its name.
static int factionL_player(lua_State *L)
Gets the player's faction.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Abstraction for rendering sprite sheets.