[Add] Pretend to be multilingual for easiar conversion later. [Fix] Allow null on toolkit_modifyText.

This commit is contained in:
Allanis 2013-04-06 17:56:03 +01:00
parent 1c0d0cac11
commit 8df3171916
5 changed files with 86 additions and 49 deletions

View File

@ -19,6 +19,9 @@
</mission>
<mission name = "Empire Recruitment">
<lua>empire00</lua>
<flags>
<unique>1</unique>
</flags>
<avail>
<chance>80</chance>
<location>Bar</location>

View File

@ -1,3 +1,26 @@
lang = lephisto.lang()
if lang == "es" then
-- Not translated.
else -- Default English.
misn_desc = "%s needs a delivery of %d tons of %s."
misn_reward = "%d Scred."
title = {}
title[1] = "Cargo delivery to %s"
title[2] = "Freight delivery to %s"
title[3] = "Transport to %s"
title[4] = "Delivery to %s"
full_title = "Ship is full"
full_msg = "Your ship is too full. You need to make room for %d tons if you want to be able to accept the mission."
accept_title = "Mission Accepted"
accept_msg = "The workers load %d tons of %s onto your ship."
toomany_title = "Too many missions"
toomany_msg = "You have too many active missions."
finish_title = "Succesful Delivery"
finish_msg = "The workers unload the %s at the docks."
miss_title = "Cargo missing"
miss_msg = "You are missing the %d tons of %s!"
end
-- Create the mission.
function create()
-- Target destination.
@ -14,15 +37,7 @@ function create()
-- Missions generic.
misn_type = "Cargo"
i = rnd.int(3)
if i == 0 then
misn.setTitle("Cargo Delivery to " .. planet)
elseif i == 1 then
misn.setTitle("Freight delivery to " .. planet)
elseif i == 2 then
misn.setTitle("Transport to " .. planet)
elseif i == 3 then
misn.setTitle("Delivery to " .. planet)
end
misn.setTitle(string.format(title[i+1], planet))
-- More mission specifics.
carg_mass = rnd.int(10, 30)
@ -30,41 +45,31 @@ function create()
if i == 0 then carg_type = "Food"
elseif i == 1 then carg_type = "Ore"
end
misn.setDesc(string.format(
"%s needs a delivery of %d tons of %s.",
planet, carg_mass, carg_type))
misn_reward = carg_mass * (750 + rnd.int(250)) + rnd.int(5000)
misn.setReward(string.format("%d Scred", misn_reward))
misn.setDesc(string.format(misn_desc, planet, carg_mass, carg_type))
reward = carg_mass * (750 + rnd.int(250)) + rnd.int(5000)
misn.setReward(string.format(misn_reward, reward))
end
function accept()
if player.freeCargo() < carg_mass then
tk.msg("Ship is full",
string.format(
"Your ship is too full, You need to make room for %d more tons if you want to be able to accept the mission.",
carg_mass-player.freeCargo()))
tk.msg(full_title, string.format(full_msg, carg_mass-player.freeCargo()))
elseif misn.accept() then -- Able to accept the mission, hooks BREAK after accepting.
carg_id = player.addCargo(carg_type, carg_mass)
tk.msg("Mission Accepted",
string.format("The workers load the %d tons of %s onto your ship.",
carg_mass, carg_type))
tk.msg(accept_title, string.format(accept_msg, carg_mass, carg_type))
hook.land("land"); -- Only hook after accepting.
else
tk.msg("Too many missions", "You have too many active missions.")
tk.msg(toomany_title, toomany_msg)
end
end
function land()
if space.landName() == planet then
if player.rmCargo(carg_id) then
player.pay(misn_reward)
tk.msg("Mission Accomplished",
string.format("The workers unload the %s at the docks.", carg_type))
player.pay(reward)
tk.msg(finish_title, string.format(finish_msg, carg_type))
misn_finish()
else
tk.msg("Where is the cargo?",
string.format("You are missing the %d tons of %s!.",
carg_mass, carg_type))
tk.msg(miss_title, string.format(miss_msg, carg_mass, carg_type))
end
end
end

View File

@ -1,23 +1,37 @@
lang = lephisto.lang()
if lang == "es" then
-- Not translated.
else -- Default English.
misn_title = "Empire Recruitment"
misn_reward = "3000 credits"
misn_desc = "Deliver some parcels for the Empire to %s."
title = {}
title[1] = "Spaceport Bar"
title[2] = "Empire Recruitment"
title[3] = "Mission Accomplished"
text = {}
text[1] = [[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.]]
text[2] = [["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?"]]
text[3] = [["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."]]
text[4] = [["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.]]
end
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
tk.msg(title[1], text[2])
if tk.yesno(title[1], text[2]) 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))
misn.setTitle(misn_title)
misn.setReward(misn_credits)
misn.setDesc(string.format(misn_desc, 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))
tk.msg(title[2], string.format(text[3], dest))
-- Set up the goal.
parcels = player.addCargo("Parcels", 0)
@ -30,8 +44,7 @@ function land()
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))
tk.msg(title[3], string.format(text[4], dest))
misn.finish()
end
end

View File

@ -17,11 +17,19 @@
#define MIN_ARGS(n) if(lua_gettop(L) < n) return 0
// Current mission.
static Mission* cur_mission = NULL;
static int misn_delete = 0; // If 1 delete current mission.
// -- Libraries. --
// Lephisto.
static int lephisto_lang(lua_State* L);
static const luaL_reg lephisto_methods[] = {
{ "lang", lephisto_lang },
{ 0, 0 }
};
// Mission.
static int misn_setTitle(lua_State* L);
static int misn_setDesc(lua_State* L);
@ -87,6 +95,7 @@ static const luaL_Reg hook_methods[] = {
// Register all the libaries.
int misn_loadLibs(lua_State* L) {
luaL_register(L, "lephisto", lephisto_methods);
luaL_register(L, "misn", misn_methods);
luaL_register(L, "space", space_methods);
luaL_register(L, "player", player_methods);
@ -128,6 +137,13 @@ int misn_run(Mission* misn, char* func) {
return ret;
}
// -- Lephisto. --
static int lephisto_lang(lua_State* L) {
// TODO: multilanguage stuff.
lua_pushstring(L, "en");
return 1;
}
// -- Mission. --
static int misn_setTitle(lua_State* L) {

View File

@ -375,7 +375,7 @@ void window_modifyText(const unsigned int wid, char* name, char* newstring) {
Widget* wgt = window_getwgt(wid, name);
if(wgt->dat.txt.text) free(wgt->dat.txt.text);
wgt->dat.txt.text = strdup(newstring);
if(newstring) wgt->dat.txt.text = strdup(newstring);
}
// Disable a button.