aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/Ic2ExpReactorPlanner/components/Vent.java
blob: e0f26416ac4f66130d6c8cf5446949ecec566279 (plain)
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
/*
 * To change this license header, choose License Headers in Project Properties. To change this template file, choose
 * Tools | Templates and open the template in the editor.
 */
package Ic2ExpReactorPlanner.components;

import java.util.ArrayList;
import java.util.List;

import gregtech.api.objects.GT_ItemStack;

/**
 * Represents some kind of vent in a reactor.
 * 
 * @author Brian McCloud
 */
public class Vent extends ReactorItem {

    private final int selfVent;
    private final int hullDraw;
    private final int sideVent;

    public Vent(final int id, final String baseName, GT_ItemStack aItem, final double maxDamage, final double maxHeat,
            final String sourceMod, final int selfVent, final int hullDraw, final int sideVent) {
        super(id, baseName, aItem, maxDamage, maxHeat, sourceMod);
        this.selfVent = selfVent;
        this.hullDraw = hullDraw;
        this.sideVent = sideVent;
    }

    public Vent(final Vent other) {
        super(other);
        this.selfVent = other.selfVent;
        this.hullDraw = other.hullDraw;
        this.sideVent = other.sideVent;
    }

    @Override
    public double dissipate() {
        double deltaHeat = Math.min(hullDraw, parent.getCurrentHeat());
        currentHullCooling = deltaHeat;
        parent.adjustCurrentHeat(-deltaHeat);
        this.adjustCurrentHeat(deltaHeat);
        final double currentDissipation = Math.min(selfVent, getCurrentHeat());
        currentVentCooling = currentDissipation;
        parent.ventHeat(currentDissipation);
        adjustCurrentHeat(-currentDissipation);
        if (sideVent > 0) {
            List<ReactorItem> coolableNeighbors = new ArrayList<>(4);
            ReactorItem component = parent.getComponentAt(row - 1, col);
            if (component != null && component.isCoolable()) {
                coolableNeighbors.add(component);
            }
            component = parent.getComponentAt(row, col + 1);
            if (component != null && component.isCoolable()) {
                coolableNeighbors.add(component);
            }
            component = parent.getComponentAt(row + 1, col);
            if (component != null && component.isCoolable()) {
                coolableNeighbors.add(component);
            }
            component = parent.getComponentAt(row, col - 1);
            if (component != null && component.isCoolable()) {
                coolableNeighbors.add(component);
            }
            for (ReactorItem coolableNeighbor : coolableNeighbors) {
                double rejectedCooling = coolableNeighbor.adjustCurrentHeat(-sideVent);
                double tempDissipatedHeat = sideVent + rejectedCooling;
                parent.ventHeat(tempDissipatedHeat);
                currentVentCooling += tempDissipatedHeat;
            }
        }
        bestVentCooling = Math.max(bestVentCooling, currentVentCooling);
        return currentDissipation;
    }

    @Override
    public double getVentCoolingCapacity() {
        double result = selfVent;
        if (sideVent > 0) {
            ReactorItem component = parent.getComponentAt(row - 1, col);
            if (component != null && component.isCoolable()) {
                result += sideVent;
            }
            component = parent.getComponentAt(row, col + 1);
            if (component != null && component.isCoolable()) {
                result += sideVent;
            }
            component = parent.getComponentAt(row + 1, col);
            if (component != null && component.isCoolable()) {
                result += sideVent;
            }
            component = parent.getComponentAt(row, col - 1);
            if (component != null && component.isCoolable()) {
                result += sideVent;
            }
        }
        return result;
    }

    @Override
    public double getHullCoolingCapacity() {
        return hullDraw;
    }

    @Override
    public double getCurrentOutput() {
        return currentVentCooling;
    }
}