[Add] View missions at land screen.

This commit is contained in:
Allanis 2013-04-01 00:23:05 +01:00
parent c45de3044d
commit 68710f9fb5
2 changed files with 92 additions and 4 deletions

View File

@ -5,15 +5,16 @@ function create()
-- Missions generic.
misn_type = "Rush"
misn_setTitle("Rush Delivery to " .. planet)
misn.setTitle("Rush Delivery to " .. planet)
-- More mission specifics.
carg_mass = rnd.int(10, 30)
carg.type = rnd.setDesc(string.format(
carg_type = "Food"
misn.setDesc(string.format(
"%s needs a rush delivery of %d tons of %s by %s.",
planet, carg_mass, carg_type, "SOMEDAY"))
misn_reward = carg_mass * 1000 + rnd.int(0, 5000)
misn.setReward(string.format("%d Scred" misn_reward))
misn.setReward(string.format("%d Scred", misn_reward))
-- Set the hooks.
hook.land("land")

View File

@ -35,6 +35,10 @@
#define BAR_WIDTH 460
#define BAR_HEIGHT 300
// Mission computer window.
#define MISSION_WIDTH 700
#define MISSION_HEIGHT 600
#define MUSIC_TAKEOFF "liftoff"
#define MUSIC_LAND "agriculture"
@ -95,6 +99,11 @@ static void spaceport_bar_close(char* str);
// News.
static void news(void);
static void news_close(char* str);
// Mission computer.
static void misn(void);
static void misn_close(char* str);
static void misn_accept(char* str);
static void misn_update(char* str);
// The local market.
static void commodity_exchange(void) {
@ -757,6 +766,84 @@ static void news_close(char* str) {
window_destroy(terciary_wid);
}
// Mission computer, cos' missions rule!
static void misn(void) {
int i;
char** misn_names;
secondary_wid = window_create("Mission Computer",
-1, -1, MISSION_WIDTH, MISSION_HEIGHT);
// Buttons.
window_addButton(secondary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseMission",
"Close", misn_close);
window_addButton(secondary_wid, -20, 40+BUTTON_HEIGHT,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnAcceptMission",
"Accept", misn_accept);
// Text.
window_addText(secondary_wid, 300+40, -60,
300, 40, 0, "txtSReward",
&gl_smallFont, &cDConsole, "Reward:");
window_addText(secondary_wid, 300+100, -60,
240, 40, 0, "txtReward", &gl_smallFont, &cBlack, NULL);
window_addText(secondary_wid, 300+40, -100,
300, MISSION_HEIGHT - BUTTON_WIDTH - 120, 0,
"txtDesc", &gl_smallFont, &cBlack, NULL);
// List.
if(mission_ncomputer != 0) {
// There are missions.
misn_names = malloc(sizeof(char*)*mission_ncomputer);
for(i = 0; i < mission_ncomputer; i++)
misn_names[i] = strdup(mission_computer[i].title);
} else {
// No missions.
misn_names = malloc(sizeof(char*));
misn_names[0] = strdup("No Missions");
}
window_addList(secondary_wid, 20, -40,
300, MISSION_HEIGHT-60,
"lstMission", misn_names, mission_ncomputer, 0, misn_update);
misn_update(NULL);
}
static void misn_close(char* str) {
if(strcmp(str, "btnCloseMission")==0)
window_destroy(secondary_wid);
}
static void misn_accept(char* str) {
(void)str;
}
static void misn_update(char* str) {
int i;
char* active_misn;
(void)str;
active_misn = toolkit_getList(secondary_wid, "lstMission");
if(strcmp(active_misn, "No Missions")==0) {
window_modifyText(secondary_wid, "txtReward", "None");
window_modifyText(secondary_wid, "txtDesc",
"There are no missions available here.");
return;
}
for(i = 0; i < mission_ncomputer; i++)
if(strcmp(active_misn, mission_computer[i].title)==0) {
window_modifyText(secondary_wid, "txtReward", mission_computer[i].reward);
window_modifyText(secondary_wid, "txtDesc", mission_computer[i].desc);
return;
}
}
// Land the player.
void land(Planet* p) {
if(landed) return;
@ -794,7 +881,7 @@ void land(Planet* p) {
if(planet_hasService(land_planet, PLANET_SERVICE_BASIC)) {
window_addButton(land_wid, 20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
"Mission Terminal", NULL);
"Mission Terminal", (void(*)(char*))misn);
window_addButton(land_wid, 20, 20 + BUTTON_HEIGHT + 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBar",