Initial commit
This commit is contained in:
202
devtools/create_ultima/files/ultima6/scripts/common/actor.lua
Normal file
202
devtools/create_ultima/files/ultima6/scripts/common/actor.lua
Normal file
@@ -0,0 +1,202 @@
|
||||
ALIGNMENT_DEFAULT = 0
|
||||
ALIGNMENT_NEUTRAL = 1
|
||||
ALIGNMENT_EVIL = 2
|
||||
ALIGNMENT_GOOD = 3
|
||||
ALIGNMENT_CHAOTIC = 4
|
||||
|
||||
HEAD = 0
|
||||
NECK = 1
|
||||
BODY = 2
|
||||
ARM = 3
|
||||
ARM_2 = 4
|
||||
HAND = 5
|
||||
HAND_2 = 6
|
||||
FOOT = 7
|
||||
|
||||
|
||||
g_combat_range_tbl = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7,
|
||||
1, 1, 2, 3, 4, 5, 6, 7,
|
||||
2, 2, 2, 3, 4, 5, 6, 7,
|
||||
3, 3, 3, 4, 5, 6, 7, 7,
|
||||
4, 4, 4, 5, 6, 7, 7, 8,
|
||||
5, 5, 5, 6, 7, 7, 8, 8,
|
||||
6, 6, 6, 7, 7, 8, 8, 8,
|
||||
7, 7, 7, 7, 8, 8, 8, 8}
|
||||
|
||||
function get_combat_range(absx, absy)
|
||||
if absx < 8 and absy < 8 then
|
||||
return g_combat_range_tbl[absx * 8 + absy + 1]
|
||||
end
|
||||
|
||||
return 9
|
||||
end
|
||||
|
||||
function get_weapon_range(obj_n)
|
||||
|
||||
local range = g_range_weapon_tbl[obj_n]
|
||||
|
||||
if range == nil then
|
||||
return 1
|
||||
end
|
||||
|
||||
return range
|
||||
end
|
||||
|
||||
function actor_randomise_stat(base_stat)
|
||||
local tmp = math.floor(base_stat/2)
|
||||
if tmp == 0 then
|
||||
return base_stat
|
||||
end
|
||||
|
||||
return math.random(0, tmp) + math.random(0, tmp) + base_stat - tmp
|
||||
end
|
||||
|
||||
function actor_is_holding_obj(actor, obj_n)
|
||||
local hand
|
||||
|
||||
hand = Actor.inv_get_readied_obj_n(actor, HAND)
|
||||
if hand == obj_n then
|
||||
return true
|
||||
end
|
||||
hand = Actor.inv_get_readied_obj_n(actor, HAND_2)
|
||||
if hand == obj_n then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function actor_has_free_arm(actor)
|
||||
if Actor.inv_get_readied_obj_n(actor, ARM) == -1
|
||||
or Actor.inv_get_readied_obj_n(actor, ARM_2) == -1 then
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function actor_find_max_xy_distance(actor, x, y)
|
||||
x, y = abs(actor.x - x), abs(actor.y - y)
|
||||
return (x > y) and x or y
|
||||
end
|
||||
|
||||
function actor_find_max_wrapped_xy_distance(actor, x, y)
|
||||
x, y = get_wrapped_dist(actor.x, x), get_wrapped_dist(actor.y, y)
|
||||
return (x > y) and x or y
|
||||
end
|
||||
|
||||
function actor_get_combat_range(actor, target_x, target_y)
|
||||
--FIXME might need to adjust the src position for multi-tile actors.
|
||||
x, y = get_wrapped_dist(actor.x, target_x), get_wrapped_dist(actor.y, target_y)
|
||||
return get_combat_range(x, y)
|
||||
end
|
||||
|
||||
function subtract_map_movement_pts(actor)
|
||||
local points = map_get_impedence(actor.x, actor.y, actor.z, false) + 5
|
||||
subtract_movement_pts(actor, points)
|
||||
end
|
||||
|
||||
function actor_move_towards_loc(actor, map_x, map_y)
|
||||
--dgb("move actor "..actor.name.." from ("..actor.x..","..actor.y..") towards ("..map_x..","..map_y..") ")
|
||||
local var_2 = (word_30A6B == 1) and 0 or 1
|
||||
local var_6 = 1
|
||||
local diff_x = map_x - actor.x
|
||||
local diff_y = map_y - actor.y
|
||||
|
||||
if (diff_x == 0 and diff_y == 0) or actor.wt == WT_STATIONARY then subtract_movement_pts(actor, 5) return 0 end
|
||||
|
||||
local x_direction, y_direction
|
||||
|
||||
if diff_x ~= 0 then
|
||||
x_direction = (diff_x >= 0) and DIR_EAST or DIR_WEST
|
||||
else
|
||||
x_direction = (math.random(0, 1) == 0) and DIR_WEST or DIR_EAST
|
||||
end
|
||||
|
||||
if diff_y ~= 0 then
|
||||
y_direction = (diff_y >= 0) and DIR_SOUTH or DIR_NORTH
|
||||
else
|
||||
y_direction = (math.random(0, 1) == 0) and DIR_SOUTH or DIR_NORTH
|
||||
end
|
||||
|
||||
unk_30A72 = 0
|
||||
|
||||
local var_4
|
||||
|
||||
if abs(diff_x) >= 4 or abs(diff_y) >= 4 then
|
||||
var_4 = (math.random(1, abs(diff_x) + abs(diff_y)) <= abs(diff_x)) and 1 or 0
|
||||
else
|
||||
if abs(diff_x) > abs(diff_y) then
|
||||
var_4 = 0
|
||||
else
|
||||
if abs(diff_x) < abs(diff_y) then
|
||||
var_4 = 1
|
||||
else
|
||||
var_4 = math.random(0, 1)
|
||||
end
|
||||
end
|
||||
|
||||
--var_4 = (abs(diff_x) >= abs(diff_y) or abs(diff_x) ~= abs(diff_y) or math.random(0, 1) == 0) and 0 or 1
|
||||
end
|
||||
----dgb("var_4 = "..var_4.."\n")
|
||||
if var_4 == 0 then
|
||||
if actor_move(actor, x_direction, var_2) == 0 then
|
||||
if actor_move_diagonal(actor, x_direction, y_direction) == 0 then
|
||||
if actor_move(actor, y_direction, var_2) == 0 then
|
||||
if math.random(0, 1) ~= 0 or actor_move(actor, (y_direction == DIR_NORTH) and DIR_SOUTH or DIR_NORTH, 1) == 0 then
|
||||
|
||||
subtract_map_movement_pts(actor)
|
||||
var_6 = 0 --didn't move anywhere
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
if actor_move(actor, y_direction, var_2) == 0 then
|
||||
if actor_move_diagonal(actor, x_direction, y_direction) == 0 then
|
||||
if actor_move(actor, x_direction, var_2) == 0 then
|
||||
if math.random(0, 1) ~= 0 or actor_move(actor, (x_direction == DIR_EAST) and DIR_WEST or DIR_EAST, 1) == 0 then
|
||||
|
||||
subtract_map_movement_pts(actor)
|
||||
var_6 = 0 --didn't move anywhere
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
unk_30A72 = 1
|
||||
----dgb("var_6 = "..var_6)
|
||||
--dgb(" now at ("..actor.x..","..actor.y..") dir="..actor.direction.."\n")
|
||||
return var_6
|
||||
|
||||
end
|
||||
|
||||
function toss_actor(actor, from_x, from_y, from_z, arg_0)
|
||||
|
||||
local random = math.random
|
||||
local player_loc = player_get_location()
|
||||
|
||||
for i=1,8 do
|
||||
|
||||
local new_x = random(1, 4) + random(1, 4) + from_x - 5
|
||||
local new_y = random(1, 4) + random(1, 4) + from_y - 5
|
||||
|
||||
if arg_0 == 0
|
||||
or player_loc.x - 5 > new_x or player_loc.x + 5 < new_x or player_loc.y - 5 > new_y or player_loc.y + 5 < new_y then
|
||||
|
||||
if Actor.move(actor, new_x, new_y, from_z) == true then return true end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function actor_has_bad_alignment(actor)
|
||||
return actor.wt == ALIGNMENT_EVIL or actor.wt == ALIGNMENT_CHAOTIC
|
||||
end
|
||||
397
devtools/create_ultima/files/ultima6/scripts/common/common.lua
Normal file
397
devtools/create_ultima/files/ultima6/scripts/common/common.lua
Normal file
@@ -0,0 +1,397 @@
|
||||
--note nuvie direction values aren't the same as the original it uses the following scheme
|
||||
--701
|
||||
--6 2
|
||||
--543
|
||||
|
||||
DIR_NORTH = 0
|
||||
DIR_EAST = 1
|
||||
DIR_SOUTH = 2
|
||||
DIR_WEST = 3
|
||||
DIR_NORTHEAST = 4
|
||||
DIR_SOUTHEAST = 5
|
||||
DIR_SOUTHWEST = 6
|
||||
DIR_NORTHWEST = 7
|
||||
DIR_NONE = 8
|
||||
|
||||
|
||||
UI_STYLE_ORIG = 0
|
||||
UI_STYLE_NEW = 1
|
||||
UI_STYLE_ORIG_PLUS_CUTOFF_MAP = 2
|
||||
UI_STYLE_ORIG_PLUS_FULL_MAP = 3
|
||||
|
||||
STACK_OBJECT_QTY = true
|
||||
|
||||
movement_offset_x_tbl = {0, 1, 1, 1, 0, -1, -1, -1}
|
||||
movement_offset_y_tbl = {-1, -1, 0, 1, 1, 1, 0, -1 }
|
||||
|
||||
if not setfenv then -- Lua 5.2
|
||||
-- based on http://lua-users.org/lists/lua-l/2010-06/msg00314.html
|
||||
-- this assumes f is a function
|
||||
local function findenv(f)
|
||||
local level = 1
|
||||
repeat
|
||||
local name, value = debug.getupvalue(f, level)
|
||||
if name == '_ENV' then return level, value end
|
||||
level = level + 1
|
||||
until name == nil
|
||||
return nil
|
||||
end
|
||||
getfenv = function (f) return(select(2, findenv(f)) or _G) end
|
||||
setfenv = function (f, t)
|
||||
local level = findenv(f)
|
||||
if level then debug.setupvalue(f, level, t) end
|
||||
return f
|
||||
end
|
||||
end
|
||||
|
||||
function get_target()
|
||||
local loc = coroutine.yield("target")
|
||||
|
||||
return loc
|
||||
end
|
||||
|
||||
function get_direction(prompt)
|
||||
|
||||
if prompt ~= nil then
|
||||
print(prompt)
|
||||
end
|
||||
|
||||
local dir = coroutine.yield("dir")
|
||||
|
||||
return dir
|
||||
end
|
||||
|
||||
function really_get_direction(prompt)
|
||||
|
||||
if prompt ~= nil then
|
||||
print(prompt)
|
||||
end
|
||||
|
||||
local dir = coroutine.yield("need_dir")
|
||||
|
||||
return dir
|
||||
end
|
||||
|
||||
function direction_string(dir)
|
||||
if dir ~= nil then
|
||||
if dir == DIR_NORTH then return "north" end
|
||||
if dir == DIR_NORTHEAST then return "northeast" end
|
||||
if dir == DIR_EAST then return "east" end
|
||||
if dir == DIR_SOUTHEAST then return "southeast" end
|
||||
if dir == DIR_SOUTH then return "south" end
|
||||
if dir == DIR_SOUTHWEST then return "southwest" end
|
||||
if dir == DIR_WEST then return "west" end
|
||||
if dir == DIR_NORTHWEST then return "northwest" end
|
||||
end
|
||||
|
||||
return "unknown"
|
||||
end
|
||||
|
||||
local dir_rev_tbl =
|
||||
{
|
||||
[DIR_NORTH] = DIR_SOUTH,
|
||||
[DIR_NORTHEAST] = DIR_SOUTHWEST,
|
||||
[DIR_EAST] = DIR_WEST,
|
||||
[DIR_SOUTHEAST] = DIR_NORTHWEST,
|
||||
[DIR_SOUTH] = DIR_NORTH,
|
||||
[DIR_SOUTHWEST] = DIR_NORTHEAST,
|
||||
[DIR_WEST] = DIR_EAST,
|
||||
[DIR_NORTHWEST] = DIR_SOUTHEAST
|
||||
}
|
||||
|
||||
function direction_reverse(dir) return dir_rev_tbl[dir] end
|
||||
|
||||
local g_dir_offset_tbl =
|
||||
{
|
||||
[DIR_NORTH] = {["x"]=0, ["y"]=-1},
|
||||
[DIR_NORTHEAST] = {["x"]=1, ["y"]=-1},
|
||||
[DIR_EAST] = {["x"]=1, ["y"]=0},
|
||||
[DIR_SOUTHEAST] = {["x"]=1, ["y"]=1},
|
||||
[DIR_SOUTH] = {["x"]=0, ["y"]=1},
|
||||
[DIR_SOUTHWEST] = {["x"]=-1, ["y"]=1},
|
||||
[DIR_WEST] = {["x"]=-1, ["y"]=0},
|
||||
[DIR_NORTHWEST] = {["x"]=-1, ["y"]=-1},
|
||||
[DIR_NONE] = {["x"]=0, ["y"]=0}
|
||||
}
|
||||
|
||||
function direction_get_loc(dir, from_x, from_y)
|
||||
return g_dir_offset_tbl[dir].x + from_x, g_dir_offset_tbl[dir].y + from_y
|
||||
end
|
||||
|
||||
function abs(val)
|
||||
if val < 0 then
|
||||
return -val
|
||||
end
|
||||
|
||||
return val
|
||||
end
|
||||
|
||||
--collect Yes/No input from user and return true if Yes selected. false otherwise.
|
||||
function input_should_proceed()
|
||||
local input = input_select("yn", true)
|
||||
print("\n")
|
||||
if input == nil or input == "N" or input == "n" then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function play_midgame_sequence(seq_num)
|
||||
local ui_style = game_get_ui_style()
|
||||
|
||||
canvas_show()
|
||||
canvas_hide_all_sprites()
|
||||
canvas_set_opacity(0xff);
|
||||
canvas_set_update_interval(25)
|
||||
canvas_rotate_game_palette(true)
|
||||
|
||||
local bg = sprite_new(nil, 8, 16, true)
|
||||
local avatar = sprite_new(nil, 8, 16, false)
|
||||
|
||||
local text_sprite
|
||||
--local text_sprite_bg
|
||||
|
||||
if ui_style == UI_STYLE_ORIG then
|
||||
canvas_set_solid_bg(false)
|
||||
else
|
||||
--[[
|
||||
text_sprite_bg = sprite_new(nil, 8, 160, true)
|
||||
text_sprite_bg.text_align = 2
|
||||
text_sprite_bg.text_color = 14
|
||||
--]]
|
||||
text_sprite = sprite_new(nil, 8, 160, true)
|
||||
text_sprite.text_align = 2
|
||||
text_sprite.text_color = 15
|
||||
bg.x = 80
|
||||
bg.y = 12
|
||||
avatar.x = 80
|
||||
avatar.y = 12
|
||||
end
|
||||
|
||||
local midgame_data = midgame_load("midgame"..string.format("%x", seq_num)..".lzc")
|
||||
local i = 0
|
||||
local data = midgame_data[i]
|
||||
|
||||
|
||||
|
||||
while data ~= nil do
|
||||
bg.image = data.images[0]
|
||||
if data.images[1] ~= nil then
|
||||
local gender = player_get_gender()
|
||||
avatar.image = data.images[1+gender]
|
||||
avatar.visible = true
|
||||
else
|
||||
avatar.visible = false
|
||||
end
|
||||
|
||||
local j = 0
|
||||
local text = data.text[j]
|
||||
while text ~= nil do
|
||||
if text ~= "*END*" then
|
||||
if ui_style == UI_STYLE_ORIG then
|
||||
clear_scroll()
|
||||
print(text)
|
||||
else
|
||||
text_sprite.text = text
|
||||
--text_sprite_bg.text = text
|
||||
end
|
||||
|
||||
local input = nil
|
||||
while input == nil do
|
||||
canvas_update()
|
||||
input = input_poll()
|
||||
if input ~= nil then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
j = j + 1
|
||||
text = data.text[j]
|
||||
end
|
||||
i = i + 1
|
||||
data = midgame_data[i]
|
||||
end
|
||||
|
||||
if ui_style == UI_STYLE_ORIG then
|
||||
clear_scroll()
|
||||
end
|
||||
canvas_set_solid_bg(true)
|
||||
canvas_rotate_game_palette(false)
|
||||
canvas_hide()
|
||||
end
|
||||
|
||||
function get_wrapped_dist(pt1, pt2)
|
||||
local diff
|
||||
|
||||
if pt2 >= pt1 then
|
||||
diff = pt2 - pt1
|
||||
else
|
||||
diff = pt1 - pt2
|
||||
end
|
||||
|
||||
if diff > 512 then
|
||||
diff = 1024 - diff
|
||||
end
|
||||
|
||||
return diff
|
||||
end
|
||||
|
||||
function get_anim_index_for_tile(tile_number)
|
||||
local total_anims = anim_get_number_of_entries()
|
||||
for i=0,total_anims-1 do
|
||||
if anim_get_tile(i) == tile_number then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function altcode_242_set_actor_talk_flag()
|
||||
print("NPC: ")
|
||||
local input = input_select(nil, true)
|
||||
local actor_num = tonumber(input, 16)
|
||||
local actor = Actor.get(actor_num)
|
||||
print("\n"..actor.name.."\n")
|
||||
print("flags: \n") --FIXME print talk flags
|
||||
print("\nBit: ")
|
||||
local bit = input_select_integer(nil, true)
|
||||
local value = Actor.get_talk_flag(actor, bit)
|
||||
local value_str = "off"
|
||||
if value == true then
|
||||
value_str = "on"
|
||||
end
|
||||
print(" is "..value_str..".\n")
|
||||
print("New value? ")
|
||||
value = input_select_integer(nil, true)
|
||||
|
||||
value_str = "off"
|
||||
|
||||
if value == 1 or value == "o" then
|
||||
value_str = "on"
|
||||
Actor.set_talk_flag(actor, bit)
|
||||
else
|
||||
Actor.clear_talk_flag(actor, bit)
|
||||
end
|
||||
print("\n"..value_str.."\n")
|
||||
end
|
||||
|
||||
function altcode_250_create_object()
|
||||
print("Create Item:\nType:0x")
|
||||
local input = input_select(nil, true)
|
||||
local obj_n = tonumber(input, 16)
|
||||
local obj = Obj.new(obj_n)
|
||||
local tmp_obj = Obj.new(obj_n+1)
|
||||
if tmp_obj ~= nil and tmp_obj.tile_num - obj.tile_num > 1 then
|
||||
print("\nFrame:0x")
|
||||
input = input_select(nil, true)
|
||||
obj.frame_n = tonumber(input, 16)
|
||||
end
|
||||
|
||||
print("\nQual:0x")
|
||||
input = input_select(nil, true)
|
||||
obj.quality = tonumber(input, 16)
|
||||
|
||||
if obj.stackable or create_object_needs_quan(obj_n) then
|
||||
print("\nQuan:0x")
|
||||
input = input_select(nil, true)
|
||||
obj.qty = tonumber(input, 16)
|
||||
end
|
||||
Obj.moveToInv(obj, Actor.get(1).actor_num)
|
||||
print("\n")
|
||||
end
|
||||
|
||||
function altcode_913_export_tmx_map_files()
|
||||
print("\nExport maps to savedir? ")
|
||||
|
||||
if not input_should_proceed() then
|
||||
return
|
||||
end
|
||||
|
||||
print("saving.\n")
|
||||
script_wait(1)
|
||||
if map_export_tmx_files() == true then
|
||||
print("done.\n\n")
|
||||
else
|
||||
print("error!!\n\n")
|
||||
end
|
||||
end
|
||||
|
||||
function altcode_914_export_tileset()
|
||||
print("Exporting tileset to \"data/images/tiles/"..config_get_game_type().."/custom_tiles.bmp\" in the savegame directory.\n")
|
||||
if not tileset_export() then
|
||||
print("file already exists. Overwrite? ")
|
||||
if not input_should_proceed() then
|
||||
return
|
||||
end
|
||||
tileset_export(true)
|
||||
end
|
||||
print("done.\n\n")
|
||||
end
|
||||
|
||||
function altcode_999_find_objs_on_map()
|
||||
print("Find Object\nObj_n: ")
|
||||
local input = input_select(nil, true)
|
||||
local obj_n = tonumber(input, 10)
|
||||
if obj_n == nil then
|
||||
print("Nothing.\n")
|
||||
return
|
||||
end
|
||||
print("\nFrame: ")
|
||||
input = input_select(nil, true)
|
||||
local frame_n = tonumber(input, 10)
|
||||
print("\nQuality: ")
|
||||
input = input_select(nil, true)
|
||||
local quality = tonumber(input, 10)
|
||||
print("\nz: ")
|
||||
input = input_select(nil, true)
|
||||
local z = tonumber(input, 10)
|
||||
if z == nil then
|
||||
z = 0
|
||||
end
|
||||
print("\n")
|
||||
for obj in find_obj(z, obj_n, frame_n, quality) do
|
||||
print(string.format("OBJ: (%x,%x,%x)\n", obj.x, obj.y, obj.z))
|
||||
party_move(obj.x, obj.y, obj.z)
|
||||
print("continue? ")
|
||||
input = input_select("yn", false)
|
||||
print("\n")
|
||||
if input == "N" or input == "n" then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local altcode_tbl = {
|
||||
[242]=altcode_242_set_actor_talk_flag,
|
||||
[250]=altcode_250_create_object,
|
||||
[913]=altcode_913_export_tmx_map_files,
|
||||
[914]=altcode_914_export_tileset,
|
||||
[999]=altcode_999_find_objs_on_map,
|
||||
}
|
||||
|
||||
function handle_alt_code(altcode)
|
||||
local func = altcode_tbl[altcode]
|
||||
if func ~= nil then
|
||||
func()
|
||||
end
|
||||
end
|
||||
|
||||
function get_actor_or_obj_from_loc(location)
|
||||
local target = map_get_actor(location)
|
||||
if target == nil then
|
||||
target = map_get_obj(location)
|
||||
end
|
||||
return target
|
||||
end
|
||||
|
||||
--load other common functions
|
||||
|
||||
local lua_file = nil
|
||||
|
||||
lua_file = nuvie_load("common/lang.lua");
|
||||
lua_file();
|
||||
lang_init("game")
|
||||
|
||||
lua_file = nuvie_load("common/actor.lua"); lua_file();
|
||||
@@ -0,0 +1,348 @@
|
||||
-- input value constants
|
||||
MOUSE_CLICK = 0
|
||||
MOUSE_MOTION = 1
|
||||
SDLK_BACKSPACE = 8
|
||||
SDLK_RETURN = 13
|
||||
SDLK_ESCAPE = 27
|
||||
SDLK_SPACE = 32
|
||||
SDLK_a = 97
|
||||
SDLK_b = 98
|
||||
SDLK_c = 99
|
||||
SDLK_g = 103
|
||||
SDLK_i = 105
|
||||
SDLK_j = 106
|
||||
SDLK_q = 113
|
||||
SDLK_r = 114
|
||||
SDLK_s = 115
|
||||
SDLK_t = 116
|
||||
SDLK_KP2 = 258
|
||||
SDLK_KP4 = 260
|
||||
SDLK_KP6 = 262
|
||||
SDLK_KP8 = 264
|
||||
SDLK_KP_ENTER = 271
|
||||
SDLK_UP = 82 + 1073741824
|
||||
SDLK_DOWN = 81 + 1073741824
|
||||
SDLK_RIGHT = 79 + 1073741824
|
||||
SDLK_LEFT = 80 + 1073741824
|
||||
|
||||
|
||||
function trim_string(s)
|
||||
return s:match'^%s*(.*%S)' or ''
|
||||
end
|
||||
|
||||
function wait_for_input()
|
||||
local input = nil
|
||||
while input == nil do
|
||||
canvas_update()
|
||||
input = input_poll()
|
||||
if input ~= nil then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return input
|
||||
end
|
||||
|
||||
local g_should_exit = false
|
||||
|
||||
function clear_should_exit_flag()
|
||||
g_should_exit = false
|
||||
end
|
||||
|
||||
function should_exit()
|
||||
return g_should_exit
|
||||
end
|
||||
|
||||
function poll_for_input()
|
||||
input = input_poll()
|
||||
if input ~= nil then
|
||||
if input == SDLK_ESCAPE then
|
||||
g_should_exit = true
|
||||
end
|
||||
end
|
||||
|
||||
if engine_should_quit() == 1 then
|
||||
g_should_exit = true
|
||||
end
|
||||
|
||||
return input
|
||||
end
|
||||
|
||||
function poll_for_key_or_button(cycles)
|
||||
local input
|
||||
|
||||
if engine_should_quit() == 1 then
|
||||
g_should_exit = true
|
||||
return true
|
||||
end
|
||||
|
||||
if cycles == nil then
|
||||
input = input_poll()
|
||||
if input ~= nil then
|
||||
if input == SDLK_ESCAPE then
|
||||
g_should_exit = true
|
||||
end
|
||||
return true
|
||||
end
|
||||
else
|
||||
local i
|
||||
for i=0,cycles,1 do
|
||||
local input = input_poll()
|
||||
if input ~= nil then
|
||||
if input == SDLK_ESCAPE then
|
||||
g_should_exit = true
|
||||
end
|
||||
return true
|
||||
end
|
||||
if engine_should_quit() == 1 then
|
||||
g_should_exit = true
|
||||
return true
|
||||
end
|
||||
canvas_update()
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function poll_for_esc(cycles)
|
||||
local input
|
||||
if cycles == nil then
|
||||
input = input_poll()
|
||||
if input ~= nil and input == SDLK_ESCAPE then
|
||||
return true
|
||||
end
|
||||
if engine_should_quit() == 1 then
|
||||
return true
|
||||
end
|
||||
else
|
||||
local i
|
||||
for i=0,cycles,1 do
|
||||
local input = input_poll()
|
||||
if input ~= nil and input == SDLK_ESCAPE then
|
||||
return true
|
||||
end
|
||||
if engine_should_quit() == 1 then
|
||||
return true
|
||||
end
|
||||
canvas_update()
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function fade_in(speed)
|
||||
if speed == nil then
|
||||
speed = 3
|
||||
end
|
||||
|
||||
local i
|
||||
for i=0x0,0xff,speed do
|
||||
canvas_set_opacity(i)
|
||||
canvas_update()
|
||||
|
||||
if engine_should_quit() == 1 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function fade_out(speed)
|
||||
if speed == nil then
|
||||
speed = 3
|
||||
end
|
||||
|
||||
local i
|
||||
for i=0xff,0,-speed do
|
||||
canvas_set_opacity(i)
|
||||
canvas_update()
|
||||
|
||||
if engine_should_quit() == 1 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function update_players(players, img_tbl)
|
||||
local rand = math.random
|
||||
|
||||
players[1].image = img_tbl[1][rand(0,12)]
|
||||
players[2].image = img_tbl[2][rand(0,8)]
|
||||
players[3].image = img_tbl[3][rand(0,2)]
|
||||
players[4].image = img_tbl[4][rand(0,6)]
|
||||
players[5].image = img_tbl[5][rand(0,4)]
|
||||
players[6].image = img_tbl[6][rand(0,2)]
|
||||
players[7].image = img_tbl[7][rand(0,4)]
|
||||
players[8].image = img_tbl[8][rand(0,4)]
|
||||
players[9].image = img_tbl[9][rand(0,3)]
|
||||
|
||||
end
|
||||
|
||||
function create_player_sprite(image, x, y)
|
||||
local sprite = sprite_new(image, x, y, true)
|
||||
sprite.clip_x = 0
|
||||
sprite.clip_y = 0
|
||||
sprite.clip_w = 320
|
||||
sprite.clip_h = 152
|
||||
|
||||
return sprite
|
||||
end
|
||||
|
||||
function create_sprite(image, x, y)
|
||||
local sprite = sprite_new(image, x, y, true)
|
||||
sprite.clip_x = 0
|
||||
sprite.clip_y = 24
|
||||
sprite.clip_w = 320
|
||||
sprite.clip_h = 128
|
||||
return sprite
|
||||
end
|
||||
|
||||
function create_firework(img_tbl)
|
||||
local rand = math.random
|
||||
local colour = rand(0,2)
|
||||
local exp = {create_sprite(img_tbl[11][8*colour], rand(0,319), rand(0,127)), colour, 0}
|
||||
return exp
|
||||
end
|
||||
|
||||
function fireworks_update(exp_tbl, img_tbl)
|
||||
local exp_finished = 0
|
||||
local k,v
|
||||
for k,v in pairs(exp_tbl) do
|
||||
if v[3] == 7 then
|
||||
v[1].visible = false
|
||||
table.remove(exp_tbl, k)
|
||||
exp_finished = exp_finished + 1
|
||||
else
|
||||
v[3] = v[3] + 1
|
||||
v[1].image = img_tbl[11][8*v[2]+v[3]]
|
||||
end
|
||||
end
|
||||
|
||||
return exp_finished
|
||||
end
|
||||
|
||||
function fireworks(img_tbl, logo)
|
||||
local rand = math.random
|
||||
local exp_tbl = {}
|
||||
local exp_count = 0
|
||||
local i
|
||||
for i=0,125 do
|
||||
if exp_count < 5 then
|
||||
if rand(0,5) == 0 then
|
||||
local exp = create_firework(img_tbl)
|
||||
table.insert(exp_tbl, exp)
|
||||
exp_count = exp_count + 1
|
||||
sprite_move_to_front(logo)
|
||||
play_sfx(12, false)
|
||||
end
|
||||
end
|
||||
local num_finished = fireworks_update(exp_tbl, img_tbl)
|
||||
exp_count = exp_count - num_finished
|
||||
poll_for_esc(1)
|
||||
end
|
||||
|
||||
--wait for remaining explosions to finish
|
||||
while exp_count > 0 do
|
||||
local num_finished = fireworks_update(exp_tbl, img_tbl)
|
||||
exp_count = exp_count - num_finished
|
||||
poll_for_esc(1)
|
||||
end
|
||||
|
||||
poll_for_esc(10)
|
||||
|
||||
-- create final 30 explosions.
|
||||
for i=1,30 do
|
||||
local exp = create_firework(img_tbl)
|
||||
table.insert(exp_tbl, exp)
|
||||
exp_count = exp_count + 1
|
||||
end
|
||||
|
||||
while exp_count > 0 do
|
||||
local num_finished = fireworks_update(exp_tbl, img_tbl)
|
||||
exp_count = exp_count - num_finished
|
||||
poll_for_esc(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function display_image_table(img_tbl, x, y)
|
||||
if x == nil then
|
||||
x = 160
|
||||
end
|
||||
|
||||
if y == nil then
|
||||
y = 100
|
||||
end
|
||||
|
||||
local sprite = sprite_new(nil, x, y, true)
|
||||
|
||||
local text_sprite = sprite_new(nil, 100, 180, true)
|
||||
|
||||
local i = 0
|
||||
for k,v in pairs(img_tbl) do
|
||||
if type(v) == "table" then
|
||||
local j = 0
|
||||
for l,m in pairs(v) do
|
||||
|
||||
local img = image_new(50,20)
|
||||
text_sprite.image = img
|
||||
image_print(img, "("..k..","..l..")", 0, 50, 0, 8, 0x6)
|
||||
sprite.image = m
|
||||
wait_for_input()
|
||||
j = j + 1
|
||||
end
|
||||
else
|
||||
local img = image_new(50,20)
|
||||
text_sprite.image = img
|
||||
image_print(img, "("..k..",x)", 0, 50, 0, 8, 0x6)
|
||||
sprite.image = v
|
||||
wait_for_input()
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
function about_martian_dreams()
|
||||
canvas_hide_all_sprites()
|
||||
local bg = sprite_new(image_load("mars.lzc", 0), 0, 24, true)
|
||||
|
||||
local text_tbl = text_load("scenetxt.lzc", 4)
|
||||
music_play("mdd_mus.lzc", 8)
|
||||
|
||||
local sprites = {}
|
||||
local i
|
||||
for i=0,81 do
|
||||
local s = sprite_new(nil, 11, 153 + i * 14, true)
|
||||
s.text_color = 6
|
||||
s.text = text_tbl[i]
|
||||
table.insert(sprites, s)
|
||||
|
||||
s = sprite_new(nil, 12, 152 + i * 14, true)
|
||||
s.text_color = 14
|
||||
s.text = text_tbl[i]
|
||||
table.insert(sprites, s)
|
||||
end
|
||||
|
||||
--black bars for the top and bottom of the screen.
|
||||
--These hide the text as it is scrolling in and out.
|
||||
sprite_new(image_new(220, 24, 0), 0, 0, true)
|
||||
sprite_new(image_new(220, 48, 0), 0, 152, true)
|
||||
|
||||
--scroll the text up the screen
|
||||
for i=0,90*14 do
|
||||
local j
|
||||
for j=1,82*2 do
|
||||
sprites[j].y = sprites[j].y - 1
|
||||
end
|
||||
poll_for_key_or_button(2)
|
||||
if should_exit() then
|
||||
fade_out()
|
||||
return
|
||||
end
|
||||
end
|
||||
music_stop()
|
||||
fade_out()
|
||||
end
|
||||
58
devtools/create_ultima/files/ultima6/scripts/common/lang.lua
Normal file
58
devtools/create_ultima/files/ultima6/scripts/common/lang.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
local lang
|
||||
local lang_en
|
||||
|
||||
local game_type = config_get_game_type()
|
||||
local lang_selected = config_get_language()
|
||||
|
||||
function lang_init(lang_type)
|
||||
if lang_type ~= "intro" then
|
||||
lang_type = "game"
|
||||
end
|
||||
|
||||
lang_en = nuvie_load(string.lower(game_type).."/lang/en/"..lang_type..".lua")
|
||||
|
||||
if lang_en == nil then
|
||||
lang_en = {}
|
||||
else
|
||||
lang_en = lang_en()
|
||||
end
|
||||
|
||||
if lang_selected ~= "en" then
|
||||
lang = nuvie_load(string.lower(game_type).."/lang/"..lang_selected.."/"..lang_type..".lua")
|
||||
if lang == nil then
|
||||
lang = lang_en
|
||||
else
|
||||
lang = lang()
|
||||
end
|
||||
else
|
||||
lang = lang_en
|
||||
end
|
||||
end
|
||||
|
||||
function i18n(code)
|
||||
local str = lang[code]
|
||||
if str == nil then
|
||||
str = lang_en[code]
|
||||
end
|
||||
if str == nil then
|
||||
str = code
|
||||
end
|
||||
return str;
|
||||
end
|
||||
|
||||
function i18nf(code, ...)
|
||||
return string.format(i18n(code), ...)
|
||||
end
|
||||
|
||||
function printnl(code)
|
||||
print("\n"..i18n(code))
|
||||
end
|
||||
|
||||
function printl(code)
|
||||
print(i18n(code))
|
||||
end
|
||||
|
||||
function printfl(code, ...)
|
||||
print(i18nf(code, ...))
|
||||
end
|
||||
Reference in New Issue
Block a user