Changes
1 changed files (+39/-22)
-
-
@@ -469,15 +469,15 @@ A' := A'.swap i jreturn A'.toArray -- These are all per-tick, not per-second abbrev productionProb := 100 abbrev homeToWorkProb := 2000 abbrev homeToGroceryStoreProb := 5000 abbrev homeToShopProb := 5000 abbrev homeToBankProb := 10000 abbrev deliveryProb := 100 abbrev workToHomeProb := 5000 abbrev consumerToHomeProb := 2000 abbrev breakdownProb := 10000 abbrev productionProb := 200 abbrev homeToWorkProb := 5000 abbrev homeToGroceryStoreProb := 10000 abbrev homeToShopProb := 10000 abbrev homeToBankProb := 50000 abbrev deliveryProb := 200 abbrev workToHomeProb := 10000 abbrev consumerToHomeProb := 5000 abbrev breakdownProb := 50000 abbrev repairProb := 25 /-- Run one iteration of the game
-
@@ -706,7 +706,7 @@ let onSide (p : Nat3) :=pos.x ≤ p.x && p.x ≤ pos.x + size.x && pos.z ≤ p.z && p.z ≤ pos.z + size.z && (p.x == pos.x || p.x == pos.x + size.x || p.z == pos.z || p.z == pos.z + size.z) if !onSide entrance || !onSide exit then throw "Building entrance or exit not on side of building" let newIdx := (← get).buildings.size let bIdx := (← get).buildings.size let size' := if (variant == .factory || variant == .industrialPlant) && size.y < 4 then { size with y := 4 }
-
@@ -760,8 +760,8 @@ if b.isResidential thenmodifyf peeps (·.push { home := (← get).buildings.size work := idx pos := b.exit dest := idx pos := b.entrance dest := bIdx dir := none brokenDown := false isDelivery := false
-
@@ -769,9 +769,9 @@ })else modifyf peeps (·.push { home := idx work := newIdx pos := (← get).buildings[idx]!.exit dest := newIdx work := bIdx pos := (← get).buildings[idx]!.entrance dest := idx dir := none brokenDown := false isDelivery := false
-
@@ -784,8 +784,8 @@ elsebreak modifyf buildings (·.push { b with spots }) if spots > 0 then modifyf unfull (·.modify (!b.isResidential).toNat (·.push newIdx)) modifyf buildingVariants (·.modify variant.ctorIdx (·.push newIdx)) modifyf unfull (·.modify (!b.isResidential).toNat (·.push bIdx)) modifyf buildingVariants (·.modify variant.ctorIdx (·.push bIdx)) def max3 (a b c : Nat) := max a (max b c)
-
@@ -1156,7 +1156,9 @@ →: Increase speed↓: Decrement inspect height ↑: Increment inspect height -: Decrement add building height =: Increment add building height" =: Increment add building height [: Fixed pointer mode ]: Free pointer mode" IO.println <| "\n".intercalate <| keyAction.map fun (c, a) ↦ s!"{c}: {a}" | "save" :: path :: _ => saveState path (← get)
-
@@ -1303,11 +1305,14 @@ let round (f : Float) := ((scale * f).round + 1e-9).toUInt64.toNat⟨round posV3.x, round posV3.y, round posV3.z⟩ /-- Get position of mouse at level `y` (relative to origin) -/ def getMouse3D (y : Int) (camera : Camera3D) : IO Vector3 := do def getMouse3D (y : Int) (camera : Camera3D) (fixedPointer : Bool) : IO Vector3 := do let yf := Float.ofInt (y / sensitivity) / scale if fixedPointer then return camera.position - (camera.position - camera.target) * (camera.position.y - yf) / camera.position.y let pos2 ← getMousePosition let windowScale ← getWindowScaleDPI -- `.dot` is just element-wise product, not the dot product! return project (pos2.dot windowScale) camera (Float.ofInt (y / sensitivity) / scale) (← getScreenWidth).toFloat (← getScreenHeight).toFloat return project (pos2.dot windowScale) camera yf (← getScreenWidth).toFloat (← getScreenHeight).toFloat def spawnInitBuildings : StateT State IO Unit := do let randPos (gap : Nat) : StateM State Nat3 := do
-
@@ -1353,6 +1358,9 @@ for i in [:40] dorandBuilding .house ⟨4, 1, 3⟩ 1 100 for i in [:12] do randBuilding .apartment ⟨8, 4, 5⟩ 1 0 -- Place all peeps at exits let b := (← get).buildings modifyf peeps (·.map fun p ↦ { p with pos := b[p.home]!.exit, dest := p.work }) setf money 100000 def renderAction (actionState : List Nat3) (curAction : Action) (mousePos : Nat3) (s : State) (newHeight : Nat) : StateT State IO Unit := do
-
@@ -1423,6 +1431,7 @@ let mut y : Int := 0let mut newHeight : Nat := sensitivity let mut frames := 0 let mut err := none let mut fixedPointer := false while !(← windowShouldClose) do -- Fix `up` to prevent the Q and E keys from messing it up camera := { ← updateCamera camera .thirdPerson with up := ⟨0, 1, 0⟩ }
-
@@ -1431,7 +1440,7 @@ y := y + 1if ← isKeyDown Key.down then y := y - 1 if (← isMouseButtonPressed MouseButton.left) then do let mousePos := (← getMouse3D y camera).toNat3Shift (← get) let mousePos := (← getMouse3D y camera fixedPointer).toNat3Shift (← get) try actionState ← doAction curAction actionState mousePos newHeight catch e =>
-
@@ -1447,6 +1456,10 @@ if (← isKeyDown '-'.toNat) then donewHeight := newHeight - 1 if (← isKeyDown '='.toNat) then do newHeight := newHeight + 1 if (← isKeyDown '['.toNat) then do fixedPointer := true if (← isKeyDown ']'.toNat) then do fixedPointer := false for (key, action) in keyAction do if (← isKeyDown key.toNat) then do curAction := action
-
@@ -1470,7 +1483,7 @@ | none => nonelet s ← get renderFrame do clearBackground Color.white let mousePosV3 ← getMouse3D y camera let mousePosV3 ← getMouse3D y camera fixedPointer let mousePos := mousePosV3.toNat3Shift s renderWithCamera camera do render s camera frames
-
@@ -1487,6 +1500,10 @@ drawText s!"{s.grid[mousePos].name} {s.grid[mousePos].control}" 10 190 20 .blackdrawFPS ((← getScreenWidth) - 100) 10 if he : err.isSome then drawText (err.get he).1 10 ((← getScreenHeight) - 30) 20 Color.Raylean.maroon if fixedPointer then let center : Vector2 := ⟨(← getScreenWidth).toFloat / 2, (← getScreenHeight).toFloat / 2⟩ drawLineV (center - ⟨0, 10⟩) (center + ⟨0, 10⟩) .black drawLineV (center - ⟨10, 0⟩) (center + ⟨10, 0⟩) .black closeWindow saveState "save.auto" (← get)
-