File: usecode.lua

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (94 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
local USE_EVENT_USE = 0x01

function use_telescope(obj, actor)
	if obj.on_map == true then
		mapwindow_center_at_location(obj.x, obj.y, obj.z)
	else -- FIXME - should probably work in the inventory (can't be done without cheating though)
		print("Not usable\n")
		return
	end
	local dir = really_get_direction("Direction-")
	if dir == nil or dir == DIR_NONE then
		mapwindow_center_at_location(actor.x, actor.y, actor.z)
		print("nowhere.\n")
		return
	end
	local dir_string = direction_string(dir)
	dir_string = dir_string:gsub("^%l", string.upper)
	print(dir_string..".\n")

	local loc = mapwindow_get_location()

	--FIXME need to fade out blacking.

	mapwindow_set_enable_blacking(false)

	for i=0,40 do
		loc.x,loc.y = direction_get_loc(dir,loc.x, loc.y)
		mapwindow_set_location(loc.x, loc.y, loc.z)
		script_wait(50)
	end

	script_wait(600)

	mapwindow_set_enable_blacking(true)

	mapwindow_center_at_location(actor.x, actor.y, actor.z)
	print("\nDone\n")

end

function use_silver_horn(obj, actor)
	local i
	for i=0,0xff do
		local tmp_actor = Actor.get(i)
		if tmp_actor.obj_n == 413 and tmp_actor.alive == true and actor_find_max_xy_distance(tmp_actor, actor.x, actor.y) <= 8 then
			print("Not now!\n")
			return
		end
	end

	local random = math.random

	for i=1,3 do
		local new_x = random(1, 7) + random(1, 7) + actor.x - 8
		local new_y = random(1, 7) + random(1, 7) + actor.y - 8
		local snake = Actor.new(413, new_x, new_y, actor.z, ALIGNMENT_CHAOTIC)
	end

	print("Silver snakes are generated!\n")
end


local usecode_table = {
[154]=use_telescope,
[313]=use_silver_horn
}

function has_usecode(obj, usecode_type)
	if usecode_type == USE_EVENT_USE and usecode_table[obj.obj_n] ~= nil then
		return true
	end

	return false
end

function use_obj(obj, actor)
	if type(usecode_table[obj.obj_n]) == "function" then
		local func = usecode_table[obj.obj_n]
		if func ~= nil then
			print("\n")
			func(obj, actor)
		end
	else
		use_obj_on(obj, actor, usecode_table[obj.obj_n])
	end
end

function move_obj(obj, rel_x, rel_y)
  return false
end

function is_ranged_select(operation)
    return false
end