From b43220dbedd328a3a19a3c2ded21e8ee52b5c5ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Aug 2007 20:33:50 +0000 Subject: [PATCH] - fixed counting of group members - fixed maximum size of region names. - fixed animals --- src/common/kernel/group.c | 58 +++++++++++++++++++++++--------------- src/common/kernel/group.h | 1 + src/common/kernel/region.c | 2 +- src/common/kernel/unit.c | 3 +- src/premake.lua | 16 ++++------- src/res/resources.xml | 16 +++++++---- 6 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/common/kernel/group.c b/src/common/kernel/group.c index a760a9634..7fc0882c3 100644 --- a/src/common/kernel/group.c +++ b/src/common/kernel/group.c @@ -132,34 +132,48 @@ free_group(group * g) free(g); } -boolean -join_group(unit * u, const char * name) +void +set_group(struct unit * u, struct group * g) { - attrib * a = NULL; - group * g; + attrib * a = NULL; + if (fval(u, UFL_GROUP)) { a = a_find(u->attribs, &at_group); } - if (a) ((group *)(a->data.v))->members--; - if (!name || !strlen(name)) { - if (a) { - a_remove(&u->attribs, a); - freset(u, UFL_GROUP); - } - return true; - } - g = find_groupbyname(u->faction->groups, name); - if (!g) { - g = new_group(u->faction, name, ++maxgid); - init_group(u->faction, g); - } - if (!a) { - a = a_add(&u->attribs, a_new(&at_group)); - fset(u, UFL_GROUP); + if (a) { + group * og = (group *)a->data.v; + if (og==g) return; + --og->members; } - a->data.v = g; - g->members++; + + if (g) { + if (!a) { + a = a_add(&u->attribs, a_new(&at_group)); + fset(u, UFL_GROUP); + } + a->data.v = g; + g->members++; + } else if (a) { + a_remove(&u->attribs, a); + freset(u, UFL_GROUP); + } +} + +boolean +join_group(unit * u, const char * name) +{ + group * g = NULL; + + if (name && name[0]) { + g = find_groupbyname(u->faction->groups, name); + if (g==NULL) { + g = new_group(u->faction, name, ++maxgid); + init_group(u->faction, g); + } + } + + set_group(u, g); return true; } diff --git a/src/common/kernel/group.h b/src/common/kernel/group.h index bd12a903e..046a6d735 100644 --- a/src/common/kernel/group.h +++ b/src/common/kernel/group.h @@ -34,6 +34,7 @@ typedef struct group { extern struct attrib_type at_group; /* attribute for units assigned to a group */ extern boolean join_group(struct unit * u, const char * name); +extern void set_group(struct unit * u, struct group * g); extern void free_group(struct group * g); extern void write_groups(FILE * F, struct group * g); diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 692c786af..c93e52520 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -121,7 +121,7 @@ write_regionname(const region * r, const faction * f, char * buffer, size_t size region_x(r, f), region_y(r, f)); } } - buf[64] = 0; + buf[size-1] = 0; return buffer; } diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 30f83f492..516136e71 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -1370,8 +1370,7 @@ create_unit(region * r, faction * f, int number, const struct race *urace, int i a = a_find(creator->attribs, &at_group); if (a) { group * g = (group*)a->data.v; - a_add(&u->attribs, a_new(&at_group))->data.v = g; - fset(u, UFL_GROUP); + set_group(u, g); } } a = a_find(creator->attribs, &at_otherfaction); diff --git a/src/premake.lua b/src/premake.lua index e375f7553..730e780ea 100644 --- a/src/premake.lua +++ b/src/premake.lua @@ -17,7 +17,7 @@ for k,v in project.configs do table.insert(package.config[v].defines, "WIN32") table.insert(package.config[v].defines, "_CRT_SECURE_NO_DEPRECATE") end - if v=="Release" then + if v~="Debug" then table.insert(package.config[v].defines, "NDEBUG") end end @@ -44,7 +44,7 @@ for k,v in project.configs do table.insert(package.config[v].defines, "WIN32") table.insert(package.config[v].defines, "_CRT_SECURE_NO_DEPRECATE") end - if v=="Release" then + if v~="Debug" then table.insert(package.config[v].defines, "NDEBUG") end end @@ -65,7 +65,7 @@ for k,v in project.configs do table.insert(package.config[v].defines, "WIN32") table.insert(package.config[v].defines, "_CRT_SECURE_NO_DEPRECATE") end - if v=="Release" then + if v~="Debug" then table.insert(package.config[v].defines, "NDEBUG") end end @@ -87,7 +87,7 @@ for k,v in project.configs do table.insert(package.config[v].defines, "WIN32") table.insert(package.config[v].defines, "_CRT_SECURE_NO_DEPRECATE") end - if v=="Release" then + if v~="Debug" then table.insert(package.config[v].defines, "NDEBUG") end end @@ -112,9 +112,7 @@ for k,v in project.configs do package.config[v].links = { "lua5.1_d", "luabind_d" } else package.config[v].links = { "lua5.1", "luabind" } - if v=="Release" then - table.insert(package.config[v].defines, "NDEBUG") - end + table.insert(package.config[v].defines, "NDEBUG") end end @@ -139,9 +137,7 @@ for k,v in project.configs do package.config[v].links = { "lua5.1_d", "luabind_d" } else package.config[v].links = { "lua5.1", "luabind" } - if v=="Release" then - table.insert(package.config[v].defines, "NDEBUG") - end + table.insert(package.config[v].defines, "NDEBUG") end -- package.config["Debug"].linkoptions = { "/NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMT" } end diff --git a/src/res/resources.xml b/src/res/resources.xml index 5a06433ff..da9392703 100644 --- a/src/res/resources.xml +++ b/src/res/resources.xml @@ -33,7 +33,7 @@ - + @@ -66,15 +66,15 @@ - + - + - + @@ -83,6 +83,8 @@ + + @@ -97,16 +99,18 @@ - + + + - +