-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTowerSupport.cbot.txt
152 lines (148 loc) · 4.16 KB
/
TowerSupport.cbot.txt
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
extern void object::TowerSupport()
{
bool manufactureCells = false; //set to true if you want the bot to also create new PowerCells if it finds none
float triggerLevel = 0.3; //Defense Towers at this power level will be taken care of (if they have PowerCells)
object[] towerList = radarall(DefenseTower);
int[] powerList;
powerList[0] = PowerStation;
powerList[1] = PowerCaptor;
int[] cellList;
cellList[0] = PowerCell;
cellList[1] = NuclearCell;
while(true)
{
for (int i = 0;i < sizeof(towerList);i++)
{
if(load != null)
{
drop();
}
CellProduction(cellList, manufactureCells);
object facility = radar(powerList);
if(towerList[i].energyCell != null && towerList[i].energyCell.energyLevel < triggerLevel) //handling scenarios where DefenseTower has a power source in it
{
goto(towerList[i].position);
grab();
object cell = radar(cellList);
if(facility != null && cell != null && distance(position,facility.position) < distance(position,cell.position)) //recharge building exists and its closer than a power cell
{
message("Going to recharge this tower's battery.");
goto(facility.position);
while(load.energyLevel <1)
{
wait(1);
}
goto(towerList[i].position);
drop();
goto(space());
}
else if(facility != null && cell != null && distance(position,facility.position) > distance(position,cell.position)) //recharge building exists but power cell is closer
{
message("Swapping for a different cell since it's closer.");
goto(space(towerList[i].position));
drop();
goto(cell.position);
grab();
if(load.energyLevel < 1 && load.category == PowerCell)
{
goto(facility.position);
while(load.energyLevel <1)
{
wait(1);
}
}
goto(towerList[i].position);
drop();
goto(space());
}
else if(facility == null && cell != null) //no recharge building, will use power cells on the ground
{
message("No way to recharge the batteries, have to look for a new one.");
goto(space(towerList[i].position));
drop();
goto(cell.position);
grab();
goto(towerList[i].position);
drop();
goto(space());
}
else if (cell == null && facility != null) //no cells on the ground, will use PowerStation/Captor
{
message("No replacement cells, will have to recharge this one.");
goto(facility.position);
while(load.energyLevel < 1)
{
wait(1);
}
goto(towerList[i].position);
drop();
goto(space());
}
else if (cell == null && facility == null) //rare case, user should enable cell production
{
message("No way to keep the tower(s) operational, set manufactureCells to true", DisplayError);
break;
}
}
else if (towerList[i].energyCell == null) //DefenseTower has no cell on it
{
object cell = radar(cellList);
goto(cell.position);
grab();
if(load != null and load.energyLevel == 0) //grabber took something that was next to the power cell
{
message("Grabber picked up the wrong item, correcting.");
goto(space());
drop();
goto(cell.position);
grab();
}
if(facility != null && load.energyLevel < 1 && load.category == PowerCell)
{
goto(facility.position);
while(load.energyLevel <1)
{
wait(1);
}
}
goto(towerList[i].position);
drop();
goto(space());
}
}
}
}
void object::CellProduction(int[] cellList, bool manufactureCells)
{
object cell = radar(cellList);
if (cell == null && manufactureCells == true)
{
object cube = radar(Titanium);
goto(cube.position);
grab();
object make = radar(PowerPlant);
goto(make.position);
drop();
wait(2);
while(isbusy(make))
{
wait(1);
}
grab();
goto(space(make.position));
drop();
}
}
point object::CellCheck(object tower) //currently unused
{
object[] cellsOnMap = radarall(PowerCell);
point cell;
for(int i = 0;i <= sizeof(cellsOnMap);i++)
{
if(cellsOnMap[i].energyLevel > load.energyLevel or cellsOnMap[i].energyLevel > tower.energyCell.energyLevel)
{
return cell = cellsOnMap[i].position;
}
}
return cell = new point(9999,9999,999);
}