-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandcard.cpp
executable file
·99 lines (81 loc) · 3.38 KB
/
commandcard.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
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
#include "main.hpp"
CommandCard::CommandCard()
{
for(unsigned ii=0; ii<height; ii++)
for(unsigned jj=0; jj<width; jj++)
buttons[ii][jj] = NULL;
}
void CommandCard::addButton(CommandButton *button)
{
int xpos=button->preferredX,
ypos=button->preferredY;
while(buttons[ypos][xpos] != NULL) {
xpos++;
if(xpos>=width) {
xpos=0;
ypos++;
if(ypos>=height) ypos=0;
}
if(xpos==button->preferredX && ypos==button->preferredY)
break;
}
buttons[ypos][xpos] = button;
}
CommandButton *CommandCard::getButton(int x, int y)
{
return buttons[y][x];
}
CommandButton::CommandButton(Image image, char hotkey, unsigned x, unsigned y,
Command::CommandType cmd, Command::CommandType unitcmd, std::string tooltip)
: image(image), hotkey(hotkey), preferredX(x), preferredY(y), command(cmd),
unitCommand(unitcmd), targetted(true), isProduction(false), tooltip(tooltip)
{
}
CommandButton::CommandButton(Image image, char hotkey, unsigned x, unsigned y,
Command::CommandType cmd, std::string tooltip)
: image(image), hotkey(hotkey), preferredX(x), preferredY(y), command(cmd),
unitCommand(Command::none), targetted(false), isProduction(false), tooltip(tooltip)
{
}
CommandButton::CommandButton(Image image, char hotkey, unsigned x, unsigned y, std::string unit, std::string tooltip)
: image(image), hotkey(hotkey), preferredX(x), preferredY(y), command(Command::buildUnit),
unitCommand(Command::none), targetted(false), unitType(unit), isProduction(true), tooltip(tooltip)
{
}
CommandButton commandMove (Image("buttons/button_move.png"), 'm', 1, 0, Command::move, Command::follow, "(M) Move");
CommandButton commandAttack (Image("buttons/button_attack.png"), 'a', 0, 0, Command::attackMove, Command::attack, "(A) Attack");
CommandButton commandStop (Image("buttons/button_cancel.png"), 's', 2, 0, Command::stop, "(S) Stop");
CommandButton commandUnload (Image("buttons/button_unload.png"), 'u', 0, 1, Command::unload, "(U) Unload");
CommandButton commandRetreat(Image("buttons/button_retreat.png"), 'r', 3, 0, Command::retreat, "(R) Retreat");
void CommandCard::addButtonName(const std::string &name)
{
if(name=="attack")
addButton(&commandAttack);
else if(name=="move")
addButton(&commandMove);
else if(name=="stop")
addButton(&commandStop);
else if(name=="retreat")
addButton(&commandRetreat);
else if(name=="unload_all")
addButton(&commandUnload);
}
CommandCard scrapyardCommands;
CommandCard blankCommandCard;
CommandButton buildRepeat(Image("buttons/button_repeat.png"), 'r', 2, 2, "repeat", "(R) Repeat production");
CommandButton buildRally(Image("buttons/button_rally.png"), 'y', 3, 2, Command::setRally, "(Y) Set rally point");
void initCommandCard()
{
Parser unitListFile("units/unitlist.dat");
const Parser::Section *units = unitListFile.getSection("units");
for(Parser::Section::const_iterator ii=units->begin(); ii!=units->end(); ii++)
{
const Parser::Line &L = *ii;
const UnitInfo *type = UnitInfo::getUnitType(L[0]);
CommandButton *button = new CommandButton(type->productionIcon, type->hotkey, type->hudX, type->hudY, L[0],
retprintf("(%c) Build %s", toupper(type->hotkey), type->name.c_str()));
scrapyardCommands.addButton(button);
}
scrapyardCommands.addButton(&buildRepeat);
scrapyardCommands.addButton(&buildRally);
}