-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_panel_fleet.cpp
More file actions
225 lines (202 loc) · 6.36 KB
/
gui_panel_fleet.cpp
File metadata and controls
225 lines (202 loc) · 6.36 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
using namespace std;
#include <SDL.h>
#include "gui.h"
#include "game.h"
#include "audio.h"
#include "fonts.h"
#include "graphics.h"
#include "gui_local.h"
#include "ship.h"
#include "fleet.h"
#include "position.h"
#define SKIP 3
static int selection = -1, grabbed = -1;
static int panel_offset = 0;
void gui_init_fleet() {
}
void panel_init_fleet() {
buttlist[PANEL_FLEET][BUTTON_EXIT] = 11;
panel_offset = 0;
selection = -1;
grabbed = -1;
}
void panel_cleanup_fleet() {
}
void panel_draw_fleet() {
int line = 0;
char buf[80];
Fleet *flt = (Fleet*)cur_object;
int col = cur_game->players[flt->Owner()]->color;
SDL_Rect screenrec = {800, 12, 224, 24*23};
screenrec.h = min(int(screenrec.h), 24*(flt->NumShips()+SKIP));
SDL_FillRect(screen, &screenrec, black);
sprintf(buf, "Fleet: %s", flt->Name());
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
if(flt->Target() && flt->Distance() >= 0) {
sprintf(buf, "Course to %s", flt->Target()->Name());
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
int eta = flt->Distance();
if(eta > 1) sprintf(buf, "ETA: %d Days", eta);
else if(eta == 1) sprintf(buf, "ETA: 1 Day");
else sprintf(buf, "Would Arrive Today");
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
}
else if(flt->Target()) {
sprintf(buf, "Invalid Course");
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
int eta = -flt->Distance();
if(eta > 1) sprintf(buf, "ETA: %d Days", eta);
else if(eta == 1) sprintf(buf, "ETA: 1 Day");
else sprintf(buf, "Would Arrive Today");
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
}
else if((!flt->Location()) && (!flt->Destination())) {
sprintf(buf, "Orbiting Star");
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
sprintf(buf, "%d-Day Orbit", (flt->Period()+255)/256);
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
}
else if(!flt->Destination()) {
sprintf(buf, "Orbiting %s", flt->Location()->Name());
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
sprintf(buf, "16 Orbits/Day");
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
}
else {
sprintf(buf, "Going to %s", flt->Destination()->Name());
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
int eta = flt->ArriveTurn() - cur_game->turn;
if(eta > 1) sprintf(buf, "ETA: %d Days", eta);
else if(eta == 1) sprintf(buf, "ETA: 1 Day");
else sprintf(buf, "Arriving Today");
string_draw(screen, 816, 13+24*(line++), cur_font_black[col], buf);
}
for(int ctr=0; ctr < min(int(flt->NumShips()), 23-SKIP); ++ctr) {
int clr = cur_game->players[flt->GetShip(ctr)->Owner()]->color;
if(ctr == selection) clr = 8;
sprintf(buf, " %s: %s",
flt->GetShip(ctr)->CName(), flt->GetShip(ctr)->Name());
string_draw(screen, 816, 13+24*(line++), cur_font_black[clr], buf);
}
if(flt->NumShips() > 1) {
buttlist[PANEL_FLEET][BUTTON_SPLIT] = 9;
}
else {
buttlist[PANEL_FLEET][BUTTON_SPLIT] = 0;
}
if(flt->CanLand() && (!flt->Destination())) {
buttlist[PANEL_FLEET][BUTTON_LAND] = 10;
mo[BUTTON_LAND] = -1;
}
else {
buttlist[PANEL_FLEET][BUTTON_LAND] = 0;
SDL_Rect canrec = {800, 768-64*2, 224, 64};
SDL_FillRect(screen, &canrec, black);
update(&canrec);
}
}
void panel_clicked_fleet(int mx, int my, int mb) {
Fleet *flt = (Fleet*)cur_object;
if(mx >= 800 && mb == 4) {
--panel_offset;
panel_draw_fleet();
SDL_Rect screenrec = {800, 12+24*SKIP, 224, 24*23};
screenrec.h = min(int(screenrec.h), 24*(flt->NumShips()));
update(&screenrec);
return;
}
if(mx >= 800 && mb == 5) {
++panel_offset;
panel_draw_fleet();
SDL_Rect screenrec = {800, 12+24*SKIP, 224, 24*23};
screenrec.h = min(int(screenrec.h), 24*(flt->NumShips()));
update(&screenrec);
return;
}
int line = my;
line -= 12+24*SKIP;
if(line >= 0) line /= 24;
if(line < 0 || line > 22
|| line >= int(flt->NumShips()) - panel_offset) {
if(selection >= 0) {
update(800, 12+24*(SKIP+selection-panel_offset), 224, 24);
selection = -1;
panel_draw_fleet();
}
return;
}
line += panel_offset;
if(mb == 3) {
}
else if(mb == 1) {
SDL_Rect screenrec = {800, 12+24*SKIP, 224, 24};
if(selection >= 0) {
screenrec.y = 12+24*(SKIP+selection);
update(&screenrec);
}
if(selection != line) {
selection = line;
screenrec.y = 12+24*(SKIP+selection);
update(&screenrec);
panel_draw_fleet();
}
else {
cur_ship = line;
panel = PANEL_SHIP;
panel_init();
}
audio_play(click2, 8, 8);
}
}
void mouse_released_fleet() {
grabbed = -1;
}
void mouse_moved_fleet(int mx, int my) {
}
void button_clicked_fleet(int button) {
Fleet *flt = (Fleet*)cur_object;
if(button == BUTTON_LAND) {
if(!flt->CanLand()) return;
if(!flt->Location()) return;
if(!flt->Location()->Represents()) return;
if(((Planet*)flt->Location()->Represents())->colonies.size() < 1) {
((Planet*)flt->Location()->Represents())->colonies.push_back(
new Colony(flt->Owner(), ((Planet*)flt->Location()->Represents()))
);
}
int which = 0;
while(!flt->GetShip(which)->CanLand()) ++which;
((Planet*)flt->Location()->Represents())->colonies[0]->LandShip(flt->GetShip(which));
if(flt->NumShips() <= 1) clear_sprites(1, 10);
flt->DestroyShip(which);
panel_draw();
page_draw();
}
if(button == BUTTON_SPLIT) {
/*
if(!flt->Location()) return;
if(!flt->Location()->Represents()) return;
for(int shp=1; shp < flt->NumShips(); ++shp) {
Fleet *newfleet = new Fleet(flt->Location()->Represents(), flt->Name());
newfleet->AddShip(flt->GetShip(shp));
newfleet->Location()->Represents()->Sys()->objects.push_back(newfleet);
}
*/
for(int shp=1; shp < flt->NumShips(); ++shp) {
Fleet *newfleet = new Fleet();
newfleet->CopyFrom(flt);
newfleet->SetName(flt->Name());
newfleet->AddShip(flt->GetShip(shp));
flt->Sys()->objects.push_back(newfleet);
}
flt->RemoveShips(1);
page_draw();
panel_init();
}
}
void panel_update_fleet() {
}