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