· 6 years ago · Aug 31, 2019, 02:10 AM
1--[[------------
2 Data used by this script.
3--]]------------
4
5-- Which decks to shuffle at the beginning of the heist.
6local shuffleDecks = {
7 "Character Deck", "Event Deck", "Tool Deck", "Loot Deck",
8 "Room Deck", "Patrol1 Deck", "Patrol2 Deck", "Patrol3 Deck" }
9
10math.randomseed(os.time())
11
12-- Table of wall positions for each layout.
13-- Positions are numbered: 1-12 are N-S walls, 13-24 are E-W.
14-- Walls positions count left-to-right, then top-to-bottom.
15-- The wall positions are used by getWallLoc() to find coordinates and facings.
16local walls = {}
17
18wallLayouts = {}
19wallLayouts[ 1 ] = { 1, 6, 10, 11, 15, 17, 18, 24 }
20wallLayouts[ 2 ] = { 1, 2, 3, 10, 11, 12, 18, 19 }
21wallLayouts[ 3 ] = { 4, 6, 7, 8, 12, 15, 17, 19 }
22wallLayouts[ 4 ] = { 3, 4, 5, 17, 18, 19, 21, 23 }
23wallLayouts[ 5 ] = { 1, 4, 5, 6, 7, 11, 15, 16 }
24wallLayouts[ 6 ] = { 5, 6, 11, 13, 14, 19, 22, 24 }
25wallLayouts[ 7 ] = { 4, 8, 14, 15, 18, 19, 20, 22 }
26wallLayouts[ 8 ] = { 5, 6, 14, 18, 19, 20, 21, 24 }
27wallLayouts[ 9 ] = { 1, 4, 5, 6, 7, 11, 16, 19 }
28wallLayouts[ 10 ] = { 4, 7, 8, 14, 15, 17, 22, 24 }
29wallLayouts[ 11 ] = { 6, 9, 14, 17, 18, 20, 22, 23 }
30wallLayouts[ 12 ] = { 2, 6, 7, 11, 14, 16, 19, 22 }
31wallLayouts[ 13 ] = { 1, 6, 7, 8, 12, 15, 18, 21 }
32wallLayouts[ 14 ] = { 7, 9, 10, 12, 15, 16, 18, 23 }
33wallLayouts[ 15 ] = { 4, 5, 6, 8, 9, 10, 16, 22 }
34wallLayouts[ 16 ] = { 4, 5, 6, 7, 8, 12, 17, 18 }
35wallLayouts[ 17 ] = { 5, 6, 7, 9, 10, 14, 22, 23 }
36wallLayouts[ 18 ] = { 3, 4, 6, 9, 10, 15, 19, 23 }
37wallLayouts[ 19 ] = { 1, 3, 4, 9, 10, 14, 19, 22 }
38wallLayouts[ 20 ] = { 2, 5, 6, 12, 13, 18, 20, 23 }
39wallLayouts[ 21 ] = { 4, 5, 6, 7, 9, 10, 15, 24 }
40wallLayouts[ 22 ] = { 2, 3, 6, 7, 10, 13, 19, 22 }
41wallLayouts[ 23 ] = { 1, 5, 8, 9, 15, 20, 21, 23 }
42wallLayouts[ 24 ] = { 1, 3, 5, 7, 8, 17, 22, 23 }
43wallLayouts[ 25 ] = { 2, 11, 12, 13, 15, 17, 18, 20 }
44wallLayouts[ 26 ] = { 4, 6, 7, 8, 15, 19, 22, 24 }
45wallLayouts[ 27 ] = { 2, 4, 5, 11, 13, 19, 22, 23 }
46wallLayouts[ 28 ] = { 1, 2, 8, 10, 17, 20, 22, 24 }
47wallLayouts[ 29 ] = { 9, 12, 14, 16, 17, 18, 21, 22 }
48wallLayouts[ 30 ] = { 1, 4, 7, 14, 16, 19, 23, 24 }
49wallLayouts[ 31 ] = { 1, 7, 12, 15, 16, 20, 21, 23 }
50wallLayouts[ 32 ] = { 3, 5, 7, 8, 14, 15, 18, 24 }
51wallLayouts[ 33 ] = { 4, 6, 7, 12, 14, 15, 19, 23 }
52wallLayouts[ 34 ] = { 3, 4, 7, 8, 10, 18, 20, 23 }
53wallLayouts[ 35 ] = { 1, 7, 8, 11, 16, 18, 19, 23 }
54wallLayouts[ 36 ] = { 2, 4, 7, 15, 17, 18, 23, 24 }
55wallLayouts[ 37 ] = { 1, 2, 3, 4, 11, 20, 21, 23 }
56wallLayouts[ 38 ] = { 2, 6, 11, 12, 16, 18, 19, 21 }
57wallLayouts[ 39 ] = { 5, 6, 9, 11, 14, 18, 22, 23 }
58wallLayouts[ 40 ] = { 2, 4, 5, 9, 16, 17, 21, 23 }
59wallLayouts[ 41 ] = { 6, 11, 12, 13, 14, 19, 20, 22 }
60wallLayouts[ 42 ] = { 4, 6, 8, 11, 15, 18, 22, 23 }
61wallLayouts[ 43 ] = { 2, 4, 8, 10, 14, 16, 19, 20 }
62wallLayouts[ 44 ] = { 7, 9, 10, 13, 14, 15, 19, 24 }
63wallLayouts[ 45 ] = { 5, 11, 14, 15, 16, 18, 19, 21 }
64wallLayouts[ 46 ] = { 1, 2, 6, 9, 11, 12, 17, 21 }
65wallLayouts[ 47 ] = { 3, 7, 8, 9, 11, 12, 14, 17 }
66wallLayouts[ 48 ] = { 2, 4, 5, 13, 16, 20, 22, 23 }
67wallLayouts[ 49 ] = { 2, 6, 9, 11, 12, 17, 19, 22 }
68wallLayouts[ 50 ] = { 5, 7, 10, 12, 13, 18, 20, 23 }
69wallLayouts[ 51 ] = { 4, 10, 12, 13, 15, 18, 19, 22 }
70wallLayouts[ 52 ] = { 1, 3, 5, 11, 14, 19, 21, 23 }
71wallLayouts[ 53 ] = { 1, 8, 11, 15, 17, 20, 21, 23 }
72wallLayouts[ 54 ] = { 2, 3, 4, 7, 8, 12, 17, 22 }
73wallLayouts[ 55 ] = { 1, 2, 3, 5, 12, 18, 21, 23 }
74wallLayouts[ 56 ] = { 5, 6, 7, 9, 14, 19, 22, 24 }
75wallLayouts[ 57 ] = { 2, 7, 8, 9, 10, 13, 23, 24 }
76wallLayouts[ 58 ] = { 2, 8, 10, 11, 12, 14, 18, 19 }
77wallLayouts[ 59 ] = { 2, 3, 5, 7, 10, 11, 12, 20 }
78wallLayouts[ 60 ] = { 2, 6, 9, 10, 12, 13, 19, 22 }
79
80
81-- 3-floor layouts. The first is "The Bank Job" from the rulebook,
82-- the rest were generated from <http://gabob.com/burgle/>
83walls.bank = {}
84
85walls.bank[ 1 ] = {}
86tmpRand=math.random( 1, 60 )
87print("Setting floor 1 to #"..tmpRand)
88walls.bank[1][1] = wallLayouts[math.random( 1, 60 )]
89tmpRand=math.random( 1, 60 )
90print("Setting floor 2 to #"..tmpRand)
91walls.bank[1][2] = wallLayouts[math.random( 1, 60 )]
92tmpRand=math.random( 1, 60 )
93print("Setting floor 3 to #"..tmpRand)
94walls.bank[1][3] = wallLayouts[math.random( 1, 60 )]
95
96
97
98
99-- 2-floor layouts. The first is "The Office Job" from the rulebook,
100-- the rest were generated from <http://gabob.com/burgle/>
101walls.office = {}
102
103walls.office[ 1 ] = {}
104walls.office[1][1] = { 1, 2, 4, 6, 8, 16, 22, 24 }
105walls.office[1][2] = { 4, 5, 6, 7, 8, 16, 17, 24 }
106
107walls.office[ 2 ] = {}
108walls.office[2][1] = { 5, 6, 7, 8, 9, 11, 21, 23 }
109walls.office[2][2] = { 1, 3, 8, 11, 12, 14, 18, 19 }
110
111walls.office[ 3 ] = {}
112walls.office[3][1] = { 2, 4, 6, 9, 11, 12, 18, 19 }
113walls.office[3][2] = { 1, 3, 5, 11, 12, 15, 18, 22 }
114
115walls.office[ 4 ] = {}
116walls.office[4][1] = { 4, 6, 10, 11, 12, 16, 18, 19 }
117walls.office[4][2] = { 4, 5, 8, 16, 18, 20, 21, 22 }
118
119walls.office[ 5 ] = {}
120walls.office[5][1] = { 2, 10, 13, 15, 19, 20, 23, 24 }
121walls.office[5][2] = { 1, 4, 5, 6, 7, 14, 20, 24 }
122
123walls.office[ 6 ] = {}
124walls.office[6][1] = { 1, 2, 3, 4, 8, 18, 19, 24 }
125walls.office[6][2] = { 2, 6, 8, 10, 12, 14, 18, 23 }
126
127walls.office[ 7 ] = {}
128walls.office[7][1] = { 2, 5, 6, 10, 12, 14, 17, 23 }
129walls.office[7][2] = { 2, 6, 11, 12, 13, 17, 20, 21 }
130
131walls.office[ 8 ] = {}
132walls.office[8][1] = { 2, 4, 6, 9, 10, 14, 16, 23 }
133walls.office[8][2] = { 3, 4, 5, 6, 7, 12, 15, 21 }
134
135walls.office[ 9 ] = {}
136walls.office[9][1] = { 1, 4, 6, 11, 14, 15, 21, 24 }
137walls.office[9][2] = { 4, 5, 8, 9, 12, 14, 15, 17 }
138
139walls.office[ 10 ] = {}
140walls.office[10][1] = { 2, 5, 7, 8, 14, 18, 19, 24 }
141walls.office[10][2] = { 1, 3, 5, 6, 9, 18, 19, 22 }
142
143
144-- Define game settings and checkbox groups.
145-- The "group" list is a list of indices into the button list for each group.
146local settings = {}
147
148settings.players = {} -- Number of players (2 to 4)
149settings.players.value = 2
150settings.players.group = { 0, 2, 4 }
151
152settings.sizes = {} -- number of floors (2 = office, 3 = bank)
153settings.sizes.value = "bank"
154settings.sizes.group = { 6, 8 }
155
156settings.walls = {} -- which wall set to use (1 = standard, 2 = generated)
157settings.walls.value = "std"
158settings.walls.group = { 10, 12 }
159
160
161--[[------------
162 Button functions.
163--]]------------
164
165-- Initialize the buttons.
166function onLoad()
167
168
169 -- Location of the "X" displays for the check boxes.
170 -- The third parameter is a horrible kludge to set the buttons' initial values.
171 -- If you change any settings.values, change these parameters too.
172 local checkBoxes = {}
173 checkBoxes.Players2 = { -0.035, -0.458, "X" }
174 checkBoxes.Players3 = { 0.188, -0.458, "" }
175 checkBoxes.Players4 = { 0.41, -0.458, "" }
176 checkBoxes.SizeOffice = { -0.035, -0.28, "" }
177 checkBoxes.SizeBank = { -0.035, -0.17, "X" }
178 checkBoxes.WallsStd = { -0.035, 0.008, "" }
179 checkBoxes.WallsGen = { -0.035, 0.12, "X" }
180
181 -- Create the checkbox displays and buttons.
182 for btnFunc, btnPos in pairs( checkBoxes ) do
183
184 -- The display has no size, so only the text will appear.
185 local btnParams = {}
186 btnParams.click_function = "none"
187 btnParams.function_owner = self
188 btnParams.label = btnPos[3]
189 btnParams.position = {}
190 btnParams.position[1] = btnPos[1]
191 btnParams.position[2] = 1
192 btnParams.position[3] = btnPos[2]
193 btnParams.rotation = { 0, 180, 0 }
194 btnParams.width = 0
195 btnParams.height = 0
196 btnParams.font_size = 39
197 self.createButton( btnParams )
198
199 -- Create the actual button just beneath the remote control.
200 btnParams.click_function = "clickBtn" .. btnFunc
201 btnParams.position[2] = 0.8
202 btnParams.width = 60
203 btnParams.height = 60
204 self.createButton( btnParams )
205
206 end
207
208 -- Create the "Start Heist" button.
209 local btnStart = {}
210 btnStart.click_function = "clickBtnStart"
211 btnStart.function_owner = self
212 btnStart.label = ""
213 btnStart.position = { 0, 0.8, 0.58 }
214 btnStart.rotation = { 0, 180, 0 }
215 btnStart.width = 330
216 btnStart.height = 330
217 btnStart.font_size = 36
218 self.createButton( btnStart )
219
220end
221
222
223-- Respond to clicks in the check boxes.
224function clickBtnPlayers2() setSetting( "players", 0, 2 ) end
225function clickBtnPlayers3() setSetting( "players", 2, 3 ) end
226function clickBtnPlayers4() setSetting( "players", 4, 4 ) end
227function clickBtnSizeOffice() setSetting( "sizes", 6, "office" ) end
228function clickBtnSizeBank() setSetting( "sizes", 8, "bank" ) end
229function clickBtnWallsStd() setSetting( "walls", 10, "std" ) end
230function clickBtnWallsGen() setSetting( "walls", 12, "gen" ) end
231
232
233-- Set the checkboxes for a group and the setting's value.
234function setSetting( theSetting, theCheckedBox, theValue )
235
236 -- Get the checkbox group for this setting and set its value.
237 local thisCheckGroup = settings[ theSetting ].group
238 settings[ theSetting ].value = theValue
239
240 -- Walk the list of buttons to find the ones for this checkbox group.
241 local allButtons = self.getButtons()
242 for _, thisBtn in pairs( allButtons ) do
243
244 -- Search the check group to see if this button is in it.
245 for _, thisCheckBox in pairs( thisCheckGroup ) do
246 if thisBtn.index == thisCheckBox then
247
248 -- If this is the button that was clicked, check it.
249 if thisBtn.index == theCheckedBox then
250 theLabel = "X"
251 else
252 theLabel = ""
253 end
254
255 self.editButton( { index = thisBtn.index, label = theLabel } )
256
257 end
258 end
259
260 end
261
262end
263
264
265-- Respond to the "Start Heist" button.
266function clickBtnStart()
267
268 -- Make sure the game hasn't already been started.
269 local gameStarted = Global.getVar( "gameStarted" )
270 if gameStarted then
271 print( "The heist has already been started." )
272 return
273 end
274
275 -- Get the settings for the game.
276 local numPlayers = settings.players.value
277
278 local theBoard = settings.sizes.value
279
280 local numFloors = 3
281 if theBoard == "office" then
282 numFloors = 2
283 end
284
285 -- The first value in the walls table is the default setup,
286 -- the rest were generated by the gabob.com/burgle/ wall generator.
287 local whichWalls = 1
288 if settings.walls.value == "gen" then
289 if theBoard == "office" then
290 whichWalls = math.random( 2, 10 )
291 else
292 whichWalls = 1
293 end
294 end
295
296 -- Remember the leftmost card position.
297 if numFloors == 2 then
298 Global.setVar( "leftEdge", -26.25 )
299 else
300 Global.setVar( "leftEdge", -40.25 )
301 end
302
303 -- Get the decks and objects needed for the script.
304 local theRooms = Global.call( "getObjectFromName", { "Room Deck" } )
305 local the3rdFloor = Global.call( "getObjectFromName", { "Floor3 Room Deck" } )
306 local the3rdSafeStairs = Global.call( "getObjectFromName", { "Floor3 Deck" } )
307 local theUnused = Global.call( "getObjectFromName", { "Unused Cards" } )
308
309 -- If it's a 3-floor game, add the 3rd floor cards to the room deck.
310 if numFloors == 3 then
311 theRooms.putObject( the3rdFloor )
312 end
313
314 -- Shuffle all the decks.
315 if not shuffleAllTheThings( shuffleDecks ) then
316 print( "Setup cancelled." )
317 return
318 end
319
320 walls.bank = {}
321 walls.bank[ 1 ] = {}
322 tmpRand=math.random( 1, 60 )
323 print("Setting floor 1 to #"..tmpRand)
324 walls.bank[1][1] = wallLayouts[math.random( 1, 60 )]
325 tmpRand=math.random( 1, 60 )
326 print("Setting floor 2 to #"..tmpRand)
327 walls.bank[1][2] = wallLayouts[math.random( 1, 60 )]
328 tmpRand=math.random( 1, 60 )
329 print("Setting floor 3 to #"..tmpRand)
330 walls.bank[1][3] = wallLayouts[math.random( 1, 60 )]
331
332
333 -- Get the list of walls for this game.
334 local wallList = walls[ theBoard ][ whichWalls ]
335
336 -- Deal and arrange the rooms and walls for each floor.
337 for i = 1, numFloors do
338 setupFloor( i )
339 setupWalls( i, wallList[ i ] )
340 setupPatrol( i )
341 end
342
343 -- If it's a two-floor game, clean up the unused pieces.
344 if numFloors == 2 then
345
346 -- Set aside the unused 3rd floor room cards.
347 theUnused.putObject( the3rdFloor )
348 theUnused.putObject( the3rdSafeStairs )
349
350 -- Set aside the third floor patrol deck tray.
351 movePatrolTray( 3, -47.25, 31.5 )
352
353 end
354
355 -- Select and place the characters.
356 setupCharacters( numPlayers )
357
358 -- Remember that the game has been started.
359 Global.setVar( "gameStarted", true )
360
361end
362
363
364--[[------------
365 Main functions.
366--]]------------
367
368-- Shuffle multiple decks of cards.
369function shuffleAllTheThings( deckList )
370
371 -- Shuffle all the decks.
372 for i in pairs( deckList ) do
373
374 -- Get the deck we'll be shuffling.
375 local thisDeckName = deckList[ i ]
376 local thisDeck = Global.call( "getObjectFromName", { thisDeckName } )
377
378 -- Verify that the deck object exists.
379 if not thisDeck then
380 print( "startHeist: No " .. thisDeckName .. " found." )
381 return false
382 end
383
384 -- Shuffle the deck!
385 thisDeck.shuffle()
386
387 end
388
389 return true
390
391end
392
393
394-- Deal cards to a floor deck, and lay them out on the board.
395function setupFloor( theFloor )
396
397 -- Get the room deck and floor deck.
398 local roomDeck = Global.call( "getObjectFromName", { "Room Deck" } )
399 local floorDeck = Global.call( "getObjectFromName",
400 { "Floor" .. theFloor .. " Deck" } )
401
402 -- Deal the room cards into the floor deck.
403 for i = 1, 14 do
404 local thisRoom = roomDeck.takeObject( {} )
405 floorDeck.putObject( thisRoom )
406 end
407
408 -- Shuffle the floor deck.
409 floorDeck.shuffle()
410
411 -- Place each room card in its spot on the board.
412 for i = 1, 16 do
413
414 -- Get the board position for this card.
415 local thisPos = Global.call( "getRoomLoc", { theFloor, i } )
416
417 -- Draw the card and place it on the board.
418 local params = {}
419 params.position = {}
420 params.position.x = thisPos.x
421 params.position.y = 3
422 params.position.z = thisPos.z
423 floorDeck.takeObject( params )
424
425 end
426
427end
428
429
430-- Lay walls out on a floor.
431function setupWalls( theFloor, wallList )
432
433 -- Find the bag containing the wall pieces.
434 local wallBag = Global.call( "getObjectFromName", { "Walls" } )
435
436 -- Walk the list of walls for this floor.
437 for i in pairs( wallList ) do
438
439 -- Get the location for this wall.
440 local thisLoc = getWallLoc( theFloor, wallList[ i ] )
441
442 -- Prepare the parameter list for takeObject().
443 local params = {}
444
445 params.position = {}
446 params.position.x = thisLoc.x
447 params.position.y = 3
448 params.position.z = thisLoc.z
449
450 params.rotation = {}
451 params.rotation.x = 0
452 if wallList[ i ] <= 12 then
453 params.rotation.y = -90
454 else
455 params.rotation.y = 0
456 end
457 params.rotation.z = 0
458
459 -- Draw a wall piece from the bag and place it.
460 local thisWall = wallBag.takeObject( params )
461
462 end
463
464end
465
466
467-- Lay guard pieces out below a floor.
468function setupPatrol( theFloor )
469
470 -- Get the relevant game settings.
471 local numPlayers = settings.players.value
472 local floorPos = Global.getVar( "leftEdge" )
473
474 -- Get the patrol deck for this floor.
475 local thisPatrolDeck = Global.call( "getObjectFromName",
476 { "Patrol" .. theFloor .. " Deck" } )
477
478 local patrolLeftovers = Global.getVar( "patrolLeftovers" )
479
480 -- Calculate where to put the leftover patrol cards for 2- and 3-player games.
481 -- Making sense of constants:
482 -- -49 = left sideboard of table
483 -- 22.75 = z-position of 1st floor leftovers
484 -- 7 = spacing between leftover decks.
485 local thePos = {}
486 thePos.x = -49
487 thePos.y = 3
488 thePos.z = 22.75 - ( theFloor-1 ) * 7
489
490 -- Initialize the patrol leftovers.
491 patrolLeftovers[ theFloor ] = nil
492
493 -- leave out 3 cards for a 3-player game, and 6 cards for a 2-player game.
494 for i = 1, ( 4-numPlayers ) * 3 do
495
496 local thisPatrolCard = thisPatrolDeck.takeObject( { position = thePos } )
497
498 -- Remember the last card we left out, so we can reshuffle it later.
499 -- (Yeah this is redundant, but it's late and the code looks prettier.)
500 patrolLeftovers[ theFloor ] = thisPatrolCard.getName()
501 thePos.y = thePos.y + 1
502
503 end
504
505 -- Place the patrol deck tray for this floor.
506 -- Making sense of constants:
507 -- 10.5 = x-offset from left side of this floor's room layout
508 -- 29.75 = spacing between floors
509 -- -19.25 = z-offset below this floor's room layout
510 movePatrolTray( theFloor, floorPos + 10.5 + ( theFloor - 1 ) * 29.75, -19.25 )
511
512end
513
514
515-- Lay character cards and tokens out on the board.
516function setupCharacters()
517
518 -- Get the number of players, the character card deck,
519 -- and the bag of stealth tokens.
520 local numPlayers = settings.players.value
521 local theCharDeck = Global.call( "getObjectFromName", { "Character Deck" } )
522 local stealthBag = Global.call( "getObjectFromName", { "Stealth Tokens" } )
523
524 -- Deal and arrange the character cards and tokens.
525 for i = 1, numPlayers do
526
527 -- Calculate x and z coordinates for the character card.
528 -- I don't put them directly into the position parameter because
529 -- other pieces will be placed relative to them.
530
531 -- Version 1.0 centered the player cards based on number of players.
532 -- Making sense of constants:
533 -- 17.5 = spacing between cards
534 -- 8.75 = how much to offset for number of players (yes, half of 17.5)
535 -- local xPos = ( i-1 ) * 17.5 - ( numPlayers-1 ) * 8.75
536
537 -- Since I added Hand zones in 1.1, I just lay them out to align with
538 -- the zones.
539 -- Making sense of constants:
540 -- 17.5 = spacing between player cards
541 -- -26.25 = leftmost player card
542 local xPos = ( i-1 ) * 17.5 - 26.25
543 local zPos = -31.5
544
545 -- Prepare the position parameter for drawing and moving pieces.
546 local params = {}
547 params.position = {}
548 params.position.y = 3
549
550 -- Draw and place a character card.
551 params.position.x = xPos
552 params.position.z = zPos
553 local thisCharCard = theCharDeck.takeObject( params )
554
555 -- Do character-specific additional setup.
556 if thisCharCard.getName() == "Raven" then
557
558 -- The Raven gets the Crow counter.
559 local theCrow = Global.call( "getObjectFromName", { "Crow" } )
560 params.position.x = xPos + 3.5
561 params.position.z = zPos + 3.5
562 theCrow.setPositionSmooth( params.position )
563
564 elseif thisCharCard.getName() == "Rigger" then
565
566 -- The Rigger gets the Dynamite tool card. Find it in the tool deck.
567 local toolDeck = Global.call( "getObjectFromName", { "Tool Deck" } )
568 local toolCards = toolDeck.getObjects()
569 local dynamiteTool = nil
570
571 -- Search the tool deck for the Dynamite card and draw it.
572 for i, thisTool in pairs( toolCards ) do
573
574 if thisTool.nickname == "Dynamite" then
575
576 params.position.x = xPos + 3.5
577 params.flip = true
578 params.index = i-1 -- I can't even.
579 dynamiteTool = toolDeck.takeObject( params )
580
581 end
582
583 end
584
585 end
586
587 -- Get and place the token for this character next to its card.
588 local thisCharToken = Global.call( "getObjectFromName",
589 { thisCharCard.getName() .. " Token" } )
590 params.position.x = xPos + 5.25
591 params.position.z = zPos
592 thisCharToken.setPositionSmooth( params.position )
593
594 -- Get and place three stealth tokens for this character.
595 params.position.z = zPos + 5.25
596
597 for j = 1, 1 do
598 -- Making sense of constants: 1.75 = grid increment
599 params.position.x = xPos + (j-2) * 1.75
600 stealthBag.takeObject( params )
601 end
602
603 end
604
605end
606
607
608--[[------------
609 Utility functions.
610--]]------------
611
612-- Return the x and z coordinates and facing for a wall.
613function getWallLoc( theFloor, theWall )
614
615 -- Get the left edge of the layout.
616 local theLeftEdge = Global.getVar( "leftEdge" )
617
618 local theLoc = {}
619
620 -- Wall positions 1-12 are NS walls, positions 13-24 are EW walls.
621 -- All wall positions are counted left-to-right, then top-to-bottom.
622 if theWall <= 12 then
623
624 -- Making sense of constants:
625 -- x theLeftEdge, z 10.5 = base location (top-left N-S wall)
626 -- 3.5 = offset for first N-S wall position (between first two rooms)
627 -- 29.75 = distance between floors
628 -- 3 = number of N-S walls in each row
629 -- 7 = spacing between walls
630 theLoc.x = theLeftEdge + 3.5 + ( theFloor-1 ) * 29.75 + ( ( theWall-1 ) % 3 ) * 7
631 theLoc.z = 10.5 - math.floor( ( theWall-1 ) / 3 ) * 7
632
633 else
634
635 -- Making sense of constants:
636 -- x theLeftEdge, z 7 = base location (top-left E-W wall)
637 -- 29.75 = distance between leftmost EW wall card of each floor
638 -- 4 = number of E-W walls in each row
639 -- 7 = spacing between walls
640 -- Subtract 12 from each wall number to account for E-W numbering.
641 theLoc.x = theLeftEdge + ( theFloor-1 ) * 29.75 + ( ( theWall-13 ) % 4 ) * 7
642 theLoc.z = 7 - math.floor( ( theWall-13 ) / 4 ) * 7
643
644 end
645
646 return theLoc
647
648end
649
650
651-- Move a patrol deck tray and its associated objects.
652function movePatrolTray( theFloor, theX, theZ )
653
654 --Get all the objects to be moved.
655 local thePatrolTray = Global.call( "getObjectFromName", { "Patrol" .. theFloor .. " Tray" } )
656 local thePatrolDeck = Global.call( "getObjectFromName", { "Patrol" .. theFloor .. " Deck" } )
657 local theGuard = Global.call( "getObjectFromName", { "Guard" .. theFloor } )
658 local theDie = Global.call( "getObjectFromName", { "Guard" .. theFloor .. " Die" } )
659
660 -- Move them! The location parameter refers to the tray,
661 -- so the other objects will be offset appropriately.
662 thePatrolTray.setPositionSmooth( { theX, 3, theZ } )
663 thePatrolDeck.setPositionSmooth( { theX - 3.5, 6, theZ + 1.75 } )
664 theGuard.setPositionSmooth( { theX + 3.5, 6, theZ + 1.75 } )
665 theDie.setPositionSmooth( { theX, 6, theZ + 1.75 } )
666
667end