Incomp. Proto. Change: attack_dir gets <force> parameter

This commit is contained in:
Petr Baudis 2011-12-22 00:12:45 +01:00
parent 177d41cf60
commit 091708f577
6 changed files with 22 additions and 16 deletions

10
README
View file

@ -57,10 +57,11 @@ The following outputs are supported:
move_dir <x> <y>
<x> and <y> are integer offsets relative
to the current position; may be just {-1,0,1}
attack_dir <x> <y>
to the current position, may be just {-1,0,1}
attack_dir <x> <y> <force>
<x> and <y> are integer offsets relative
to the current position; may be just {-1,0,1}
to the current position, may be just {-1,0,1};
<force> is invested energy, damage is proportional
breed_dir <x> <y> <info>
<info> is arbitrary string passed to the "mother"
(to be passed to the child)
@ -105,3 +106,6 @@ If the id corresponds to a disconnected agent, the connection
is immediately attached to that agent. Combining this with other
negotiation commands is undefined, except for newborns - in that case,
negotiation commands must follow after agent_id.
TODO proto. change:
tickid for input

View file

@ -66,7 +66,7 @@ agent::move_dir(int dir_x, int dir_y)
}
bool
agent::attack_dir(int dir_x, int dir_y)
agent::attack_dir(int dir_x, int dir_y, int force)
{
if (dead || !tile)
return false;
@ -76,8 +76,8 @@ agent::attack_dir(int dir_x, int dir_y)
return false;
class agent *a = t2->agent;
chenergy(world::attack_cost);
a->chenergy(world::defense_cost);
chenergy(-force);
a->chenergy(-force * world::defense_const_factor);
if (dead || a->dead)
return true;
@ -86,9 +86,10 @@ agent::attack_dir(int dir_x, int dir_y)
int attack_roll = random() % attack_dice;
int defense_dice = round(a->attr.defense * a->energy);
int defense_roll = random() % defense_dice;
if (attack_roll > defense_roll)
a->chenergy(defense_roll - attack_roll);
return attack_roll >= defense_roll;
if (attack_roll > defense_roll) {
a->chenergy(-force);
}
return attack_roll > defense_roll;
}
bool

View file

@ -58,7 +58,7 @@ public:
void spawn_at(class tile &tile);
bool move_dir(int dir_x, int dir_y);
bool attack_dir(int dir_x, int dir_y);
bool attack_dir(int dir_x, int dir_y, int force);
bool breed_dir(int dir_x, int dir_y, std::string info);
bool secrete(int id, double intensity);

View file

@ -116,7 +116,7 @@ sub take_action($$) {
print "moves ".join(", ", @move)." => (".dirindex($max).":$max->[0],$max->[1])\n";
if ($attack[dirindex($max)]) {
print $socket "attack_dir $max->[0] $max->[1]\r\n";
print $socket "attack_dir $max->[0] $max->[1] 100\r\n";
} else {
print $socket "move_dir $max->[0] $max->[1]\r\n";
}

View file

@ -168,11 +168,12 @@ bump_negot:
bump();
mask |= 1;
} else if (!negotiation && !cmd.compare("attack_dir") && !(mask & 2)) {
int x = 0, y = 0;
sscanf(line.c_str(), "%d %d", &x, &y);
int x = 0, y = 0, force = 0;
sscanf(line.c_str(), "%d %d %d", &x, &y, &force);
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))
if (force < 1) force = 1;
if (!agent->attack_dir(x, y, force))
bump();
mask |= 2;
} else if (!negotiation && !cmd.compare("breed_dir") && !(mask & 4)) {

View file

@ -7,8 +7,6 @@ struct world {
const static int max_energy = 20000;
const static int move_cost = -50;
const static int attack_cost = -400;
const static int defense_cost = -200;
const static int breed_out_cost = -newborn_energy/4;
const static int breed_in_cost = -newborn_energy*3/4;
const static int pheromone_cost = -10;
@ -19,6 +17,8 @@ struct world {
const static int sun_energy = 10;
const static int soil_energy = 20; /* ... times five for lone herbs, times one for dense forests */
const static double defense_const_factor = 0.2;
const static int dead_body_energy = 2000;
const static double dead_body_energy_carryover = 0.5;
const static int dead_decay = -50;