[Add] Cargo missions take into account fright distance.

This commit is contained in:
Allanis 2013-04-24 18:05:49 +01:00
parent 472579aa2a
commit 82ee8a41a7
4 changed files with 47 additions and 16 deletions

View File

@ -33,8 +33,8 @@ function create()
if i > 10 then
misn.finish(false)
end
system = space.getSystem(planet)
misn_dist = space.jumpDist(system)
-- Missions generic.
misn_type = "Cargo"
@ -48,7 +48,9 @@ function create()
elseif i == 1 then carg_type = "Ore"
end
misn.setDesc(string.format(misn_desc, planet, system, carg_mass, carg_type))
reward = carg_mass * (750 + rnd.int(250)) + rnd.int(5000)
reward = misn_dist * carg_mass * (250+rnd.int(150)) +
carg_mass * (150+rnd.int(75)) +
rnd.int(1500)
misn.setReward(string.format(misn_reward, reward))
end

View File

@ -33,6 +33,7 @@ function create()
misn.finish(false)
end
system = space.getSystem(planet)
misn_dist = space.jumpDist(system)
-- Mission generics.
misn_type = "Cargo"
@ -47,7 +48,9 @@ function create()
end
misn.setDesc(string.format(misn_desc, carg_mass, carg_type, planet, system))
reward = carg_mass * (1250+rnd.int(250)) + rnd.int(7500)
reward = misn_dist * carg_mass * (500+rnd.int(250)) +
carg_mass * (250+rnd.int(150)) +
rnd.int(2500)
misn.setReward(string.format(misn_reward, reward))
end

View File

@ -91,10 +91,12 @@ static const luaL_reg var_methods[] = {
static int space_getPlanet(lua_State* L);
static int space_getSystem(lua_State* L);
static int space_landName(lua_State* L);
static int space_jumpDist(lua_State* L);
static const luaL_Reg space_methods[] = {
{ "getPlanet", space_getPlanet },
{ "getSystem", space_getSystem },
{ "landName", space_landName },
{ "jumpDist", space_jumpDist },
{ 0, 0 }
};
@ -501,9 +503,8 @@ static int space_getPlanet(lua_State* L) {
}
static int space_getSystem(lua_State* L) {
char* planetname, *system;
MIN_ARGS(1);
char* planetname, *system;
if(lua_isstring(L, -1)) planetname = (char*) lua_tostring(L, -1);
else return 0;
@ -521,6 +522,31 @@ static int space_landName(lua_State* L) {
return 0;
}
static int space_jumpDist(lua_State* L) {
MIN_ARGS(1);
StarSystem** s;
int jumps;
char* start, *goal;
if(lua_isstring(L, -1))
start = (char*)lua_tostring(L, -1);
else {
MISN_DEBUG("invalid parameter 1");
return 0;
}
if((lua_gettop(L) > 1) && lua_isstring(L, -2))
goal = (char*) lua_tostring(L, -2);
else
goal = cur_system->name;
s = system_getJumpPath(&jumps, start, goal);
free(s);
lua_pushnumber(L, jumps);
return 1;
}
// -- Time. --
static int time_get(lua_State* L) {
lua_pushnumber(L, ltime_get());

View File

@ -39,7 +39,7 @@ typedef enum PlanetClass_ {
} PlanetClass;
// Planet services.
#define PLANET_SERVICE_LAND (1<<0) // Can we land?
#define PLANET_SERVICE_LAND (1<<0) // Can we land?
#define PLANET_SERVICE_BASIC (1<<1) // Refueling, spaceport bar, new.
#define PLANET_SERVICE_COMMODITY (1<<2)
#define PLANET_SERVICE_OUTFITS (1<<3)
@ -47,24 +47,24 @@ typedef enum PlanetClass_ {
#define planet_hasService(p,s) ((p)->services & s)
typedef struct Planet_ {
char* name; // Planet name
Vec2 pos; // Position in star system.
char* name; // Planet name
Vec2 pos; // Position in star system.
PlanetClass class; // Planet type.
int faction; // Planet faction.
PlanetClass class; // Planet type.
int faction; // Planet faction.
char* description; // Planet description.
char* bar_description; // Spaceport bar description.
unsigned int services; // Offered services.
char* description; // Planet description.
char* bar_description; // Spaceport bar description.
unsigned int services; // Offered services.
Commodity** commodities; // Commodities sold.
int ncommodities; // Amount in stock.
int ncommodities; // Amount in stock.
// tech[0] stores global tech level (everything that and below) while
// tech[1-PLANET_TECH_MAX] stores the unique tech levels.
int tech[PLANET_TECH_MAX];
glTexture* gfx_space; // Graphics in space.
glTexture* gfx_exterior; // Graphics in the exterior.
glTexture* gfx_space; // Graphics in space.
glTexture* gfx_exterior; // Graphics in the exterior.
} Planet;
// Star systems.