FireBrigade.java 2.5 KB
Newer Older
Juon Kawakami's avatar
init  
Juon Kawakami committed
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package firesimulator.world;

import java.io.DataOutputStream;
import java.io.IOException;

import rescuecore.OutputBuffer;

public class FireBrigade extends MovingObject {

	public static int REFILL_QUANTITY;
	public static int REFILL_HYDRANT_QUANTITY;
	public static int MAX_WATER_QUANTITY;
	private int initialWaterQuantity;
	private int waterQuantity;
	private int waterUsed;
	private boolean changed;

	public FireBrigade(int id) {
		super(id);
		initialWaterQuantity = 0;
		waterQuantity = 0;
		waterUsed = 0;
		changed = false;
	}

	public String getType() {
		return "FIRE_BRIGADE";
	}

	public void setInitialWaterQuantity(int quantity) {
		initialWaterQuantity = quantity;
		waterQuantity = quantity;
	}

	public int getWaterQuantity() {
		return waterQuantity;
	}

	public int getWaterUsed() {
		return waterUsed;
	}

	public void setWaterQuantity(int quantity) {
		waterQuantity = quantity;
		changed = true;
	}

	public void addWaterUsed(int quantity) {
		waterUsed += quantity;
	}

	public void nextCycle() {
		waterUsed = 0;
		changed = false;
	}

	public void reset() {
		waterQuantity = initialWaterQuantity;
		waterUsed = 0;
		changed = false;
	}

	public boolean hasChanged() {
		return changed;
	}
	public boolean refillInHydrant() {
		//System.out.println(getID()+" Location is:"+getLocation()+" "+getLocation().getType());
		if(!(getLocation().getType().equals("HYDRANT")))
			return false;

		for (Object next : world.getFirebrigades()) {
			FireBrigade firebrigade = (FireBrigade)next;
			if(firebrigade.getLocationID()==this.getLocationID()&&
					firebrigade.getID()<this.getID())
					return false;
		}
		
		if (getWaterQuantity() + REFILL_HYDRANT_QUANTITY> MAX_WATER_QUANTITY) 
			setWaterQuantity(MAX_WATER_QUANTITY);
		else
			setWaterQuantity(getWaterQuantity() + REFILL_HYDRANT_QUANTITY);
		return true;
	}
	public boolean refillInRefuge() {
		if (!(getLocation().isRefuge()))
			return false;
		
		int fr = ((Refuge) getLocation()).getFieryness();
		if (fr == 3 || fr == 6 || fr == 7)
			return false;
		
		
		if (getWaterQuantity() + REFILL_QUANTITY > MAX_WATER_QUANTITY) {
			setWaterQuantity(MAX_WATER_QUANTITY);
		} else {
			setWaterQuantity(getWaterQuantity() + REFILL_QUANTITY);
		}
		return true;
	}
	public boolean refill() {
//		if (!getCurrentAction().equals("AK_REST")){
//			return false;
//		}unusable because the old simulator don't know the last action
		
		if (getLocation() == null)
			return false;
		
		if(refillInHydrant())
			return true;
		
		if(refillInRefuge())
			return true;
		
		return false;
	}
}