diff --git a/TODO b/TODO index 03e41e7..bf0a791 100644 --- a/TODO +++ b/TODO @@ -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). diff --git a/dat/mission.xml b/dat/mission.xml index 614b638..16a9e36 100644 --- a/dat/mission.xml +++ b/dat/mission.xml @@ -1,7 +1,7 @@ - - welcome + + tutorial 1 diff --git a/dat/missions/tutorial.lua b/dat/missions/tutorial.lua new file mode 100644 index 0000000..353825f --- /dev/null +++ b/dat/missions/tutorial.lua @@ -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 + diff --git a/dat/start.xml b/dat/start.xml index 0466329..cd6f2c3 100644 --- a/dat/start.xml +++ b/dat/start.xml @@ -13,8 +13,9 @@ Delta Pavonis - 0 - 0 - + 150 + 150 + + Tutorial diff --git a/src/mission.c b/src/mission.c index fafb68c..1d73dd7 100644 --- a/src/mission.c +++ b/src/mission.c @@ -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; diff --git a/src/mission.h b/src/mission.h index 85b5694..dba09ab 100644 --- a/src/mission.h +++ b/src/mission.h @@ -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); diff --git a/src/player.c b/src/player.c index 2e0b28f..e9cfe50 100644 --- a/src/player.c +++ b/src/player.c @@ -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);