forked from github/server
make it impossible to create buildings with size 0
This commit is contained in:
parent
2d39641e3f
commit
a5b39962fd
|
@ -183,16 +183,20 @@ static int tolua_building_set_owner(lua_State * L)
|
||||||
|
|
||||||
static int tolua_building_create(lua_State * L)
|
static int tolua_building_create(lua_State * L)
|
||||||
{
|
{
|
||||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
region *r = (region *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *bname = tolua_tostring(L, 2, 0);
|
const char *bname = tolua_tostring(L, 2, NULL);
|
||||||
|
int size = (int)tolua_tonumber(L, 3, 1);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
log_error("building.create expects a region as argument 1");
|
log_error("building.create expects a region as argument 1");
|
||||||
} else if (!bname) {
|
} else if (!bname) {
|
||||||
log_error("building.create expects a name as argument 2");
|
log_error("building.create expects a name as argument 2");
|
||||||
|
}
|
||||||
|
else if (size <= 0) {
|
||||||
|
log_error("building.create expects a size > 0");
|
||||||
} else {
|
} else {
|
||||||
const building_type *btype = bt_find(bname);
|
const building_type *btype = bt_find(bname);
|
||||||
if (btype) {
|
if (btype) {
|
||||||
building *b = new_building(btype, r, default_locale);
|
building *b = new_building(btype, r, default_locale, size);
|
||||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -827,8 +827,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
b->size += built;
|
b->size += built;
|
||||||
} else {
|
} else {
|
||||||
/* build a new building */
|
/* build a new building */
|
||||||
b = new_building(btype, r, lang);
|
b = new_building(btype, r, lang, built);
|
||||||
b->size = built;
|
|
||||||
b->type = btype;
|
b->type = btype;
|
||||||
fset(b, BLD_MAINTAINED);
|
fset(b, BLD_MAINTAINED);
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ building *building_create(int id)
|
||||||
}
|
}
|
||||||
|
|
||||||
building *new_building(const struct building_type * btype, region * r,
|
building *new_building(const struct building_type * btype, region * r,
|
||||||
const struct locale * lang)
|
const struct locale * lang, int size)
|
||||||
{
|
{
|
||||||
building **bptr = &r->buildings;
|
building **bptr = &r->buildings;
|
||||||
int id = newcontainerid();
|
int id = newcontainerid();
|
||||||
|
@ -377,6 +377,7 @@ building *new_building(const struct building_type * btype, region * r,
|
||||||
const char *bname;
|
const char *bname;
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
|
|
||||||
|
assert(size > 0);
|
||||||
b->type = btype;
|
b->type = btype;
|
||||||
b->region = r;
|
b->region = r;
|
||||||
while (*bptr)
|
while (*bptr)
|
||||||
|
@ -396,6 +397,7 @@ building *new_building(const struct building_type * btype, region * r,
|
||||||
assert(bname);
|
assert(bname);
|
||||||
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
|
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
|
||||||
b->name = str_strdup(bname);
|
b->name = str_strdup(bname);
|
||||||
|
b->size = size;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ extern "C" {
|
||||||
int buildingcapacity(const struct building *b);
|
int buildingcapacity(const struct building *b);
|
||||||
struct building *building_create(int id);
|
struct building *building_create(int id);
|
||||||
struct building *new_building(const struct building_type *typ,
|
struct building *new_building(const struct building_type *typ,
|
||||||
struct region *r, const struct locale *lang);
|
struct region *r, const struct locale *lang, int size);
|
||||||
int build_building(struct unit *u, const struct building_type *typ,
|
int build_building(struct unit *u, const struct building_type *typ,
|
||||||
int id, int size, struct order *ord);
|
int id, int size, struct order *ord);
|
||||||
bool building_finished(const struct building *b);
|
bool building_finished(const struct building *b);
|
||||||
|
|
|
@ -61,7 +61,7 @@ static void test_rename_building(CuTest * tc)
|
||||||
test_create_locale();
|
test_create_locale();
|
||||||
btype = test_create_buildingtype("castle");
|
btype = test_create_buildingtype("castle");
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
b = new_building(btype, r, default_locale);
|
b = new_building(btype, r, default_locale, 1);
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
u_set_building(u, b);
|
u_set_building(u, b);
|
||||||
|
@ -84,7 +84,7 @@ static void test_rename_building_twice(CuTest * tc)
|
||||||
test_create_locale();
|
test_create_locale();
|
||||||
btype = test_create_buildingtype("castle");
|
btype = test_create_buildingtype("castle");
|
||||||
r = test_create_region(0, 0, NULL);
|
r = test_create_region(0, 0, NULL);
|
||||||
b = new_building(btype, r, default_locale);
|
b = new_building(btype, r, default_locale, 1);
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
u_set_building(u, b);
|
u_set_building(u, b);
|
||||||
|
|
|
@ -42,8 +42,7 @@ void equip_newunits(struct unit *u)
|
||||||
if (u->building == NULL) {
|
if (u->building == NULL) {
|
||||||
const building_type *btype = bt_find("castle");
|
const building_type *btype = bt_find("castle");
|
||||||
if (btype != NULL) {
|
if (btype != NULL) {
|
||||||
building *b = new_building(btype, r, u->faction->locale);
|
building *b = new_building(btype, r, u->faction->locale, 10);
|
||||||
b->size = 10;
|
|
||||||
u_set_building(u, b);
|
u_set_building(u, b);
|
||||||
building_set_owner(u);
|
building_set_owner(u);
|
||||||
}
|
}
|
||||||
|
|
11
src/spells.c
11
src/spells.c
|
@ -4415,7 +4415,7 @@ int sp_icastle(castorder * co)
|
||||||
const building_type *type;
|
const building_type *type;
|
||||||
region *r = co_get_region(co);
|
region *r = co_get_region(co);
|
||||||
unit *mage = co_get_caster(co);
|
unit *mage = co_get_caster(co);
|
||||||
int cast_level = co->level;
|
int size, cast_level = co->level;
|
||||||
double power = co->force;
|
double power = co->force;
|
||||||
spellparameter *pa = co->par;
|
spellparameter *pa = co->par;
|
||||||
const char *bname;
|
const char *bname;
|
||||||
|
@ -4431,18 +4431,17 @@ int sp_icastle(castorder * co)
|
||||||
type = bt_find("castle");
|
type = bt_find("castle");
|
||||||
}
|
}
|
||||||
|
|
||||||
b = new_building(bt_illusion, r, mage->faction->locale);
|
|
||||||
|
|
||||||
/* Groesse festlegen. */
|
/* Groesse festlegen. */
|
||||||
if (type == bt_illusion) {
|
if (type == bt_illusion) {
|
||||||
b->size = (rng_int() % (int)((power * power) + 1) * 10);
|
size = (rng_int() % (int)((power * power) + 1) * 10);
|
||||||
}
|
}
|
||||||
else if (type->maxsize > 0) {
|
else if (type->maxsize > 0) {
|
||||||
b->size = type->maxsize;
|
size = type->maxsize;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b->size = ((rng_int() % (int)(power)) + 1) * 5;
|
size = ((rng_int() % (int)(power)) + 1) * 5;
|
||||||
}
|
}
|
||||||
|
b = new_building(bt_illusion, r, mage->faction->locale, size);
|
||||||
|
|
||||||
bname = LOC(mage->faction->locale, buildingtype(type, b, 0));
|
bname = LOC(mage->faction->locale, buildingtype(type, b, 0));
|
||||||
building_setname(b, bname);
|
building_setname(b, bname);
|
||||||
|
|
|
@ -335,8 +335,7 @@ building * test_create_building(region * r, const building_type * btype)
|
||||||
bt_castle->flags |= BTF_FORTIFICATION;
|
bt_castle->flags |= BTF_FORTIFICATION;
|
||||||
btype = bt_castle;
|
btype = bt_castle;
|
||||||
}
|
}
|
||||||
b = new_building(btype, r, default_locale);
|
b = new_building(btype, r, default_locale, (btype->maxsize > 0) ? btype->maxsize : 1);
|
||||||
b->size = btype->maxsize > 0 ? btype->maxsize : 1;
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,13 +116,13 @@ static attrib_type at_wormhole = {
|
||||||
static void
|
static void
|
||||||
make_wormhole(const building_type * bt_wormhole, region * r1, region * r2)
|
make_wormhole(const building_type * bt_wormhole, region * r1, region * r2)
|
||||||
{
|
{
|
||||||
building *b1 = new_building(bt_wormhole, r1, default_locale);
|
int size = bt_wormhole->maxcapacity * bt_wormhole->capacity;
|
||||||
building *b2 = new_building(bt_wormhole, r2, default_locale);
|
building *b1 = new_building(bt_wormhole, r1, default_locale, size);
|
||||||
|
building *b2 = new_building(bt_wormhole, r2, default_locale, size);
|
||||||
attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
|
attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
|
||||||
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
|
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
|
||||||
a1->data.v = b2->region;
|
a1->data.v = b2->region;
|
||||||
a2->data.v = b1->region;
|
a2->data.v = b1->region;
|
||||||
b1->size = b2->size = bt_wormhole->maxcapacity * bt_wormhole->capacity;
|
|
||||||
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
|
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
|
||||||
ADDMSG(&r2->msgs, msg_message("wormhole_appear", "region", r2));
|
ADDMSG(&r2->msgs, msg_message("wormhole_appear", "region", r2));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue