[Freeciv-Dev] Re: Barbarians
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
At 1999/10/21 14:38 , Jerzy Klek wrote:
>So this is what I did for barbarians. Hopefully worth
>discussing.
Looks like a great start. Sometimes, they can be awfully vicious. (Like
when I stepped on a Hut on an island, and the Barbarians loaded up several
boats and went off to pillage multiple places in my empire ;-)
I noticed a few, minor things (which all seem related):
- Barbarians show up in the Players dialog; they probably shouldn't.
- Barbarians show up in the Historian Reports; they probably shouldn't.
- Barbarians show up in the Final Report; they probably shouldn't.
Another thought: I haven't checked, but are Barbarians included in the
Demographics Report (when it comes to what place you are)? Again, they
probably shouldn't be.
Also, once, when I surrounded a Hut on an island, it seemed to create a
boat without any units on board. This led me to looking at
unleash_barbarians(). I think it may have a couple of small problems in
the following section of code:
if( sea_cnt > 0 ) { /* maybe it's an island, try to get on boats */
boat = find_a_unit_type(L_BARBARIAN_BOAT, -1);
boat_cnt = unit_cnt/unit_types[boat].transport_capacity + 1;
for( i=0; i < boat_cnt; i++ ) {
do rand_neighbour(x, y, &xu, &yu);
while( !is_free_sea(xu, yu, me) );
create_unit( barbarians, xu, yu, boat, 0, 0, -1);
}
unit_list_iterate(map_get_tile(x, y)->units, punit2)
if( punit2->owner == me ) {
send_unit_info( 0, punit2, 0);
do rand_neighbour(x, y, &xu, &yu);
while( !(is_free_sea(xu, yu, me) || is_free_land(xu, yu, me)) );
handle_unit_move_request(barbarians, punit2, xu, yu);
}
unit_list_iterate_end;
}
First, shouldn't:
boat_cnt = unit_cnt/unit_types[boat].transport_capacity + 1;
be
boat_cnt = ((unit_cnt - 1)/unit_types[boat].transport_capacity) + 1;
?
And, even then it overestimates the number of boats needed, because it
doesn't take into account free land squares.
Also, when you are moving units onto boats, you only check for is_free_sea().
But, shouldn't you check to make sure there's a boat there?
I think it should maybe create boats on the fly, like:
int xb, yb, rem;
if( sea_cnt > 0 ) { /* maybe it's an island, try to get on boats */
boat = find_a_unit_type(L_BARBARIAN_BOAT, -1);
xb = yb = -1;
rem = unit_types[boat].transport_capacity;
unit_list_iterate(map_get_tile(x, y)->units, punit2)
if( punit2->owner == me ) {
send_unit_info( 0, punit2, 0);
for (;;) {
rand_neighbour(x, y, &xu, &yu);
if( is_free_land(xu, yu, me) ) break;
if( (xu == xb) && (yu == yb) ) {
if( rem > 0 ) {
rem--;
break;
}
xb = yb = -1;
} else if( (xb < 0) && (yb < 0) && is_free_sea(xu, yu, me)) {
create_unit( barbarians, xu, yu, boat, 0, 0, -1);
xb = xu;
yb = yu;
rem = unit_types[boat].transport_capacity - 1;
break;
}
}
handle_unit_move_request(barbarians, punit2, xu, yu);
}
unit_list_iterate_end;
}
(The above is just a suggestion -- I didn't even try to compile it ;-)
jjm
|
|