mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
connection::actions(): Do not permit multiple actions of the same kind per tick
This commit is contained in:
parent
0e1243f86f
commit
529c401457
1 changed files with 6 additions and 2 deletions
|
@ -61,6 +61,8 @@ connection::actions(class agent &agent)
|
|||
}
|
||||
|
||||
while (in_buf.c_str()[0] != '\r') {
|
||||
int mask = 0;
|
||||
|
||||
int nlofs = in_buf.find("\r\n");
|
||||
std::string line = in_buf.substr(0, nlofs);
|
||||
in_buf.erase(0, nlofs + 2);
|
||||
|
@ -85,20 +87,22 @@ connection::actions(class agent &agent)
|
|||
if (rate >= 0 && rate <= 1)
|
||||
agent.attr.defense = rate;
|
||||
|
||||
} else if (!negotiation && !cmd.compare("move_dir")) {
|
||||
} else if (!negotiation && !cmd.compare("move_dir") && !(mask & 1)) {
|
||||
int x = 0, y = 0;
|
||||
sscanf(line.c_str(), "%d %d", &x, &y);
|
||||
if (x < -1) x = -1; if (x > 1) x = 1;
|
||||
if (y < -1) y = -1; if (y > 1) y = 1;
|
||||
if (!agent.move_dir(x, y))
|
||||
bump();
|
||||
} else if (!negotiation && !cmd.compare("attack_dir")) {
|
||||
mask |= 1;
|
||||
} else if (!negotiation && !cmd.compare("attack_dir") && !(mask & 2)) {
|
||||
int x = 0, y = 0;
|
||||
sscanf(line.c_str(), "%d %d", &x, &y);
|
||||
if (x < -1) x = -1; if (x > 1) x = 1;
|
||||
if (y < -1) y = -1; if (y > 1) y = 1;
|
||||
if (!agent.attack_dir(x, y))
|
||||
bump();
|
||||
mask |= 2;
|
||||
|
||||
} else {
|
||||
std::cout << "unknown line " << cmd << " " << line << " ...\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue