[Add] Now you can define start mission in start.xml, also began initial tutorial level.

This commit is contained in:
Allanis 2014-03-04 00:53:04 +00:00
parent cccb8cbff3
commit 401ea9b4e5
7 changed files with 87 additions and 7 deletions

5
TODO
View File

@ -1,4 +1,7 @@
Vital:
-- CHECK MISSIONS OUT!! BORKED!!
-- New game improvements.
-- Introductory screen (text + image?).
-- Tutorial or small guide.
@ -53,5 +56,5 @@ Minor:
-- Possibly use Queso CGL
SOMEDAY!! MAYBE...:
-- 3d models (not actually 3D, just no sprites).
-- 3d models (not actually a 3D perspective, just no sprites).

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Missions>
<mission name="Welcome">
<lua>welcome</lua>
<mission name="Tutorial">
<lua>tutorial</lua>
<flags>
<unique>1</unique>
</flags>

31
dat/missions/tutorial.lua Normal file
View File

@ -0,0 +1,31 @@
--[[
-- The beginner player tutorial.
--
-- Does simple stuff like teach the player to fly around or use
-- her communications system.
--]]
-- Localization stuff, translators would work here.
lang = lephisto.lang()
if lang == "es" then
else -- Default English.
title = {}
title[1] = "Tutorial"
text = {}
text[1] = "Would you like to run the Tutorial to learn how to play Lephisto?"
misn_title = "Lephisto Tutorial"
misn_reward = "Knowledge of how to play the game."
misn_desc = "New Player Tutorial to learn how to survive in the universe."
end
function create()
if tk.yesno(title[1], text[1]) then
misn.accept()
-- Set basic mission information.
misn.setTitle(misn_title)
misn.setReward(misn_reward)
misn.setDesc(misn_desc)
end
end

View File

@ -13,8 +13,9 @@
</date>
<system>
<name>Delta Pavonis</name>
<x>0</x>
<y>0</y>
<x>150</x>
<y>150</y>
</system>
<mission>Tutorial</mission>
</player>
</Start>

View File

@ -82,7 +82,7 @@ int mission_getID(char* name) {
/* Get a MissionData based on ID. */
MissionData* mission_get(int id) {
if((id <= 0) || (mission_nstack < id)) return NULL;
if((id < 0) || (id >= mission_nstack)) return NULL;
return &mission_stack[id];
}
@ -260,6 +260,30 @@ void missions_bar(int faction, char* planet, char* sysname) {
}
}
/**
* @brief Starts a mission.
*
* Mission must still call misn.accept() to actually get added to the players
* active missions.
* @param name Name of the mission to start.
* @return 0 on success.
*/
int mission_start(char* name) {
Mission mission;
MissionData* mdat;
/* Try to get the mission. */
mdat = mission_get(mission_getID(name));
if(mdat == NULL)
return -1;
/* Try to run the mission.
mission_init(&mission, mdat, 0);
mission_cleanup(&mission); /* Clean up in case not accepted. */
return 0;
}
/* Mark all active systems that need marking. */
void mission_sysMark(void) {
int i;

View File

@ -76,6 +76,7 @@ Mission* missions_computer(int* n, int faction, char* planet, char* sysname);
/* Player accepted mission - mission computer. */
int mission_accept(Mission* mission);
void missions_bar(int faction, char* planet, char* sysname);
int missions_start(char* name);
/* Misc. */
void missions_update(const double dt);

View File

@ -56,6 +56,7 @@ Pilot* player = NULL; /**< The player. */
static Ship* player_ship = NULL; /**< Temp ship to hold when naming it. */
static double player_px, player_py, player_vx, player_vy, player_dir; /**< More hack. */
static int player_credits = 0; /**< Temp hack on create. */
static char* player_mission = NULL; /**< More hack. */
/*
* Player sounds.
@ -274,6 +275,14 @@ void player_new(void) {
return;
intro_display();
/* Add the mission if found. */
if(player_mission != NULL) {
if(mission_start(player_mission) < 0)
WARN("Failed to run start mission '%s'.", player_mission);
free(player_mission);
player_mission = NULL;
}
}
/**
@ -288,7 +297,9 @@ static int player_newMake(void) {
int l, h, tl, th;
double x, y;
/* Sane defaults. */
sysname = NULL;
player_mission = NULL;
buf = pack_readfile(DATA, START_DATA, &bufsize);
@ -339,10 +350,19 @@ static int player_newMake(void) {
xmlr_int(tmp, "high", th);
} while(xml_nextNode(tmp));
}
/* Check for mission. */
if(xml_isNode(cur, "mission")) {
if(player_mission != NULL) {
WARN("start.xml already contains a mission node!");
continue;
}
player_mission = strdup(xml_get(cur));
}
} while((cur = cur->next));
}
}while((node = node->next));
/* Clean up. */
xmlFreeDoc(doc);
free(buf);