From 1c0d0cac11c4fd5bfadd3c6a9a716478aeb02175 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 6 Apr 2013 17:11:35 +0100 Subject: [PATCH] [Add] Major release: First fancy missions for spaceport bars. --- dat/commodity.xml | 10 ++++- dat/mission.xml | 9 +++++ dat/missions/empire00.lua | 39 +++++++++++++++++++ src/economy.c | 3 +- src/font.c | 4 +- src/land.c | 2 +- src/misn_lua.c | 79 ++++++++++++++++++++------------------- src/mission.c | 27 ++++++++++++- src/mission.h | 1 + src/toolkit.c | 8 ++-- 10 files changed, 134 insertions(+), 48 deletions(-) create mode 100644 dat/missions/empire00.lua diff --git a/dat/commodity.xml b/dat/commodity.xml index 03c3db7..04636d2 100644 --- a/dat/commodity.xml +++ b/dat/commodity.xml @@ -11,6 +11,14 @@ 240 210 180 - + + + + + + + + + diff --git a/dat/mission.xml b/dat/mission.xml index 902dfa5..16b7503 100644 --- a/dat/mission.xml +++ b/dat/mission.xml @@ -17,5 +17,14 @@ Empire United + + empire00 + + 80 + Bar + Empire United + Neutral + + diff --git a/dat/missions/empire00.lua b/dat/missions/empire00.lua new file mode 100644 index 0000000..65df234 --- /dev/null +++ b/dat/missions/empire00.lua @@ -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 + diff --git a/src/economy.c b/src/economy.c index a9fe042..fc5802f 100644 --- a/src/economy.c +++ b/src/economy.c @@ -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; } diff --git a/src/font.c b/src/font.c index 12a27b9..05c5d81 100644 --- a/src/font.c +++ b/src/font.c @@ -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; diff --git a/src/land.c b/src/land.c index 919913f..621fde1 100644 --- a/src/land.c +++ b/src/land.c @@ -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); } } diff --git a/src/misn_lua.c b/src/misn_lua.c index 87825dd..111e846 100644 --- a/src/misn_lua.c +++ b/src/misn_lua.c @@ -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) { diff --git a/src/mission.c b/src/mission.c index 2836560..e1fccb7 100644 --- a/src/mission.c +++ b/src/mission.c @@ -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); } diff --git a/src/mission.h b/src/mission.h index 452ce97..5339454 100644 --- a/src/mission.h +++ b/src/mission.h @@ -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); diff --git a/src/toolkit.c b/src/toolkit.c index cc4ba97..118144e 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -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;