forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poison_gas.cpp
35 lines (29 loc) · 867 Bytes
/
poison_gas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "stdafx.h"
#include "poison_gas.h"
#include "level.h"
void PoisonGas::addAmount(double a) {
CHECK(a > 0);
amount = min(3., a + amount);
}
const double decrease = 0.001;
const double spread = 0.10;
void PoisonGas::tick(Level* level, Vec2 pos) {
if (amount < 0.1) {
amount = 0;
return;
}
for (Vec2 v : Vec2::directions8(true)) {
Square* square = level->getSquare(pos + v);
if (square->canSeeThru() && amount > 0 && square->getPoisonGasAmount() < amount) {
double transfer = v.isCardinal4() ? spread : spread / 2;
transfer = min(amount, transfer);
transfer = min((amount - square->getPoisonGasAmount()) / 2, transfer);
amount -= transfer;
level->getSquare(v + pos)->addPoisonGas(transfer);
}
}
amount = max(0.0, amount - decrease);
}
double PoisonGas::getAmount() const {
return amount;
}