diff --git a/README b/README index 7de38c7..937314b 100644 --- a/README +++ b/README @@ -57,10 +57,11 @@ The following outputs are supported: move_dir and are integer offsets relative - to the current position; may be just {-1,0,1} - attack_dir + to the current position, may be just {-1,0,1} + attack_dir and are integer offsets relative - to the current position; may be just {-1,0,1} + to the current position, may be just {-1,0,1}; + is invested energy, damage is proportional breed_dir 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 diff --git a/agent.cc b/agent.cc index 2b117ce..237a341 100644 --- a/agent.cc +++ b/agent.cc @@ -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 diff --git a/agent.h b/agent.h index 747c8bf..c900f62 100644 --- a/agent.h +++ b/agent.h @@ -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); diff --git a/client/example.pl b/client/example.pl index 60e5547..9bbc82f 100755 --- a/client/example.pl +++ b/client/example.pl @@ -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"; } diff --git a/connection.cc b/connection.cc index 64b9403..eaa90f6 100644 --- a/connection.cc +++ b/connection.cc @@ -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)) { diff --git a/world.h b/world.h index ac21459..d24ccb9 100644 --- a/world.h +++ b/world.h @@ -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;