Skip to content

Commit

Permalink
Bugfix: Prisons aren't placing the prison bars in the correct places
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Mar 17, 2024
1 parent b9ba5ba commit 034bd2b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 74 deletions.
112 changes: 44 additions & 68 deletions Scenes/PlaceThingWithSlab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,97 +8,73 @@ onready var oSelector = Nodelist.list["oSelector"]

onready var dir = oSlabPlacement.dir

# The way things placed from slabs.tng works, is that we use the same coordinates (via bitmask and fullVariationIndex) as what's in slabs.dat/clm (level 1000)
# Except we change the positions based on some placement rules.
# For example the Prison bars need extra rules for detecting nearby walls, but the original slab cubes did not need these rules.
# So objects have their own placement rules, though we use the original bitmask/fullVariationIndex (from oSlabPlacement) as a basis to work from.

func place_slab_objects(xSlab, ySlab, slabID, ownership, clmIndexGroup, bitmask, surrID, bitmaskType):
oInstances.delete_attached_instances_on_slab(xSlab, ySlab)

if slabID == Slabs.WATER:
if Random.rng.randf_range(0.0, 100.0) < oWaterEffectPercent.value:
var xSubtile = (xSlab*3) + Random.randi_range(0,2) + 0.5
var ySubtile = (ySlab*3) + Random.randi_range(0,2) + 0.5
var zSubtile = 0
var createAtPos = Vector3(xSubtile, ySubtile, zSubtile)
oInstances.place_new_thing(Things.TYPE.EFFECTGEN, 2, createAtPos, ownership)
elif slabID == Slabs.LAVA:
if Random.rng.randf_range(0.0, 100.0) < oLavaEffectPercent.value:
var xSubtile = (xSlab*3) + Random.randi_range(0,2) + 0.5
var ySubtile = (ySlab*3) + Random.randi_range(0,2) + 0.5
var zSubtile = 0
var createAtPos = Vector3(xSubtile, ySubtile, zSubtile)
oInstances.place_new_thing(Things.TYPE.EFFECTGEN, 1, createAtPos, ownership)

if Slabs.is_door(slabID):
create_door_thing(xSlab, ySlab, ownership)

if slabID == Slabs.PRISON:
var subtiles_with_bars = prison_bar_bitmask(slabID, surrID)
match slabID:
Slabs.WATER:
if Random.rng.randf_range(0.0, 100.0) < oWaterEffectPercent.value:
create_effect(xSlab, ySlab, ownership, Things.TYPE.EFFECTGEN, 2)
Slabs.LAVA:
if Random.rng.randf_range(0.0, 100.0) < oLavaEffectPercent.value:
create_effect(xSlab, ySlab, ownership, Things.TYPE.EFFECTGEN, 1)
Slabs.PRISON:
var subtiles_with_bars = prison_bar_bitmask(slabID, surrID)
for i in range(9):
spawn_object(xSlab, ySlab, slabID, ownership, i, clmIndexGroup[i], subtiles_with_bars.has(i))
_:
if Slabs.is_door(slabID):
create_door_thing(xSlab, ySlab, ownership)
else:
for i in range(9):
spawn_object(xSlab, ySlab, slabID, ownership, i, clmIndexGroup[i], true)

for i in range(9):
var variation = int(clmIndexGroup[i] / 9)
var convertedSubtile = clmIndexGroup[i] % 9
var objectStuff = get_object(variation, convertedSubtile)
func create_effect(xSlab, ySlab, ownership, effectType, effectSubtype):
var xSubtile = (xSlab*3) + Random.randi_range(0,2) + 0.5
var ySubtile = (ySlab*3) + Random.randi_range(0,2) + 0.5
var createAtPos = Vector3(xSubtile, ySubtile, 0)
oInstances.place_new_thing(effectType, effectSubtype, createAtPos, ownership)

if objectStuff.size() > 0 and subtiles_with_bars.has(i):
oInstances.spawn_attached(xSlab, ySlab, slabID, ownership, i, objectStuff)

else:

for i in range(9): # iterate over the range of 0-8, assuming 9 subtiles per variation
var variation = int(clmIndexGroup[i] / 9) # Convert to int for safety, as division of ints in GDScript results in float
var convertedSubtile = clmIndexGroup[i] % 9
var objectStuff = get_object(variation, convertedSubtile) # Pass slabVar and datSubtile to the get_object function
if objectStuff.size() > 0:
oInstances.spawn_attached(xSlab, ySlab, slabID, ownership, i, objectStuff)
func spawn_object(xSlab, ySlab, slabID, ownership, subtile, clmIndex, shouldSpawn):
var variation = int(clmIndex / 9)
var convertedSubtile = clmIndex % 9
var objectStuff = get_object(variation, convertedSubtile)
if objectStuff.size() > 0 and shouldSpawn:
oInstances.spawn_attached(xSlab, ySlab, slabID, ownership, subtile, objectStuff)

func get_object(variation, subtile):
if variation < Slabset.tng.size():
for objectStuff in Slabset.tng[variation]:
if subtile == objectStuff[Slabset.obj.SUBTILE]: # Assuming the third element in objectStuff array is the subtile number
if subtile == objectStuff[Slabset.obj.SUBTILE]:
return objectStuff
return [] # Return an empty array if no objectStuff is found or if slabVar is out of range

return []

func create_door_thing(xSlab, ySlab, ownership):
var createAtPos = Vector3((xSlab*3)+1.5, (ySlab*3)+1.5, 5)
var rememberLockedState = 0

var rememberLockedState = 0 # This is the fallback value if oPlaceLockedCheckBox isn't being used

# Destroy existing door thing
var doorID = oInstances.get_node_on_subtile(createAtPos.x, createAtPos.y, "Door")
if is_instance_valid(doorID) == true:
if is_instance_valid(doorID):
rememberLockedState = doorID.doorLocked

doorID.position = Vector2(-500000,-500000) # Not sure if this is necessary
doorID.queue_free()

# Recreate door thing
var id = oInstances.place_new_thing(Things.TYPE.DOOR, 0, createAtPos, ownership) #subtype determined in oInstances
var id = oInstances.place_new_thing(Things.TYPE.DOOR, 0, createAtPos, ownership)
id.doorLocked = rememberLockedState

# Overwrite locked state with ui checkbox setting
if oPlaceLockedCheckBox.visible == true:
# Only affect the slab under cursor
#if xSlab == oSelector.cursorTile.x and ySlab == oSelector.cursorTile.y:
# Set locked state to checkbox state
if oPlaceLockedCheckBox.pressed == true:
id.doorLocked = 1
else:
id.doorLocked = 0
if oPlaceLockedCheckBox.visible:
id.doorLocked = 1 if oPlaceLockedCheckBox.pressed else 0

id.update_spinning_key()

func prison_bar_bitmask(slabID, surrID):
var subtiles_with_bars = []
if Slabs.data[ surrID[dir.s] ][Slabs.IS_SOLID] == false and slabID != surrID[dir.s]:
subtiles_with_bars.append_array([6, 7, 8])
if Slabs.data[ surrID[dir.w] ][Slabs.IS_SOLID] == false and slabID != surrID[dir.w]:
subtiles_with_bars.append_array([0, 3, 6])
if Slabs.data[ surrID[dir.n] ][Slabs.IS_SOLID] == false and slabID != surrID[dir.n]:
subtiles_with_bars.append_array([0, 1, 2])
if Slabs.data[ surrID[dir.e] ][Slabs.IS_SOLID] == false and slabID != surrID[dir.e]:
subtiles_with_bars.append_array([2, 5, 8])
var bar_subtiles = {
dir.s: [6, 7, 8],
dir.w: [0, 3, 6],
dir.n: [0, 1, 2],
dir.e: [2, 5, 8]
}
for direction in [dir.s, dir.w, dir.n, dir.e]:
if not Slabs.data[surrID[direction]][Slabs.IS_SOLID] and slabID != surrID[direction]:
subtiles_with_bars.append_array(bar_subtiles[direction])
return subtiles_with_bars
15 changes: 9 additions & 6 deletions Scenes/ReadData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ func new_slb():

func read_own(buffer):
buffer.seek(0)
var dataHeight = (M.ySize*3)+1
var dataWidth = (M.xSize*3)+1
for ySubtile in dataHeight:
for xSubtile in dataWidth:
value = buffer.get_u8()
oDataOwnership.set_cell(xSubtile/3,ySubtile/3,value)
var dataWidth = (M.xSize * 3) + 1
var totalSubtiles = ((M.ySize * 3) + 1) * dataWidth
var data = buffer.get_data(totalSubtiles)
print(data)
# for i in totalSubtiles:
# var ySubtile = i / dataWidth
# var xSubtile = i % dataWidth
# var value = data.get(i) # Convert byte to integer
# oDataOwnership.set_cell(xSubtile / 3, ySubtile / 3, value)
func new_own():
pass

Expand Down

0 comments on commit 034bd2b

Please sign in to comment.