-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
166 lines (135 loc) · 4.33 KB
/
main.lua
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
--------------------------------------------------------------------------------
-- Copyright (c) 2015 Jason Lynch <[email protected]>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Setup
--------------------------------------------------------------------------------
CONFIG = require "config"
local battle = require "ai.battle"
local bridge = require "util.bridge"
local dialog = require "util.dialog"
local input = require "util.input"
local route = require "util.route"
local log = require "util.log"
local menu = require "action.menu"
local sequence = require "ai.sequence"
local walk = require "action.walk"
FULL_RUN = emu.framecount() == 1
INITIALIZED = false
--------------------------------------------------------------------------------
-- Functions
--------------------------------------------------------------------------------
local function _get_version()
local file = io.popen("git describe --tags --dirty", "r")
local version_full = file:read('*all')
if version_full == "" then
return "v0.0.9-dev"
else
return string.match(string.match(version_full, "%S.*"), ".*%S")
end
end
local function _set_route()
ROUTES = {"no64-excalbur", "no64-rosa", "nocw", "paladin"}
NO64_ROUTES = {"no64-excalbur", "no64-rosa"}
math.randomseed(os.time())
if CONFIG.ROUTE then
if CONFIG.ROUTE == "no64" then
return NO64_ROUTES[math.random(#NO64_ROUTES)]
else
return CONFIG.ROUTE
end
else
return ROUTES[math.random(#ROUTES)]
end
end
local function _set_encounter_seed()
if CONFIG.ENCOUNTER_SEED then
return CONFIG.ENCOUNTER_SEED
else
return math.random(0, 255)
end
end
local function _set_seed()
local seed = CONFIG.SEED
if not seed then
math.randomseed(os.time())
math.random()
math.random()
math.random()
seed = math.random(0, 2147483646)
end
if SEED and CONFIG.AUTOMATIC and CONFIG.SEED ~= nil then
seed = SEED + 1
end
math.randomseed(seed)
_ = math.random()
_ = math.random()
_ = math.random()
return seed
end
local function _reset()
ROUTE = _set_route()
ENCOUNTER_SEED = _set_encounter_seed()
SEED = _set_seed()
log.reset()
log.log("Edge Final Fantasy IV Speed Run Bot")
log.log("-----------------------------------")
log.log(string.format("Version: %s", _get_version()))
if FULL_RUN then
log.log("Beginning Full Run")
log.log(string.format("Route: %s", ROUTE))
log.log(string.format("Encounter Seed: %d", ENCOUNTER_SEED))
log.log(string.format("RNG Seed: %d", SEED))
else
log.log("Beginning Test Mode")
end
bridge.reset()
menu.reset()
route.reset()
walk.reset()
dialog.reset()
battle.reset()
sequence.reset()
INITIALIZED = true
end
--------------------------------------------------------------------------------
-- Main Loop
--------------------------------------------------------------------------------
while true do
if emu.framecount() == 1 or not INITIALIZED then
FULL_RUN = emu.framecount() == 1
_reset()
end
dialog.cycle()
if not battle.cycle() and sequence.is_active() then
sequence.cycle()
end
if FULL_RUN and sequence.is_end() then
log.log("Rebooting...")
client.reboot_core()
end
if CONFIG.OVERLAY then
sequence.draw_overlay()
end
bridge.cycle()
input.cycle()
emu.frameadvance()
end