Skip to content

Commit

Permalink
one button for digging and cutting trees
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal committed Feb 6, 2014
1 parent 7270aa1 commit d1109b8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
32 changes: 15 additions & 17 deletions collective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ vector<Collective::BuildInfo> Collective::initialBuildInfo {
};

vector<Collective::BuildInfo> Collective::normalBuildInfo {
BuildInfo({SquareType::FLOOR, ResourceId::GOLD, 0, "Dig"}),
BuildInfo(BuildInfo::CUT_TREE),
BuildInfo(BuildInfo::DIG),
BuildInfo({SquareType::STOCKPILE, ResourceId::GOLD, 0, "Storage"}),
BuildInfo({SquareType::TREASURE_CHEST, ResourceId::WOOD, 4, "Treasure room"}),
BuildInfo({ResourceId::WOOD, 4, "door", ViewId::DOOR}),
Expand Down Expand Up @@ -498,6 +497,12 @@ void Collective::refreshGameInfo(View::GameInfo& gameInfo) const {
elem.cost <= numGold(elem.resourceId) });
}
break;
case BuildInfo::DIG: {
info.buttons.push_back({
ViewObject(ViewId::DIG_ICON, ViewLayer::LARGE_ITEM, ""),
"dig or cut tree", Nothing(), "", true});
}
break;
case BuildInfo::TRAP: {
BuildInfo::TrapInfo& elem = button.trapInfo;
int numTraps = getTrapItems(elem.type).size();
Expand All @@ -520,10 +525,6 @@ void Collective::refreshGameInfo(View::GameInfo& gameInfo) const {
elem.cost <= numGold(elem.resourceId)});
}
break;
case BuildInfo::CUT_TREE:
info.buttons.push_back({
ViewObject(ViewId::WOOD_PLANK, ViewLayer::CREATURE, ""), "Cut tree", Nothing(), "", true});
break;
case BuildInfo::IMP: {
pair<ViewObject, int> cost = {ViewObject::mana(), getImpCost()};
info.buttons.push_back({
Expand Down Expand Up @@ -883,40 +884,37 @@ void Collective::processInput(View* view) {
selection = SELECT;
}
break;
case BuildInfo::CUT_TREE:
case BuildInfo::DIG:
if (marked.count(pos) && selection != SELECT) {
unmarkSquare(pos);
selection = DESELECT;
if (throneMarked == pos)
throneMarked = Nothing();
} else {
if (!marked.count(pos) && selection != DESELECT &&
level->getSquare(pos)->canConstruct(SquareType::TREE_TRUNK)) {
} else
if (!marked.count(pos) && selection != DESELECT) {
if (level->getSquare(pos)->canConstruct(SquareType::TREE_TRUNK)) {
markSquare(pos, SquareType::TREE_TRUNK, {ResourceId::GOLD, 0});
selection = SELECT;
} else
if (level->getSquare(pos)->canConstruct(SquareType::FLOOR) || !memory[level].hasViewIndex(pos)) {
markSquare(pos, SquareType::FLOOR, { ResourceId::GOLD, 0});
selection = SELECT;
}
}
break;
case BuildInfo::SQUARE:
if (marked.count(pos) && selection != SELECT) {
unmarkSquare(pos);
selection = DESELECT;
if (throneMarked == pos)
throneMarked = Nothing();
} else {
BuildInfo::SquareInfo info = getBuildInfo()[currentButton].squareInfo;
bool diggingSquare = !memory[level].hasViewIndex(pos) ||
(level->getSquare(pos)->canConstruct(info.type));
if (!marked.count(pos) && selection != DESELECT && diggingSquare &&
numGold(info.resourceId) >= info.cost &&
(info.type != SquareType::KEEPER_THRONE || !throneMarked) &&
(info.type != SquareType::TRIBE_DOOR || canBuildDoor(pos)) &&
(info.type == SquareType::FLOOR || canSee(pos))) {
markSquare(pos, info.type, {info.resourceId, info.cost});
selection = SELECT;
takeGold({info.resourceId, info.cost});
if (info.type == SquareType::KEEPER_THRONE)
throneMarked = pos;
}
}
break;
Expand Down
5 changes: 2 additions & 3 deletions collective.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ class Collective : public CreatureView, public EventListener {
ViewId viewId;
} doorInfo;

enum BuildType { SQUARE, CUT_TREE, IMP, TRAP, DOOR, GUARD_POST, DESTROY} buildType;
enum BuildType { DIG, SQUARE, IMP, TRAP, DOOR, GUARD_POST, DESTROY} buildType;

BuildInfo(SquareInfo info) : squareInfo(info), buildType(SQUARE) {}
BuildInfo(TrapInfo info) : trapInfo(info), buildType(TRAP) {}
BuildInfo(DoorInfo info) : doorInfo(info), buildType(DOOR) {}
BuildInfo(BuildType type) : buildType(type) {
CHECK(contains({IMP, GUARD_POST, CUT_TREE, DESTROY}, type));
CHECK(contains({DIG, IMP, GUARD_POST, DESTROY}, type));
}

};
Expand Down Expand Up @@ -226,7 +226,6 @@ class Collective : public CreatureView, public EventListener {
const Creature* attender;
};
map<Vec2, GuardPostInfo> guardPosts;
Optional<Vec2> throneMarked;
double mana;
int points = 0;
Model* model;
Expand Down
1 change: 1 addition & 0 deletions enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ enum class ViewId {
ABYSS,
DOOR,
PLANNED_DOOR,
DIG_ICON,
FOUNTAIN,
CHEST,
OPENED_CHEST,
Expand Down
Binary file modified tiles3_int.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion window_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ Tile getSprite(ViewId id) {
case ViewId::ABYSS: return Tile('~', darkGray);
case ViewId::DOOR: return Tile(4, 2, 2, true);
case ViewId::PLANNED_DOOR: return Tile(4, 2, 2, true).setTranslucent(0.5);
case ViewId::DIG_ICON: return Tile(8, 10, 2);
case ViewId::SWORD: return Tile(12, 9, 3);
case ViewId::SPECIAL_SWORD: return Tile(13, 9, 3);
case ViewId::ELVEN_SWORD: return Tile(14, 9, 3);
Expand Down Expand Up @@ -514,6 +515,7 @@ Tile getAsciiTile(const ViewObject& obj) {
case ViewId::ABYSS: return Tile('~', darkGray);
case ViewId::DOOR: return Tile('|', brown);
case ViewId::PLANNED_DOOR: return Tile('|', darkBrown);
case ViewId::DIG_ICON: return Tile(8, 10, 2);
case ViewId::SWORD: return Tile(')', lightGray);
case ViewId::SPECIAL_SWORD: return Tile(')', yellow);
case ViewId::ELVEN_SWORD: return Tile(')', gray);
Expand Down Expand Up @@ -893,7 +895,7 @@ void WindowView::resize(int width, int height) {
Optional<Vec2> mousePos;

Optional<Vec2> WindowView::getHighlightedTile() {
if (!mousePos)
if (!mousePos || !mousePos->inRectangle(getMapViewBounds()))
return Nothing();
return mapLayout->projectOnMap(*mousePos);
}
Expand Down

0 comments on commit d1109b8

Please sign in to comment.