[Freeciv-Dev] Stacksize limit
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch adds stacksize server option. If it is set to 0 (default) any
number of units can fit in one square. Else it is max number of them.
I suppose that this patch should work ok, but here are some places in
server which can violate this behaviour - because it is not so simple to
decide what to do then. Examples include:
- building unit in city with full stack (my proposal is to send message
to player and hold production for as long as there is no place)
- teleporation of units for various reasons (spy after steal, break
alliance separation of stacks etc) - need to find city with free space,
but what to do if all cities are full ? Scrap unit ?
I've not touched this code yet - I'm waiting for ideas especially about
second case.
Please include this patch - it shouldn't break anything and it is first
step towards C:CTP emulation.
Artur diff -urPwb -x Makefile freeciv-old/client/packhand.c freeciv/client/packhand.c
--- freeciv-old/client/packhand.c Tue Sep 7 17:52:41 1999
+++ freeciv/client/packhand.c Sun Sep 12 11:40:21 1999
@@ -1049,6 +1049,7 @@
}
game.nation_count = packet->nation_count;
+ game.stack_size = packet->stack_size;
if(races) free(races);
races = fc_calloc(game.nation_count, sizeof(struct player_race));
}
diff -urPwb -x Makefile freeciv-old/common/game.c freeciv/common/game.c
--- freeciv-old/common/game.c Tue Sep 7 17:52:52 1999
+++ freeciv/common/game.c Sun Sep 12 11:41:06 1999
@@ -734,6 +734,7 @@
strcpy(game.ruleset.nations, GAME_DEFAULT_RULESET);
game.firepower_factor = 1;
game.num_unit_types = 0;
+ game.stack_size = 0;
game.government_count = 0;
game.default_government = G_MAGIC; /* flag */
diff -urPwb -x Makefile freeciv-old/common/game.h freeciv/common/game.h
--- freeciv-old/common/game.h Tue Sep 7 17:52:52 1999
+++ freeciv/common/game.h Sun Sep 12 11:46:14 1999
@@ -87,6 +87,7 @@
int government_when_anarchy;
int nation_count;
+ int stack_size;
struct {
char techs[MAX_LEN_NAME];
@@ -248,6 +249,10 @@
#define GAME_DEFAULT_TIMEOUT 0
#define GAME_MIN_TIMEOUT 0
#define GAME_MAX_TIMEOUT 999
+
+#define GAME_DEFAULT_STACKSIZE 0
+#define GAME_MIN_STACKSIZE 0
+#define GAME_MAX_STACKSIZE 20
#define GAME_DEFAULT_RULESET "default"
diff -urPwb -x Makefile freeciv-old/common/map.c freeciv/common/map.c
--- freeciv-old/common/map.c Tue Sep 7 17:52:56 1999
+++ freeciv/common/map.c Sun Sep 12 12:11:53 1999
@@ -16,6 +16,7 @@
#include <ctype.h>
#include "city.h"
+#include "game.h"
#include "log.h"
#include "mem.h"
#include "shared.h"
@@ -1103,4 +1104,25 @@
{
return (map_adjust_x(x1) == map_adjust_x(x2)
&& map_adjust_y(y1) == map_adjust_y(y2));
+}
+
+
+/***************************************************************
+ How many units can still go to this tile ?
+***************************************************************/
+int tile_has_free_places( int x, int y)
+{
+
+ if ( game.stack_size > 0 )
+ {
+ int count = 0;
+ unit_list_iterate(map_get_tile(x, y)->units, punit)
+ {
+ count++;
+ }
+ unit_list_iterate_end;
+ return game.stack_size - count;
+ }
+
+ return 10000;
}
diff -urPwb -x Makefile freeciv-old/common/map.h freeciv/common/map.h
--- freeciv-old/common/map.h Tue Sep 7 17:52:56 1999
+++ freeciv/common/map.h Sun Sep 12 12:11:07 1999
@@ -225,6 +225,7 @@
int is_special_close(int x, int y);
int is_special_type_close(int x, int y, enum tile_special_type spe);
int is_sea_usable(int x, int y);
+int tile_has_free_places( int x, int y);
int get_tile_food_base(struct tile * ptile);
int get_tile_shield_base(struct tile * ptile);
int get_tile_trade_base(struct tile * ptile);
diff -urPwb -x Makefile freeciv-old/common/packets.c freeciv/common/packets.c
--- freeciv-old/common/packets.c Tue Sep 7 17:52:57 1999
+++ freeciv/common/packets.c Sun Sep 12 11:38:52 1999
@@ -1917,6 +1917,7 @@
cptr=put_int8(cptr, packet->num_unit_types);
cptr=put_int8(cptr, packet->nation_count);
+ cptr=put_int8(cptr, packet->stack_size );
cptr=put_tech_list(cptr, packet->rtech.pop_pollution);
cptr=put_tech_list(cptr, packet->rtech.partisan_req);
@@ -1959,6 +1960,7 @@
iget_int8(&iter, &packet->num_unit_types);
iget_int8(&iter, &packet->nation_count);
+ iget_int8(&iter, &packet->stack_size);
iget_tech_list(&iter, packet->rtech.pop_pollution);
iget_tech_list(&iter, packet->rtech.partisan_req);
diff -urPwb -x Makefile freeciv-old/common/packets.h freeciv/common/packets.h
--- freeciv-old/common/packets.h Tue Sep 7 17:52:58 1999
+++ freeciv/common/packets.h Sun Sep 12 11:37:22 1999
@@ -459,6 +459,7 @@
int default_government;
int government_count;
int nation_count;
+ int stack_size;
};
/*********************************************************
diff -urPwb -x Makefile freeciv-old/common/unit.c freeciv/common/unit.c
--- freeciv-old/common/unit.c Tue Sep 7 17:53:01 1999
+++ freeciv/common/unit.c Sun Sep 12 12:03:19 1999
@@ -201,6 +201,8 @@
return 0;
if (city1->airlift + pcity->airlift < 2)
return 0;
+ if ( !tile_has_free_places(pcity->x, pcity->y) )
+ return 0;
return 1;
}
diff -urPwb -x Makefile freeciv-old/po/stamp-cat-id freeciv/po/stamp-cat-id
--- freeciv-old/po/stamp-cat-id Thu Jan 1 01:00:00 1970
+++ freeciv/po/stamp-cat-id Sun Sep 12 11:34:06 1999
@@ -0,0 +1 @@
+timestamp
diff -urPwb -x Makefile freeciv-old/server/ruleset.c freeciv/server/ruleset.c
--- freeciv-old/server/ruleset.c Tue Sep 7 17:53:27 1999
+++ freeciv/server/ruleset.c Sun Sep 12 11:41:28 1999
@@ -1168,6 +1168,7 @@
packet.num_unit_types = game.num_unit_types;
packet.nation_count = game.nation_count;
+ packet.stack_size = game.stack_size;
for(to=0; to<game.nplayers; to++) { /* dests */
if(dest==0 || get_player(to)==dest) {
diff -urPwb -x Makefile freeciv-old/server/stdinhand.c
freeciv/server/stdinhand.c
--- freeciv-old/server/stdinhand.c Tue Sep 7 17:53:27 1999
+++ freeciv/server/stdinhand.c Sun Sep 12 11:44:36 1999
@@ -404,6 +404,14 @@
" this option is mostly unimplemented and only affects a few rules.\n"
" See also README.rulesets and the techs, units, buildings and terrain\n"
" options." },
+
+ { "stacksize", &game.stack_size,
+ SSET_RULES, SSET_TO_CLIENT,
+ GAME_MIN_STACKSIZE, GAME_MAX_STACKSIZE, GAME_DEFAULT_STACKSIZE,
+ "Maximum number of units on same tile",
+ " Sets maximum number of units which can occupy same tile at given time.\n"
+ " If set to 0 it means there is no limit"
+ },
/* Flexible rules: these can be changed after the game has started.
* Should such flexible rules exist? diplchance is included here
diff -urPwb -x Makefile freeciv-old/server/unittools.c
freeciv/server/unittools.c
--- freeciv-old/server/unittools.c Mon Aug 23 14:35:25 1999
+++ freeciv/server/unittools.c Sun Sep 12 12:06:41 1999
@@ -66,6 +66,9 @@
if(is_enemy_unit_tile(x,y,punit->owner))
return 0;
+ if (!tile_has_free_places(x,y))
+ return 0;
+
ptile=map_get_tile(x, y);
ptile2=map_get_tile(punit->x, punit->y);
if(is_ground_unit(punit)) {
- [Freeciv-Dev] Stacksize limit,
Artur Biesiadowski <=
|
|