Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire extinguishers don't impact explosion chance #994

Closed
strawgate opened this issue Mar 6, 2016 · 17 comments · Fixed by #1648
Closed

Fire extinguishers don't impact explosion chance #994

strawgate opened this issue Mar 6, 2016 · 17 comments · Fixed by #1648
Assignees
Labels
enhancement issue type

Comments

@strawgate
Copy link

Describe the issue

Fire extinguishers currently impact happiness but don't impact equipment explosion chance.

From the game manual:
"✚ Fire Extinguishers are looked for by Very Important People - VIPs. VIPs like being safe. If
they don’t see a reassuring number of Fire Extinguishers when they visit, their reports to
the Ministry won’t be very favorable. Fire Extinguishers also increase safety levels around
Hospital equipment, and their presence makes Patients and Staff alike happier."

Expected Behavior

Fire extinguishers should lower the chance that a piece of equipment explodes either by increasing it's strength or implementing a % chance that when the threshold is hit the equipment doesn't explode.

System Information

CorsixTH Version: 0.50

Operating System: any

Theme Hospital Version: any

@TheCycoONE
Copy link
Member

Did the original game implement this? I don't recall the extinguisher having any effect on machine strength.

@strawgate
Copy link
Author

FYI, I was hoping to use this as an intro to try contributing to this project so we'll see how it goes.

I'm not entirely sure if/how the original game implemented it but the "logic" is littered all over the place.

CorsixTH game guide https://github.com/CorsixTH/CorsixTH/wiki/Game-Guide

Fire extinguisher VIP's like to see these and they minimise danger from malfunctioning machinery.
The DNA Fixer Machine is a very complex piece of equipment and it would be sensible to keep a fire extinguisher in the room with it, just in case.
The presence of nearby fire extinguishers helps decrease the risk of explosion. A machine that explodes kills everyone in the room and renders the room permanently unusable thereafter.

And in player documentation http://bullfrogproductions.wikia.com/wiki/Hospital_Items

The Fire extinguisher refers to single Red Fire extinguisher that can be bought and placed around your hospital as a form of fire protection. They cost £25 per Fire extinguisher and an unlimited amount can be bought. Placing one near machinery will reduce the amount of breakdowns.

Official Game Guide http://vignette2.wikia.nocookie.net/bullfrogproductions/images/2/20/Manual_Theme_Hospital.pdf/revision/latest?cb=20131210232242

The presence of nearby
fire extinguishers helps decrease the risk of explosion. A machine that explodes kills everyone
in the room and renders the room permanently unusable thereafter

What are your thoughts on this?

@TheCycoONE
Copy link
Member

I think it would be good to implement, though we should have a consensus on what the desired behavior should be before you spend time coding it.
The first thing to do would be to study machine breakdown in the original game, if it has any effect there then that would be an ideal template.

I don't think it's viable that a fire extinguisher make the base strength of the machine higher. If there's nothing in the original game to copy, then I like the idea of a small increase in the chance that the machine doesn't explode for each use past the critical threshold.

@MarkL1961
Copy link
Contributor

I don't believe they increased the strength of a machine or reduced the chance of explosion through use. Once a machine reaches 0 in uses it explodes.
However it may have reduced the chance of explosion from an earthquake, which would be difficult to check as the screen moves that much and for different lengths of time you would have trouble measuring how quickly the uses go up.
So as checking TH on this is pretty much out of the question, why not get a consensus from everyone on whether this would a good addition to the game?
If that is the way you go you get my vote for reducing the risk of explosions when one is present in the room.

@Alberth289346 Alberth289346 added the enhancement issue type label May 11, 2016
@lewri
Copy link
Member

lewri commented Jun 8, 2020

What about if there's a fire extinguisher in the room, and if the machine strength <=0; we do a 50/50 chance of whether it will explode? If the chance is successful we reset the strength to 1 to give a chance for the handyman to repair it.

@mugmuggy
Copy link
Contributor

mugmuggy commented Jun 9, 2020

TH builds in this buffer without the fire extinguishers with what I can tell.
If the times used exceeds the full machine strength
The 'chance' by the looks is given by: 1.5 * full machine strength - 'times used' + 1
if that is 1 or less, then destroy room.
If > 1 then the result is a 1 in 'chance' it will destroy the room. But I will try and verify at some point.

@TheCycoONE
Copy link
Member

I think we're ok to vary from the implementation of the original here, as the intent (as specified in the manual) was that they would have some impact.

@mugmuggy
Copy link
Contributor

mugmuggy commented Jun 9, 2020

Agree, just thought I would point out that there is an escalating chance of failure instead of the 50/50 and a defined must crash point.

@lewri
Copy link
Member

lewri commented Jun 9, 2020

In Corsix I assume we currently just explode the room if the strength hits 0.

To add to mugmuggy's point, I do remember that machines in the original would usually make that horrible warning sound when they were about to blow.... I don't remember this happening in Corsix currently (could be wrong).

I think 50/50 is the best balance. It could be lower if you think that might be too forgiving.
We would also need to account for earthquakes. As I'm not sure how damage is reported over the earthquake (is it by tick, or all at once?)

@TheCycoONE
Copy link
Member

Earthquake damage is by game tick and handled through machineUsed. It should not require any special consideration.

@lewri
Copy link
Member

lewri commented Jun 10, 2020

My concern is if the damage is by tick we could end up with a horrible loop:
tick - earthquake reduces strength to 0, we roll and it succeeds (sets to 1)
tick - earthquake reduces again to 0, we roll and it succeeds
etc...

To be more efficient, it would be better to wait to roll until the earthquake ends. It would definitely be kinder on the player... but I think general thoughts are that our implementation of explosions are too harsh on the player anyway right now.

Edit: Though machines can explode mid-earthquake too. So maybe instead roll on the first time it hits 0 during the earthquake, then hard set it to 1 if it succeeds until the earthquake ends.

@TheCycoONE
Copy link
Member

Why is it bad to check multiple times in the same quake? Just means your chance of being saved diminishes the more your machine wouldn't stand up to the magnitude of the quake.

@lewri
Copy link
Member

lewri commented Jun 13, 2020

Point noted. As such, I think the code below will fit this suggestion. If it's a good start then I'll make it into a PR.

+ local roll_to_crash = nil
+ -- If a fire extinguisher in the room, make explosion chance 50%
+ for object, _ in pairs(room.objects) do
+    if object.object_type.id == "extinguisher" then
+      roll_to_crash = math.random(0,1)
+      break
+    end
+  end
+  -- Room is set to explode and fire extinguisher failed to save it
+  if threshold < 1 and (roll_to_crash == nil or roll_to_crash == 1) then
    -- Clean up any task of handyman coming to repair the machine
    self.hospital:removeHandymanTask(taskIndex, "repairing")
    -- Blow up the room
    room:crashRoom()
    self:setCrashedAnimation()
    -- No special cursor required when hovering over the crashed room
    self.hover_cursor = nil
    -- Clear dynamic info (tracks machine usage which is no longer required)
    self:clearDynamicInfo()
    -- Prevent the machine from smoking, it's now just a pile of rubble
    setSmoke(self, false)
    -- If we have the window for this machine open, close it
    local window = self.world.ui:getWindow(UIMachine)
    if window and window.machine == self then
      window:close()
    end
    -- Clear the icon showing a handyman is coming to repair the machine
    self:setRepairing(nil)
    return true
+  -- Else if urgent repair needed or extinguisher saved the room
  elseif threshold < 4 then
+    if threshold < 1 then
+      self.times_used = self.times_used - 1
+    end
    -- If the job of repairing the machine isn't queued, queue it now (higher priority)
    if taskIndex == -1 then
      local call = self.world.dispatcher:callForRepair(self, true, false, true)
      self.hospital:addHandymanTask(self, "repairing", 2, self.tile_x, self.tile_y, call)
    else -- Otherwise the task is already queued. Increase the priority to above that of machines with at least 4 uses left
      self.hospital:modifyHandymanTaskPriority(taskIndex, 2, "repairing")
    end
  -- Else if repair is needed, but not urgently
  elseif threshold < 6 then
    -- If the job of repairing the machine isn't queued, queue it now (low priority)
    if taskIndex == -1 then
      local call = self.world.dispatcher:callForRepair(self)
      self.hospital:addHandymanTask(self, "repairing", 1, self.tile_x, self.tile_y, call)
    end
  end

@lewri
Copy link
Member

lewri commented Jun 13, 2020

Or do you want some kind of max times a room can be saved? And should that be concurrently, or cumulatively?

@TheCycoONE
Copy link
Member

I don't think we want or need to decrement the times_used count. machine_dialog would need to be adjusted to account for usage higher than strength, but there are other places that report raw uses which shouldn't be wrong.

@lewri
Copy link
Member

lewri commented Jun 15, 2020

To preserve times_used I found a new method of having a flag saved_by_earthquake attached to each object (really it should only attach to each machine, but no harm done here). Its default is always 0, except when we need to check its threshold has dropped below 1. In that case, it does a math.random to see if the extinguisher saved the machine. If it does, the value changes to 1 until the machine is used again (earthquakes count as use). When it is used again it will set back to 0... and roll again if our threshold is still <1.

You can look at what I've wrote at machine.lua on my patch-2 branch. Tell me if that's more suitable.

Also, as mentioned on IRC yesterday, machine_dialog doesn't seem to care when our times_used > strength for any graphical output.
image

@mugmuggy
Copy link
Contributor

I just quickly ducked into the original, with 2 quakes one after the other with strength of 5. Inflator default strength is 8, didn't smoke on the first quake wouldn't smoke until 6 uses.
Smoked after the 2nd quake and shows time used >8
image

First use after that crashed. Haven't gone and debugged it yet though.

@lewri lewri self-assigned this Jul 14, 2020
@lewri lewri added this to To do in 0.65 Release via automation Jul 14, 2020
@lewri lewri moved this from To do to In progress in 0.65 Release Jul 14, 2020
0.65 Release automation moved this from In progress to Done Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement issue type
Projects
No open projects
0.65 Release
  
Done
Development

Successfully merging a pull request may close this issue.

6 participants