summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-11-27 05:52:06 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-11-27 05:57:36 +0100
commita93188b3a226c4d61e531eef270c6e7be975da4c (patch)
treeac94236d14ae5b0627799515816ffa1784935109
parent8bfe5dc896639328329197c32e2276309aa1b83d (diff)
Split target type and target offset in Action.
-rw-r--r--common/action.cpp6
-rw-r--r--common/action.h15
-rw-r--r--server/game.cpp12
3 files changed, 21 insertions, 12 deletions
diff --git a/common/action.cpp b/common/action.cpp
index 77988d6..527d25e 100644
--- a/common/action.cpp
+++ b/common/action.cpp
@@ -1,14 +1,14 @@
#include "action.h"
#include <algorithm>
-Action::Action() {
+Action::Action() : target_type(None), target_offset(0) {
}
-Action::Action(Type ty, int ta) : type(ty), target(ta) {
+Action::Action(Type ty, TargetType tt, int to) : type(ty), target_type(tt), target_offset(to) {
}
bool Action::operator==(const Action& other) {
- return type == other.type && target == other.target;
+ return type == other.type && target_type == other.target_type && target_offset == other.target_offset;
}
diff --git a/common/action.h b/common/action.h
index e1b06f2..122411b 100644
--- a/common/action.h
+++ b/common/action.h
@@ -18,14 +18,22 @@ class Action {
Draw // draw
};
+ //! Action target type.
+ enum TargetType {
+ None, // No target
+ Hand, // Target in hand.
+ Open // Target in open.
+ };
+
//! Type of action.
Type type;
//! Target of action (if applicable).
- int target;
+ TargetType target_type;
+ int target_offset;
Action();
- Action(Type ty, int ta = 0);
+ Action(Type ty, TargetType tt = None, int to = 0);
//! Compare to another action.
bool operator==(const Action& other);
@@ -33,7 +41,8 @@ class Action {
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & type;
- ar & target;
+ ar & target_type;
+ ar & target_offset;
}
};
diff --git a/server/game.cpp b/server/game.cpp
index 56885c3..5319e1b 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -156,7 +156,7 @@ void Game::round_update_discard() {
void Game::handle_action_draw(Action action) {
switch(action.type) {
case Action::Discard: {
- players[current_player].discard(action.target);
+ players[current_player].discard(action.target_offset);
round_update_discard();
} break;
@@ -295,12 +295,12 @@ Actions Game::Player::get_actions_draw() {
// List all tiles that can be discarded.
for(std::size_t i = 0; i < hand.size(); i++) {
- possible_actions.push_back(Action(Action::Discard, i));
+ possible_actions.push_back(Action(Action::Discard, Action::Hand, i));
}
} else {
// Only tile that can be discarded is the last drawn one.
- possible_actions.push_back(Action(Action::Discard, hand.size() - 1));
+ possible_actions.push_back(Action(Action::Discard, Action::Hand, hand.size() - 1));
}
return possible_actions;
@@ -314,18 +314,18 @@ Actions Game::Player::get_actions_discard(Tile tile) {
Targets targets = can_chi(tile);
if(!targets.empty()) {
for(Targets::iterator it = targets.begin(); it != targets.end(); it++) {
- possible_actions.push_back(Action(Action::Chi, *it));
+ possible_actions.push_back(Action(Action::Chi, Action::Hand, *it));
}
}
// Check if tile can be called for a pon.
int target = can_pon(tile);
if(target > 0) {
- possible_actions.push_back(Action(Action::Pon, target));
+ possible_actions.push_back(Action(Action::Pon, Action::Hand, target + 1));
// Check if tile can be called for a kan.
if(can_kan(tile, target)) {
- possible_actions.push_back(Action(Action::Kan, target));
+ possible_actions.push_back(Action(Action::Kan, Action::Hand, target + 2));
}
}
}