[Add] Major release: First fancy missions for spaceport bars.
This commit is contained in:
parent
83d3fbf07c
commit
1c0d0cac11
@ -11,6 +11,14 @@
|
||||
<high>240</high>
|
||||
<medium>210</medium>
|
||||
<low>180</low>
|
||||
</commodity>
|
||||
</commodity>
|
||||
<commodity name = "Parcels">
|
||||
</commodity>
|
||||
<commodity name = "Colonists">
|
||||
</commodity>
|
||||
<commodity name = "Tourists">
|
||||
</commodity>
|
||||
<commodity name = "Pilgrims">
|
||||
</commodity>
|
||||
</Commodities>
|
||||
|
||||
|
@ -17,5 +17,14 @@
|
||||
<alliance>Empire United</alliance>
|
||||
</avail>
|
||||
</mission>
|
||||
<mission name = "Empire Recruitment">
|
||||
<lua>empire00</lua>
|
||||
<avail>
|
||||
<chance>80</chance>
|
||||
<location>Bar</location>
|
||||
<alliance>Empire United</alliance>
|
||||
<alliance>Neutral</alliance>
|
||||
</avail>
|
||||
</mission>
|
||||
</Missions>
|
||||
|
||||
|
39
dat/missions/empire00.lua
Normal file
39
dat/missions/empire00.lua
Normal file
@ -0,0 +1,39 @@
|
||||
function create()
|
||||
-- Intro message.
|
||||
tk.msg("Spaceport Bar",
|
||||
[[As you enter the bar you can't help but notice that a fellow at a table has been looking at you since you came in. You tend to your business as if you hadn't noticed. A while later you feel a tap on your shoulder and see it's the same man.]]);
|
||||
if tk.yesno("Spaceport Bar",
|
||||
[["Hello, sorry to interupt you. I'm lieutenant Tamrit from the empire Armada. We're having another recruitment operation and would be interested in having another pilot among us. Would you be interested in working for the Empire?"]])
|
||||
then
|
||||
misn.accept()
|
||||
|
||||
dest = space.getPlanet("Empire");
|
||||
|
||||
-- Mission details.
|
||||
misn.setTitle("Empire Recruitment")
|
||||
misn.setReward("3000 Scred")
|
||||
misn.setDesc(string.format("Deliver some parcels for the Empire to %s.", dest))
|
||||
|
||||
tk.msg("Empire Recruitment", string.format(
|
||||
[["Welcome aboard.", says Tamrit before giving you a firm handshake. "At first you'll be tested with cargo missions while we get data on your flying skills. Later you could get called for more important missions. Who knows? You could be the next Medek, greatest pilot we ever had on the Armada."
|
||||
He hits a couple buttons on his wrist computer that springs into action.
|
||||
"It looks like we already have a simple task for you. Deliver these parcels to %s. The best pilots started out delivering papers and ended up flying into combat against large warships."]], dest))
|
||||
|
||||
-- Set up the goal.
|
||||
parcels = player.addCargo("Parcels", 0)
|
||||
hook.land("land")
|
||||
end
|
||||
end
|
||||
|
||||
function land()
|
||||
if space.landName() == dest then
|
||||
if player.rmCargo(parcels) then
|
||||
player.pay(3000)
|
||||
-- More flavour text :)
|
||||
tk.msg("Mission Success", string.format(
|
||||
"You deliver the parcels to the Empire station at the %s spaceport. Afterwards they make you do some paperwork to formalize your participation with the Empire. You aren't too sure of your encounter with the Empire, only time will tell", dest))
|
||||
misn.finish()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -70,13 +70,14 @@ static Commodity* commodity_parse(xmlNodePtr parent) {
|
||||
else if(xml_isNode(node, "low"))
|
||||
tmp->low = xml_getInt(node);
|
||||
} while((node = node->next));
|
||||
|
||||
#if 0 // Let's kill this for now.
|
||||
#define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name)
|
||||
MELEMENT(tmp->high==0, "high");
|
||||
MELEMENT(tmp->description==NULL, "description");
|
||||
MELEMENT(tmp->medium==0, "medium");
|
||||
MELEMENT(tmp->low==0, "low");
|
||||
#undef MELEMENT
|
||||
#endif
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
@ -181,8 +181,8 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
|
||||
double bx, double by, glColour* c, const char* fmt, ...) {
|
||||
|
||||
//float h = ft_font->h / .63; // Slightly increase font size.
|
||||
char txt[1024];
|
||||
char buf[128];
|
||||
char txt[4096];
|
||||
char buf[256];
|
||||
va_list ap;
|
||||
int p, i, j, n, m, len, ret, lastspace;
|
||||
double x, y;
|
||||
|
@ -772,7 +772,7 @@ static void spaceport_bar(void) {
|
||||
land_planet->bar_description);
|
||||
|
||||
if(!has_visited(VISITED_BAR)) {
|
||||
// TODO: mission check.
|
||||
missions_bar(land_planet->faction, land_planet->name, cur_system->name);
|
||||
visited(VISITED_BAR);
|
||||
}
|
||||
}
|
||||
|
@ -106,10 +106,10 @@ int misn_run(Mission* misn, char* func) {
|
||||
lua_getglobal(misn->L, func);
|
||||
if((ret = lua_pcall(misn->L, 0, 0, 0))) {
|
||||
// Did an oops.
|
||||
err = (char*) lua_tostring(misn->L, -1);
|
||||
err = (lua_isstring(misn->L, -1)) ? (char*) lua_tostring(misn->L, -1) : NULL;
|
||||
if(strcmp(err, "Mission Finished"))
|
||||
WARN("Mission '%s' -> '%s' : %s",
|
||||
cur_mission->data->name, func, err);
|
||||
cur_mission->data->name, func, (err) ? err : "Unknown Error");
|
||||
else ret = 0;
|
||||
}
|
||||
|
||||
@ -220,41 +220,42 @@ static int space_getPlanet(lua_State* L) {
|
||||
lua_pushstring(L, space_getRndPlanet());
|
||||
return 1;
|
||||
}
|
||||
else if(lua_isnumber(L, -1) || lua_istable(L, -1)) {
|
||||
// Faction table or single.
|
||||
if(lua_isnumber(L, -1)) {
|
||||
// Faction is just a number.
|
||||
i = lua_tonumber(L, -1);
|
||||
planets = space_getFactionPlanet(&nplanets, &i, 1);
|
||||
}
|
||||
else if(lua_istable(L, -1)) {
|
||||
// Load up the table.
|
||||
lua_pushnil(L);
|
||||
nfactions = (int) lua_gettop(L);
|
||||
factions = malloc(sizeof(int) * nfactions);
|
||||
i = 0;
|
||||
while(lua_next(L, -2) != 0) {
|
||||
factions[i++] = (int) lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
// Get the planets.
|
||||
planets = space_getFactionPlanet(&nplanets, factions, nfactions);
|
||||
free(factions);
|
||||
}
|
||||
// Choose random planet.
|
||||
if(nplanets == 0) {
|
||||
// No suitable planets.
|
||||
free(planets);
|
||||
return 0;;
|
||||
}
|
||||
rndplanet = planets[RNG(0, nplanets-1)];
|
||||
free(planets);
|
||||
|
||||
lua_pushstring(L, rndplanet);
|
||||
return 1;
|
||||
else if(lua_isnumber(L, -1)) {
|
||||
i = lua_tonumber(L, -1);
|
||||
planets = space_getFactionPlanet(&nplanets, &i, 1);
|
||||
}
|
||||
return 0; // Nothing good passed.
|
||||
else if(lua_isstring(L, 1)) {
|
||||
i = faction_get((char*) lua_tostring(L, -1));
|
||||
planets = space_getFactionPlanet(&nplanets, &i, 1);
|
||||
}
|
||||
else if(lua_istable(L, -1)) {
|
||||
// Load up the table.
|
||||
lua_pushnil(L);
|
||||
nfactions = (int) lua_gettop(L);
|
||||
factions = malloc(sizeof(int) * nfactions);
|
||||
i = 0;
|
||||
while(lua_next(L, -2) != 0) {
|
||||
factions[i++] = (int) lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
// Get the planets.
|
||||
planets = space_getFactionPlanet(&nplanets, factions, nfactions);
|
||||
free(factions);
|
||||
}
|
||||
else return 0; // Nothing useful.
|
||||
|
||||
// Choose random planet.
|
||||
if(nplanets == 0) {
|
||||
// No suitable planet.
|
||||
free(planets);
|
||||
return 0;
|
||||
}
|
||||
|
||||
rndplanet = planets[RNG(0, nplanets-1)];
|
||||
free(planets);
|
||||
|
||||
lua_pushstring(L, rndplanet);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int space_landName(lua_State* L) {
|
||||
@ -357,6 +358,7 @@ static int tk_msg(lua_State* L) {
|
||||
}
|
||||
|
||||
static int tk_yesno(lua_State* L) {
|
||||
int ret;
|
||||
char* title, *str;
|
||||
MIN_ARGS(2);
|
||||
|
||||
@ -365,8 +367,9 @@ static int tk_yesno(lua_State* L) {
|
||||
if(lua_isstring(L, -1)) str = (char*) lua_tostring(L, -1);
|
||||
else return 0;
|
||||
|
||||
dialogue_YesNo(title, str);
|
||||
return 0;
|
||||
ret = dialogue_YesNo(title, str);
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tk_input(lua_State* L) {
|
||||
|
@ -82,10 +82,35 @@ static int mission_init(Mission* mission, MissionData* misn) {
|
||||
return mission->id;
|
||||
}
|
||||
|
||||
// Small wrapper for misn_run.
|
||||
void mission_accept(Mission* mission) {
|
||||
misn_run(mission, "accept");
|
||||
}
|
||||
|
||||
// Runs bar missions, all lua side and one-shot.
|
||||
void missions_bar(int faction, char* planet, char* system) {
|
||||
MissionData* misn;
|
||||
Mission mission;
|
||||
int i;
|
||||
double chance;
|
||||
|
||||
for(i = 0; i < mission_nstack; i++) {
|
||||
misn = &mission_stack[i];
|
||||
if((misn->avail.loc == MIS_AVAIL_BAR) &&
|
||||
(((misn->avail.planet && strcmp(misn->avail.planet, planet)==0)) ||
|
||||
(misn->avail.system && (strcmp(misn->avail.system, system)==0)) ||
|
||||
mission_matchFaction(misn, faction))) {
|
||||
|
||||
chance = (double)(misn->avail.chance % 100)/100.;
|
||||
|
||||
if(RNGF() < chance) {
|
||||
mission_init(&mission, misn);
|
||||
mission_cleanup(&mission); // It better clean up for itself or we do it.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up a mission.
|
||||
void mission_cleanup(Mission* misn) {
|
||||
if(misn->id) hook_rmParent(misn->id); // Remove existing hooks.
|
||||
@ -141,7 +166,7 @@ Mission* missions_computer(int* n, int faction, char* planet, char* system) {
|
||||
|
||||
for(j = 0; j < rep; j++)
|
||||
// Random chance of rep appearances.
|
||||
if(RNGF() > chance) {
|
||||
if(RNGF() < chance) {
|
||||
tmp = realloc(tmp, sizeof(Mission) * ++m);
|
||||
mission_init(&tmp[m-1], misn);
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ extern Mission player_missions[MISSION_MAX];
|
||||
Mission* missions_computer(int* n, int faction, char* planet, char* system);
|
||||
// Player accepted mission - mission computer.
|
||||
void mission_accept(Mission* mission);
|
||||
void mission_bar(int faction, char* planet, char* system);
|
||||
|
||||
// Load/Quit.
|
||||
int missions_load(void);
|
||||
|
@ -1387,7 +1387,7 @@ static Widget* toolkit_getFocus(void) {
|
||||
}
|
||||
|
||||
void dialogue_alert(const char* fmt, ...) {
|
||||
char msg[256];
|
||||
char msg[512];
|
||||
va_list ap;
|
||||
unsigned int wdw;
|
||||
int h;
|
||||
@ -1423,7 +1423,7 @@ static void dialogue_alertClose(char* str) {
|
||||
// Display an alert popup with only an OK button and a message.
|
||||
static unsigned int msg_wid = 0;
|
||||
void dialogue_msg(char* caption, const char* fmt, ...) {
|
||||
char msg[256];
|
||||
char msg[4096];
|
||||
va_list ap;
|
||||
int h;
|
||||
|
||||
@ -1461,7 +1461,7 @@ static void dialogue_msgClose(char* str) {
|
||||
static int yesno_result;
|
||||
static unsigned int yesno_wid = 0;
|
||||
int dialogue_YesNo(char* caption, const char* fmt, ...) {
|
||||
char msg[256];
|
||||
char msg[4096];
|
||||
va_list ap;
|
||||
int h;
|
||||
|
||||
@ -1512,7 +1512,7 @@ static void dialogue_YesNoClose(char* str) {
|
||||
// Toolkit input boxes, return input.
|
||||
static unsigned int input_wid = 0;
|
||||
char* dialogue_input(char* title, int min, int max, const char* fmt, ...) {
|
||||
char msg[256], *input;
|
||||
char msg[512], *input;
|
||||
va_list ap;
|
||||
int h;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user