-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.ttslua
218 lines (202 loc) · 6.72 KB
/
global.ttslua
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
-- http://steamcommunity.com/sharedfiles/filedetails/?id=924691456
function onload()
GM_NOTES_NAME_FOR_THING_CARD = "A"
GM_NOTES_NAME_FOR_SUCCESS = "S"
GM_NOTES_NAME_FOR_FAILURE = "F"
GAME_STATES = {
"Briefing", "Assignments", "Work", "Debrief", "Assimilation",
"Isolation"
}
CURRENT_GAME_STATE = 1
BLINDNESS = false
MIN_PLAYERS = 6
MAX_PLAYERS = 9
ACTUAL_PLAYERS = nil
TOTAL_CARDS_IN_DECK = 52 -- unreliable above ~60. depends on decks 8938e8, 3d5c94 ingame
RATIO_OF_SUCCESS_TO_FAILURE = 6/10
MISSIONS_PER_PLAYERS = {
[6] = 12,
[7] = 13,
[8] = 14,
[9] = 16
}
MISSIONS_TO_COMPLETE = nil
end
--[[ getters ]]
get_game_state = function()
-- consumes nothing and produces the name of the current game state.
return GAME_STATES[CURRENT_GAME_STATE + 1]
end
format_game_state = function()
-- utility function which produces a string describing the current game
-- state in the format "PHASE NUMBER - PHASE NAME"
-- example: "1 - Briefing"
fstring = "%i: %s"
current_state = get_game_state()
current_state_number = CURRENT_GAME_STATE + 1
return string.format(fstring, current_state_number, current_state)
end
--[[ setters ]]
missions_to_complete = function(nOrNil)
-- consumes a NumberOrNil and produces nil, if the NumberOrNil is
-- nil, or a number of missions the players must complete, based on
-- their number, n.
if nOrNil == nil then
return nil
elseif (nOrNil < MIN_PLAYERS) or (nOrNil > MAX_PLAYERS) then
printToAll("invalid call to missions_to_complete: n out of bounds")
return nil
else
local number_of_missions = MISSIONS_PER_PLAYERS[nOrNil]
return number_of_missions
end
return "nothing"
end
advance_game_state = function()
--- consumes nothing and advances the current game state.
--- returns a formatted description of the new game state.
CURRENT_GAME_STATE = (CURRENT_GAME_STATE + 1) % #GAME_STATES
return format_game_state()
end
reverse_game_state = function()
--- consumes nothing and reverses the current game state
candidate = CURRENT_GAME_STATE - 1
if candidate < 0 then
CURRENT_GAME_STATE = #GAME_STATES - 1
else
CURRENT_GAME_STATE = candidate
end
return get_game_state()
end
--[[ predicates ]]
function is_taskcard_p(any)
-- consumes whatever object and returns 'true' if it's a taskcard,
-- false otherwise.
local name_or_nil = any.getName()
return string.find(name_or_nil, "::") ~= nil
end
function is_taskcard_desc_p(any)
-- consumes whatever table and returns "true" if it represents the *description* of
-- a taskcard
local name_or_nil = any.name
return string.find(name_or_nil, "::") ~= nil
end
--[[ functions to assist working with "types"]]
function get_quasi_type(obj)
-- consumes an object and gets a TTS quasi-type
return obj_parse_to_string(tostring(obj))[1]
end
function obj_parse_to_string(obj)
-- consumes an object and produces a table representing the parsed
-- components of its tostring output
str = tostring(obj)
elements = string.gmatch(str, "[%a_]+")
result_table = {}
i = 1
for element in elements do
result_table[i] = element
i = i + 1
end
return result_table
end
--[[ card-counting functions ]]
function count_successes(deckOrCard)
-- consumes an object and produces and produces
-- the number of cards in the suits of hearts and
-- diamonds it contains.
item_class = get_quasi_type(deckOrCard)
if item_class == "Card" then
return card_count_successes(deckOrCard)
elseif item_class == "Deck" then
return deck_count_successes(deckOrCard)
else
return -1
end
end
function count_jokers(deckOrCard)
-- consumes an object and produces the number of
-- jokers it contains. Returns -1 if the items could
-- not be, or contain, a Joker.
item_class = get_quasi_type(deckOrCard)
if item_class == "Card" then
return card_count_jokers(deckOrCard)
elseif item_class == "Deck" then
return deck_count_jokers(deckOrCard)
else
return -1
end
end
function card_count_jokers(card)
-- consumes a card and produces 1 if it's a joker, 0
-- otherwise
if is_a_joker(card) then
return 1
else
return 0
end
end
function is_a_joker(obj)
-- consumes an object and produces 'true' if the card's a joker,
-- false otherwise
return obj.getGMNotes() == GM_NOTES_NAME_FOR_THING_CARD
end
function card_desc_is_a_joker(card_desc)
-- consumes a card-description (result of deck.getObjects)
-- and produces 'true' if the description is of a joker,
-- 'false' otherwise
return card_desc.gm_notes == GM_NOTES_NAME_FOR_THING_CARD
end
function deck_count_jokers(deck)
-- consumes a deck and produces the number of jokers it contains
cards = deck.getObjects()
local count = 0
for _, card_desc in pairs(cards) do
if card_desc_is_a_joker(card_desc) then count = count + 1 end
end
return count
end
function card_is_success(card)
-- consumes a card and produces 'true' if it's
-- a success, 'false' otherwise
return card.getGMNotes() == GM_NOTES_NAME_FOR_SUCCESS
end
function card_count_successes(card)
-- consumes a card and produces 1 if that card is a success,
-- 0 otherwise
if card_is_success(card) then
return 1
else
return 0
end
end
function card_desc_is_success(card_desc)
-- consumes a card_description and produces
-- true if it represents a success card, false otherwise.
return card_desc.gm_notes == GM_NOTES_NAME_FOR_SUCCESS
end
function deck_count_successes(deck)
-- consumes a deck and produces the number of successes in it.
cards = deck.getObjects()
local count = 0
for _, card_desc in pairs(cards) do
if card_desc_is_success(card_desc) then count = count + 1 end
end
return count
end
--[[ functions helping to manage collision-based objects ]]
function should_ignore_collision_p(collision_info)
if collision_info.collision_object == nil or
collision_info.collision_object == self or
collision_info.collision_object.getGUID() == nil or
collision_info.collision_object.tag == "Surface" or
collision_info.collision_object.tag == "Board" or objectLoaded then
return true
else
return false
end
end
--[[ The OnLoad function. This is called after everything in the game save finishes loading.
Most of your script code goes here. --]]
--[[ Lua code. See documentation: http://berserk-games.com/knowledgebase/scripting/ --]]
--[[ The Update function. This is called once per frame. --]]
function update() --[[ print('Update loop!') --]]end