"ID zu groß"
- fixed parameters for some lua functions (pointers/objects)
Issue: 1457
This commit is contained in:
Enno Rehling 2008-07-08 22:28:22 +00:00
parent cf789999cf
commit 67c4b861f1
9 changed files with 327 additions and 337 deletions

View file

@ -75,11 +75,11 @@ lc_age(struct attrib * a)
}
static int
building_addaction(building& b, const char * fname, const char * param)
building_addaction(building * b, const char * fname, const char * param)
{
attrib * a = a_add(&b.attribs, a_new(&at_building_action));
attrib * a = a_add(&b->attribs, a_new(&at_building_action));
building_action * data = (building_action*)a->data.v;
data->b = &b;
data->b = b;
data->fname = strdup(fname);
if (param) data->param = strdup(param);
@ -87,41 +87,41 @@ building_addaction(building& b, const char * fname, const char * param)
}
static const char *
building_getinfo(const building& b)
building_getinfo(const building * b)
{
return (const char*)b.display;
return (const char*)b->display;
}
static void
building_setinfo(building& b, const char * info)
building_setinfo(building * b, const char * info)
{
free(b.display);
b.display = strdup(info);
free(b->display);
b->display = strdup(info);
}
static const char *
building_getname(const building& b)
building_getname(const building * b)
{
return (const char *)b.name;
return (const char *)b->name;
}
static void
building_setname(building& b, const char * name)
building_setname(building * b, const char * name)
{
free(b.name);
b.name = strdup(name);
free(b->name);
b->name = strdup(name);
}
static region *
building_getregion(const building& b)
building_getregion(const building * b)
{
return b.region;
return b->region;
}
static void
building_setregion(building& bld, region& r)
building_setregion(building * bld, region * r)
{
building * b = &bld;
building * b = bld;
building ** blist = &b->region->buildings;
while (*blist && *blist!=b) {
blist = &(*blist)->next;
@ -129,11 +129,11 @@ building_setregion(building& bld, region& r)
*blist = b->next;
b->next = NULL;
blist = &r.buildings;
blist = &r->buildings;
while (*blist && *blist!=b) blist = &(*blist)->next;
*blist = b;
b->region = &r;
b->region = r;
}
static std::ostream&

View file

@ -159,9 +159,9 @@ get_direction(const char * name)
}
static void
lua_equipunit(unit& u, const char * eqname)
lua_equipunit(unit * u, const char * eqname)
{
equip_unit(&u, get_equipment(eqname));
equip_unit(u, get_equipment(eqname));
}
static void
@ -199,11 +199,11 @@ update_subscriptions(void)
}
static void
lua_learnskill(unit& u, const char * skname, float chances)
lua_learnskill(unit * u, const char * skname, float chances)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
learn_skill(&u, sk, chances);
learn_skill(u, sk, chances);
}
}

View file

@ -65,33 +65,33 @@ public:
};
static eressea::list<unit *, unit *, factionunit>
faction_units(const faction& f)
faction_units(const faction * f)
{
return eressea::list<unit *, unit *, factionunit>(f.units);
return eressea::list<unit *, unit *, factionunit>(f->units);
}
static void
faction_setalliance(faction& f, alliance * team)
faction_setalliance(faction * f, alliance * team)
{
if (f.alliance==0) setalliance(&f, team);
if (f->alliance==0) setalliance(f, team);
}
static alliance *
faction_getalliance(const faction& f)
faction_getalliance(const faction * f)
{
return f.alliance;
return f->alliance;
}
const char *
faction_getlocale(const faction& f)
faction_getlocale(const faction * f)
{
return locale_name(f.locale);
return locale_name(f->locale);
}
void
faction_setlocale(faction& f, const char * name)
faction_setlocale(faction * f, const char * name)
{
f.locale = find_locale(name);
f->locale = find_locale(name);
}
static std::ostream&
@ -108,57 +108,57 @@ operator==(const faction& a, const faction&b)
}
static int
faction_getpolicy(const faction& a, const faction& b, const char * flag)
faction_getpolicy(const faction * a, const faction * b, const char * flag)
{
int mode;
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
if (strcmp(flag, helpmodes[mode].name)==0) {
return get_alliance(&a, &b) & mode;
return get_alliance(a, b) & mode;
}
}
return 0;
}
static void
faction_setpolicy(faction& a, faction& b, const char * flag, bool value)
faction_setpolicy(faction * a, faction * b, const char * flag, bool value)
{
int mode;
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
if (strcmp(flag, helpmodes[mode].name)==0) {
if (value) set_alliance(&a, &b, get_alliance(&a, &b) | helpmodes[mode].status);
else set_alliance(&a, &b, get_alliance(&a, &b) & ~helpmodes[mode].status);
if (value) set_alliance(a, b, get_alliance(a, b) | helpmodes[mode].status);
else set_alliance(a, b, get_alliance(a, b) & ~helpmodes[mode].status);
break;
}
}
}
static const char *
faction_get_variable(faction& f, const char *key)
faction_get_variable(faction * f, const char *key)
{
return get_variable((&f)->attribs, key);
return get_variable(f->attribs, key);
}
static void
faction_set_variable(faction& f, const char *key, const char *value)
faction_set_variable(faction * f, const char *key, const char *value)
{
set_variable(&((&f)->attribs), key, value);
set_variable(&f->attribs, key, value);
}
static void
faction_delete_variable(faction& f, const char *key)
faction_delete_variable(faction * f, const char *key)
{
return delete_variable(&((&f)->attribs), key);
return delete_variable(&f->attribs, key);
}
static int
faction_additem(faction& f, const char * iname, int number)
faction_additem(faction * f, const char * iname, int number)
{
if (iname!=NULL) {
const item_type * itype = it_find(iname);
if (itype!=NULL) {
item * i = i_change(&f.items, itype, number);
item * i = i_change(&f->items, itype, number);
return i?i->number:0;
} // if (itype!=NULL)
}
@ -166,78 +166,78 @@ faction_additem(faction& f, const char * iname, int number)
}
static void
faction_addnotice(faction& f, const char * str)
faction_addnotice(faction * f, const char * str)
{
const char * loc = LOC(f.locale, str);
ADDMSG(&f.msgs, msg_message("msg_event", "string", loc));
const char * loc = LOC(f->locale, str);
ADDMSG(&f->msgs, msg_message("msg_event", "string", loc));
}
static const char *
faction_getrace(const faction& f)
faction_getrace(const faction * f)
{
return f.race->_name[0];
return f->race->_name[0];
}
static void
faction_setrace(faction& f, const char * rcname)
faction_setrace(faction * f, const char * rcname)
{
race * rc = rc_find(rcname);
if (rc!=NULL) {
f.race = rc;
f->race = rc;
}
}
static eressea::list<std::string, item *, eressea::bind_items>
faction_items(const faction& f) {
return eressea::list<std::string, item *, eressea::bind_items>(f.items);
faction_items(const faction * f) {
return eressea::list<std::string, item *, eressea::bind_items>(f->items);
}
void
faction_set_passw(faction& f, const char * passw)
faction_set_passw(faction * f, const char * passw)
{
free(f.passw);
f.passw = strdup(passw);
free(f->passw);
f->passw = strdup(passw);
}
const char *
faction_get_passw(const faction& f)
faction_get_passw(const faction * f)
{
return f.passw;
return f->passw;
}
void
faction_set_banner(faction& f, const char * banner)
faction_set_banner(faction * f, const char * banner)
{
free(f.banner);
f.banner = strdup(banner);
free(f->banner);
f->banner = strdup(banner);
}
const char *
faction_get_banner(const faction& f)
faction_get_banner(const faction * f)
{
if (f.banner) {
return (const char*)f.banner;
if (f->banner) {
return (const char*)f->banner;
}
return "";
}
void
faction_set_email(faction& f, const char * email)
faction_set_email(faction * f, const char * email)
{
free(f.email);
f.email = strdup(email);
free(f->email);
f->email = strdup(email);
}
const char *
faction_get_email(const faction& f)
faction_get_email(const faction * f)
{
return f.email;
return f->email;
}
void
faction_getorigin(const faction& f, int &x, int &y)
faction_getorigin(const faction * f, int &x, int &y)
{
ursprung * origin = f.ursprung;
ursprung * origin = f->ursprung;
while (origin!=NULL && origin->id!=0) {
origin = origin->next;
}
@ -249,49 +249,41 @@ faction_getorigin(const faction& f, int &x, int &y)
y = 0;
}
}
void
faction_setorigin(faction& f, int x, int y)
{
x = 0;
y = 0;
}
short
faction_getorigin_x(const faction& f) {
return f.ursprung->x;
faction_getorigin_x(const faction * f) {
return f->ursprung->x;
}
void
faction_setorigin_x(faction& f, short x) {
f.ursprung->x = x;
faction_setorigin_x(faction * f, short x) {
f->ursprung->x = x;
}
static short
faction_getorigin_y(const faction& f) {
return f.ursprung->y;
faction_getorigin_y(const faction * f) {
return f->ursprung->y;
}
static void
faction_setorigin_y(faction& f, short y) {
f.ursprung->y = y;
faction_setorigin_y(faction * f, short y) {
f->ursprung->y = y;
}
static int
faction_countheroes(const faction& f)
faction_countheroes(const faction * f)
{
return countheroes(&f);
return countheroes(f);
}
static void
faction_renumber(faction& f, int no)
faction_renumber(faction * f, int no)
{
renumber_faction(&f, no);
renumber_faction(f, no);
}
static int
faction_maxheroes(const faction& f)
faction_maxheroes(const faction * f)
{
return maxheroes(&f);
return maxheroes(f);
}
void
@ -304,7 +296,7 @@ bind_faction(lua_State * L)
def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)),
class_<struct faction>("faction")
.def(tostring(self))
.def(tostring(const_self))
.def(self == faction())
.def("set_policy", &faction_setpolicy)
.def("get_policy", &faction_getpolicy)
@ -331,7 +323,6 @@ bind_faction(lua_State * L)
.property("items", &faction_items, return_stl_iterator)
.property("x", &faction_getorigin_x, &faction_setorigin_x)
.property("y", &faction_getorigin_y, &faction_setorigin_y)
//.property("origin", &faction_getorigin, &faction_setorigin, pure_out_value(_2) + pure_out_value(_3), copy)
.def("renum", &faction_renumber)
.def("add_notice", &faction_addnotice)

View file

@ -95,21 +95,21 @@ lua_writereports(void)
}
static void
message_unit(unit& sender, unit& target, const char * str)
message_unit(unit * sender, unit * target, const char * str)
{
deliverMail(target.faction, sender.region, &sender, str, &target);
deliverMail(target->faction, sender->region, sender, str, target);
}
static void
message_faction(unit& sender, faction& target, const char * str)
message_faction(unit * sender, faction * target, const char * str)
{
deliverMail(&target, sender.region, &sender, str, NULL);
deliverMail(target, sender->region, sender, str, NULL);
}
static void
message_region(unit& sender, const char * str)
message_region(unit * sender, const char * str)
{
ADDMSG(&sender.region->msgs, msg_message("mail_result", "unit message", &sender, str));
ADDMSG(&sender->region->msgs, msg_message("mail_result", "unit message", sender, str));
}
static void
@ -181,9 +181,9 @@ process_orders(void)
}
static int
levitate_ship(ship& sh, unit& mage, double power, int duration)
levitate_ship(ship * sh, unit * mage, double power, int duration)
{
curse * c = shipcurse_flyingship(&sh, &mage, power, duration);
curse * c = shipcurse_flyingship(sh, mage, power, duration);
if (c) {
return c->no;
}

View file

@ -72,7 +72,7 @@ public:
return E_OK;
}
int set_unit(const char * param, const unit& u) {
int set_unit(const char * param, const unit * u) {
if (mtype==0) return E_INVALID_MESSAGE;
int i = get_param(param);
@ -83,12 +83,12 @@ public:
return E_INVALID_PARAMETER_TYPE;
}
args[i].v = (void*)&u;
args[i].v = (void*)u;
return E_OK;
}
int set_region(const char * param, const region& r) {
int set_region(const char * param, const region * r) {
if (mtype==0) return E_INVALID_MESSAGE;
int i = get_param(param);
@ -99,7 +99,7 @@ public:
return E_INVALID_PARAMETER_TYPE;
}
args[i].v = (void*)&r;
args[i].v = (void*)r;
return E_OK;
}
@ -138,21 +138,21 @@ public:
return E_OK;
}
int send_faction(faction& f) {
int send_faction(faction * f) {
if (mtype==0) return E_INVALID_MESSAGE;
if (msg==NULL) {
msg = msg_create(mtype, args);
}
add_message(&f.msgs, msg);
add_message(&f->msgs, msg);
return E_OK;
}
int send_region(region& r) {
int send_region(region * r) {
if (mtype==0) return E_INVALID_MESSAGE;
if (msg==NULL) {
msg = msg_create(mtype, args);
}
add_message(&r.msgs, msg);
add_message(&r->msgs, msg);
return E_OK;
}

View file

@ -43,143 +43,143 @@ get_regions(void) {
}
static eressea::list<unit *>
region_units(const region& r) {
return eressea::list<unit *>(r.units);
region_units(const region * r) {
return eressea::list<unit *>(r->units);
}
static eressea::list<building *>
region_buildings(const region& r) {
return eressea::list<building *>(r.buildings);
region_buildings(const region * r) {
return eressea::list<building *>(r->buildings);
}
static eressea::list<ship *>
region_ships(const region& r) {
return eressea::list<ship *>(r.ships);
region_ships(const region * r) {
return eressea::list<ship *>(r->ships);
}
static void
region_setname(region& r, const char * name) {
if (r.land) rsetname((&r), name);
region_setname(region * r, const char * name) {
if (r->land) rsetname(r, name);
}
static const char *
region_getterrain(const region& r) {
return (const char *)r.terrain->_name;
region_getterrain(const region * r) {
return (const char *)r->terrain->_name;
}
static const char *
region_getname(const region& r) {
if (r.land) return (const char *)r.land->name;
region_getname(const region * r) {
if (r->land) return (const char *)r->land->name;
return NULL;
}
static void
lua_region_setowner(region& r, faction * f) {
region_setowner(&r, f);
lua_region_setowner(region * r, faction * f) {
region_setowner(r, f);
}
static faction *
lua_region_getowner(const region& r) {
return region_owner(&r);
lua_region_getowner(const region * r) {
return region_owner(r);
}
static void
region_setherbtype(region& r, const char * str) {
region_setherbtype(region * r, const char * str) {
const struct resource_type * rtype = rt_find(str);
if (rtype!=NULL && rtype->itype!=NULL) {
rsetherbtype(&r, rtype->itype);
rsetherbtype(r, rtype->itype);
}
}
static const char *
region_getherbtype(const region& r) {
const struct item_type * itype = rherbtype(&r);
region_getherbtype(const region * r) {
const struct item_type * itype = rherbtype(r);
if (itype==NULL) return NULL;
return itype->rtype->_name[0];
}
static void
region_setinfo(region& r, const char * info)
region_setinfo(region * r, const char * info)
{
free(r.display);
r.display = strdup(info);
free(r->display);
r->display = strdup(info);
}
static const char *
region_getinfo(const region& r) {
return (const char *)r.display;
region_getinfo(const region * r) {
return (const char *)r->display;
}
static int
region_plane(const region& r)
region_plane(const region * r)
{
if (r.planep==NULL) return 0;
return r.planep->id;
if (r->planep==NULL) return 0;
return r->planep->id;
}
static void
region_addnotice(region& r, const char * str)
region_addnotice(region * r, const char * str)
{
addmessage(&r, NULL, str, MSG_MESSAGE, ML_IMPORTANT);
addmessage(r, NULL, str, MSG_MESSAGE, ML_IMPORTANT);
}
static std::ostream&
operator<<(std::ostream& stream, const region& r)
{
stream << regionname(&r, NULL) << ", " << region_getterrain(r);
stream << regionname(&r, NULL) << ", " << (const char *)r.terrain->_name;
return stream;
}
static bool
operator==(const region& a, const region&b)
operator==(const region& a, const region& b)
{
return a.x==b.x && a.y==b.y;
}
static bool
region_getflag(const region& r, int bit)
region_getflag(const region * r, int bit)
{
if (r.flags & (1<<bit)) return true;
if (r->flags & (1<<bit)) return true;
return false;
}
static void
region_setflag(region& r, int bit, bool set)
region_setflag(region * r, int bit, bool set)
{
if (set) r.flags |= (1<<bit);
else r.flags &= ~(1<<bit);
if (set) r->flags |= (1<<bit);
else r->flags &= ~(1<<bit);
}
static int
region_getresource(const region& r, const char * type)
region_getresource(const region * r, const char * type)
{
const resource_type * rtype = rt_find(type);
if (rtype!=NULL) {
const rawmaterial * rm;
for (rm=r.resources;rm;rm=rm->next) {
for (rm=r->resources;rm;rm=rm->next) {
if (rm->type->rtype==rtype) {
return rm->amount;
}
}
if (rtype==rt_find("money")) return rmoney(&r);
if (rtype==rt_find("horse")) return rhorses(&r);
if (rtype==rt_find("peasant")) return rpeasants(&r);
if (rtype==rt_find("money")) return rmoney(r);
if (rtype==rt_find("horse")) return rhorses(r);
if (rtype==rt_find("peasant")) return rpeasants(r);
} else {
if (strcmp(type, "seed")==0) return rtrees(&r, 0);
if (strcmp(type, "sapling")==0) return rtrees(&r, 1);
if (strcmp(type, "tree")==0) return rtrees(&r, 2);
if (strcmp(type, "grave")==0) return deathcount(&r);
if (strcmp(type, "chaos")==0) return chaoscount(&r);
if (strcmp(type, "seed")==0) return rtrees(r, 0);
if (strcmp(type, "sapling")==0) return rtrees(r, 1);
if (strcmp(type, "tree")==0) return rtrees(r, 2);
if (strcmp(type, "grave")==0) return deathcount(r);
if (strcmp(type, "chaos")==0) return chaoscount(r);
}
return 0;
}
static void
region_setresource(region& r, const char * type, int value)
region_setresource(region * r, const char * type, int value)
{
const resource_type * rtype = rt_find(type);
if (rtype!=NULL) {
rawmaterial * rm = r.resources;
rawmaterial * rm = r->resources;
while (rm) {
if (rm->type->rtype==rtype) {
rm->amount = value;
@ -188,41 +188,41 @@ region_setresource(region& r, const char * type, int value)
rm=rm->next;
}
if (!rm) {
if (rtype==rt_find("money")) rsetmoney(&r, value);
else if (rtype==rt_find("peasant")) rsetpeasants(&r, value);
else if (rtype==rt_find("horse")) rsethorses(&r, value);
if (rtype==rt_find("money")) rsetmoney(r, value);
else if (rtype==rt_find("peasant")) rsetpeasants(r, value);
else if (rtype==rt_find("horse")) rsethorses(r, value);
}
} else {
if (strcmp(type, "seed")==0) {
rsettrees(&r, 0, value);
rsettrees(r, 0, value);
} else if (strcmp(type, "sapling")==0) {
rsettrees(&r, 1, value);
rsettrees(r, 1, value);
} else if (strcmp(type, "tree")==0) {
rsettrees(&r, 2, value);
rsettrees(r, 2, value);
} else if (strcmp(type, "grave")==0) {
int fallen = value-deathcount(&r);
deathcounts(&r, fallen);
int fallen = value-deathcount(r);
deathcounts(r, fallen);
} else if (strcmp(type, "chaos")==0) {
int fallen = value-chaoscount(&r);
chaoscounts(&r, fallen);
int fallen = value-chaoscount(r);
chaoscounts(r, fallen);
}
}
}
static void
region_setroad(region& r, int dir, lua_Number size)
region_setroad(region * r, int dir, lua_Number size)
{
if (r.terrain->max_road>0) {
rsetroad(&r, (direction_t)dir, (short)(r.terrain->max_road * size));
if (r->terrain->max_road>0) {
rsetroad(r, (direction_t)dir, (short)(r->terrain->max_road * size));
}
}
static lua_Number
region_getroad(region& r, int dir)
region_getroad(region * r, int dir)
{
lua_Number result = rroad(&r, (direction_t)dir);
if (r.terrain->max_road<=0 || result<=0) return 0;
return r.terrain->max_road / result;
lua_Number result = rroad(r, (direction_t)dir);
if (r->terrain->max_road<=0 || result<=0) return 0;
return r->terrain->max_road / result;
}
static region *
@ -247,24 +247,24 @@ region_terraform(short x, short y, const char * tname)
}
static region *
region_next(const region& r, int dir)
region_next(const region * r, int dir)
{
if (dir<0 || dir >=MAXDIRECTIONS) return NULL;
return r_connect(&r, (direction_t)dir);
return r_connect(r, (direction_t)dir);
}
static void
region_adddirection(region& r, region &rt, const char * name, const char * info)
region_adddirection(region * r, region * rt, const char * name, const char * info)
{
create_special_direction(&r, &rt, -1, info, name);
spec_direction * sd = special_direction(&r, &rt);
create_special_direction(r, rt, -1, info, name);
spec_direction * sd = special_direction(r, rt);
sd->active = 1;
}
static void
region_remove(region& r)
region_remove(region * r)
{
remove_region(&regions, &r);
remove_region(&regions, r);
}
static void
@ -282,7 +282,7 @@ plane_remove(int plane_id)
}
void
region_move(region& r, short x, short y)
region_move(region * r, short x, short y)
{
if (findregion(x,y)) {
log_error(("Bei %d, %d gibt es schon eine Region.\n", x, y));
@ -291,41 +291,41 @@ region_move(region& r, short x, short y)
#ifdef FAST_CONNECT
direction_t dir;
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
region * rn = r.connect[dir];
region * rn = r->connect[dir];
if (rn!=NULL) {
direction_t reldir = reldirection(rn, &r);
direction_t reldir = reldirection(rn, r);
rn->connect[reldir] = NULL;
}
rn = findregion(x+delta_x[dir], y+delta_y[dir]);
if (rn!=NULL) {
direction_t reldir = (direction_t)((dir + 3) % MAXDIRECTIONS);
rn->connect[reldir] = &r;
rn->connect[reldir] = r;
}
r.connect[dir] = rn;
r->connect[dir] = rn;
}
#endif
runhash(&r);
r.x = x;
r.y = y;
rhash(&r);
runhash(r);
r->x = x;
r->y = y;
rhash(r);
}
static eressea::list<std::string, item *, eressea::bind_items>
region_items(const region& r) {
if (r.land) {
return eressea::list<std::string, item *, eressea::bind_items>(r.land->items);
region_items(const region * r) {
if (r->land) {
return eressea::list<std::string, item *, eressea::bind_items>(r->land->items);
} else {
return eressea::list<std::string, item *, eressea::bind_items>(NULL);
}
}
static int
region_additem(region& r, const char * iname, int number)
region_additem(region * r, const char * iname, int number)
{
if (iname!=NULL) {
const item_type * itype = it_find(iname);
if (itype!=NULL && r.land) {
item * i = i_change(&r.land->items, itype, number);
if (itype!=NULL && r->land) {
item * i = i_change(&r->land->items, itype, number);
return i?i->number:0;
} // if (itype!=NULL)
}
@ -333,22 +333,22 @@ region_additem(region& r, const char * iname, int number)
}
static bool
region_getkey(region& r, const char * name)
region_getkey(region * r, const char * name)
{
int flag = atoi36(name);
attrib * a = find_key(r.attribs, flag);
attrib * a = find_key(r->attribs, flag);
return (a!=NULL);
}
static void
region_setkey(region& r, const char * name, bool value)
region_setkey(region * r, const char * name, bool value)
{
int flag = atoi36(name);
attrib * a = find_key(r.attribs, flag);
attrib * a = find_key(r->attribs, flag);
if (a==NULL && value) {
add_key(&r.attribs, flag);
add_key(&r->attribs, flag);
} else if (a!=NULL && !value) {
a_remove(&r.attribs, a);
a_remove(&r->attribs, a);
}
}

View file

@ -274,10 +274,10 @@ lua_maintenance(const unit * u)
}
static void
unit_setscript(struct unit& u, const luabind::object& f)
unit_setscript(struct unit * u, const luabind::object& f)
{
luabind::object * fptr = new luabind::object(f);
setscript(&u.attribs, fptr);
setscript(&u->attribs, fptr);
}
static void

View file

@ -45,46 +45,46 @@ operator==(const ship& a, const ship& sh)
}
static ship *
add_ship(region& r, const char * sname)
add_ship(region * r, const char * sname)
{
const ship_type * stype = st_find(sname);
ship * sh = new_ship(stype, NULL, &r);
ship * sh = new_ship(stype, NULL, r);
sh->size = stype->construction->maxsize;
return sh;
}
static int
ship_maxsize(const ship& s) {
return s.type->construction->maxsize;
ship_maxsize(const ship * s) {
return s->type->construction->maxsize;
}
const char *
ship_gettype(const ship& s) {
return s.type->name[0];
ship_gettype(const ship * s) {
return s->type->name[0];
}
int
ship_getweight(const ship& s) {
ship_getweight(const ship * s) {
int w, c;
getshipweight(&s, &w, &c);
getshipweight(s, &w, &c);
return w;
}
int
ship_getcapacity(const ship& s) {
return shipcapacity(&s);
ship_getcapacity(const ship * s) {
return shipcapacity(s);
}
static void
ship_setregion(ship& sh, region& r)
ship_setregion(ship * sh, region * r)
{
move_ship(&sh, sh.region, &r, NULL);
move_ship(sh, sh->region, r, NULL);
}
static region *
ship_getregion(const ship& sh)
ship_getregion(const ship * sh)
{
return sh.region;
return sh->region;
}
void

View file

@ -57,8 +57,8 @@ public:
};
static eressea::list<spell *, spell_list *, bind_spell_ptr>
unit_spells(const unit& u) {
sc_mage * mage = get_mage(&u);
unit_spells(const unit * u) {
sc_mage * mage = get_mage(u);
if (mage==NULL) return eressea::list<spell *, spell_list *, bind_spell_ptr>(NULL);
spell_list * splist = mage->spells;
return eressea::list<spell *, spell_list *, bind_spell_ptr>(splist);
@ -82,13 +82,13 @@ public:
};
static eressea::list<std::string, order *, bind_orders>
unit_orders(const unit& u) {
return eressea::list<std::string, order *, bind_orders>(u.orders);
unit_orders(const unit * u) {
return eressea::list<std::string, order *, bind_orders>(u->orders);
}
static eressea::list<std::string, item *, eressea::bind_items>
unit_items(const unit& u) {
return eressea::list<std::string, item *, eressea::bind_items>(u.items);
unit_items(const unit * u) {
return eressea::list<std::string, item *, eressea::bind_items>(u->items);
}
static unit *
@ -99,84 +99,84 @@ add_unit(faction * f, region * r)
}
static void
unit_setnumber(unit& u, int number)
unit_setnumber(unit * u, int number)
{
if (u.number==0) {
set_number(&u, number);
u.hp = unit_max_hp(&u) * number;
if (u->number==0) {
set_number(u, number);
u->hp = unit_max_hp(u) * number;
} else {
scale_number(&u, number);
scale_number(u, number);
}
}
static void
unit_setracename(unit& u, const char * name)
unit_setracename(unit * u, const char * name)
{
set_racename(&u.attribs, name);
set_racename(&u->attribs, name);
}
static int
unit_getnumber(const unit& u)
unit_getnumber(const unit * u)
{
return u.number;
return u->number;
}
static int
unit_getitem(const unit& u, const char * iname)
unit_getitem(const unit * u, const char * iname)
{
if (iname!=NULL) {
const item_type * itype = it_find(iname);
if (itype!=NULL) {
return i_get(u.items, itype);
return i_get(u->items, itype);
}
}
return -1;
}
static int
unit_additem(unit& u, const char * iname, int number)
unit_additem(unit * u, const char * iname, int number)
{
if (iname!=NULL) {
const item_type * itype = it_find(iname);
if (itype!=NULL) {
item * i = i_change(&u.items, itype, number);
item * i = i_change(&u->items, itype, number);
return i?i->number:0;
} // if (itype!=NULL)
}
const item_type * itype = it_find(iname);
if (itype!=NULL) {
item * i = i_change(&u.items, itype, number);
item * i = i_change(&u->items, itype, number);
return i?i->number:0;
}
return -1;
}
static int
unit_usepooled(unit& u, const char * iname, int number)
unit_usepooled(unit * u, const char * iname, int number)
{
const resource_type * rtype = rt_find(iname);
if (rtype!=NULL) {
return use_pooled(&u, rtype, GET_DEFAULT, number);
return use_pooled(u, rtype, GET_DEFAULT, number);
}
return -1;
}
static int
unit_getpooled(unit& u, const char * iname)
unit_getpooled(unit * u, const char * iname)
{
const resource_type * rtype = rt_find(iname);
if (rtype!=NULL) {
return get_pooled(&u, rtype, GET_DEFAULT, INT_MAX);
return get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
}
return -1;
}
static int
unit_getskill(const unit& u, const char * skname)
unit_getskill(const unit * u, const char * skname)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
skill * sv = get_skill(&u, sk);
skill * sv = get_skill(u, sk);
if (sv==NULL) return 0;
return sv->level;
}
@ -184,44 +184,44 @@ unit_getskill(const unit& u, const char * skname)
}
static int
unit_effskill(const unit& u, const char * skname)
unit_effskill(const unit * u, const char * skname)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
return effskill(&u, sk);
return effskill(u, sk);
}
return -1;
}
static int
unit_setskill(unit& u, const char * skname, int level)
unit_setskill(unit * u, const char * skname, int level)
{
skill_t sk = sk_find(skname);
if (sk!=NOSKILL) {
set_level(&u, sk, level);
set_level(u, sk, level);
return level;
} // if (sk!=NULL)
return -1;
}
static const char *
unit_getrace(const unit& u)
unit_getrace(const unit * u)
{
return u.race->_name[0];
return u->race->_name[0];
}
static void
unit_setrace(unit& u, const char * rcname)
unit_setrace(unit * u, const char * rcname)
{
race * rc = rc_find(rcname);
if (rc!=NULL) {
if (u.irace==u.race) u.irace = rc;
u.race = rc;
if (u->irace==u->race) u->irace = rc;
u->race = rc;
}
}
static void
unit_castspell(unit& u, const char * name)
unit_castspell(unit * u, const char * name)
{
spell_list * slist = spells;
while (slist!=NULL) {
@ -232,10 +232,10 @@ unit_castspell(unit& u, const char * name)
co->familiar = NULL;
co->force = sp->level;
co->level = sp->level;
co->magician.u = &u;
co->magician.u = u;
co->order = NULL;
co->par = NULL;
co->rt = u.region;
co->rt = u->region;
co->sp = sp;
if (sp->sp_function==NULL) {
log_error(("spell '%s' has no function.\n", sp->sname));
@ -250,14 +250,14 @@ unit_castspell(unit& u, const char * name)
}
static void
unit_addspell(unit& u, const char * name)
unit_addspell(unit * u, const char * name)
{
bool add = false;
spell_list * slist = spells;
while (slist!=NULL) {
spell * sp = slist->data;
if (strcmp(name, sp->sname)==0) {
struct sc_mage * mage = get_mage(&u);
struct sc_mage * mage = get_mage(u);
if (add) log_error(("two spells are called %s.\n", name));
add_spell(mage, sp);
add = true;
@ -268,9 +268,9 @@ unit_addspell(unit& u, const char * name)
}
static unit *
unit_isfamiliar(const unit& u)
unit_isfamiliar(const unit * u)
{
attrib * a = a_find(u.attribs, &at_familiarmage);
attrib * a = a_find(u->attribs, &at_familiarmage);
if (a!=NULL) {
return (unit*)a->data.v;
}
@ -278,9 +278,9 @@ unit_isfamiliar(const unit& u)
}
static unit *
unit_getfamiliar(const unit& u)
unit_getfamiliar(const unit * u)
{
attrib * a = a_find(u.attribs, &at_familiar);
attrib * a = a_find(u->attribs, &at_familiar);
if (a!=NULL) {
return (unit*)a->data.v;
}
@ -288,15 +288,15 @@ unit_getfamiliar(const unit& u)
}
static void
unit_setfamiliar(unit& mage, unit& familiar)
unit_setfamiliar(unit * mage, unit * familiar)
{
create_newfamiliar(&mage, &familiar);
create_newfamiliar(mage, familiar);
}
static void
unit_removespell(unit& u, const spell * sp)
unit_removespell(unit * u, const spell * sp)
{
sc_mage * mage = get_mage(&u);
sc_mage * mage = get_mage(u);
if (mage!=NULL) {
spell_list ** isptr = &mage->spells;
while (*isptr && (*isptr)->data != sp) {
@ -311,9 +311,9 @@ unit_removespell(unit& u, const spell * sp)
}
static int
unit_hpmax(const unit& u)
unit_hpmax(const unit * u)
{
return unit_max_hp(&u);
return unit_max_hp(u);
}
static void
@ -323,25 +323,25 @@ unit_setregion(unit * u, region * r)
}
static region *
unit_getregion(const unit& u)
unit_getregion(const unit * u)
{
return u.region;
return u->region;
}
static void
unit_setship(unit& u, const ship& s)
unit_setship(unit * u, ship * s)
{
leave(u.region, &u);
if (u.region!=s.region) {
move_unit(&u, s.region, NULL);
leave(u->region, u);
if (u->region!=s->region) {
move_unit(u, s->region, NULL);
}
u.ship = findship(s.no);
u->ship = s;
}
static ship *
unit_getship(const unit& u)
unit_getship(const unit * u)
{
return u.ship;
return u->ship;
}
static void
@ -351,76 +351,75 @@ unit_setbuilding(unit * u, building * b)
if (u->region!=b->region) {
move_unit(u, b->region, NULL);
}
assert(b==findbuilding(b->no));
u->building = b;
}
static building *
unit_getbuilding(const unit& u)
unit_getbuilding(const unit * u)
{
return u.building;
return u->building;
}
static int
unit_getid(const unit& u)
unit_getid(const unit * u)
{
return u.no;
return u->no;
}
static void
unit_setid(unit& u, int id)
unit_setid(unit * u, int id)
{
unit * nu = findunit(id);
if (nu==NULL) {
uunhash(&u);
u.no = id;
uhash(&u);
uunhash(u);
u->no = id;
uhash(u);
}
}
static const char *
unit_getname(const unit& u)
unit_getname(const unit * u)
{
return (const char *)u.name;
return (const char *)u->name;
}
static void
unit_setname(unit& u, const char * name)
unit_setname(unit * u, const char * name)
{
free(u.name);
u.name = strdup(name);
free(u->name);
u->name = strdup(name);
}
static const char *
unit_getinfo(const unit& u)
unit_getinfo(const unit * u)
{
return (const char *)u.display;
return (const char *)u->display;
}
static void
unit_setinfo(unit& u, const char * info)
unit_setinfo(unit * u, const char * info)
{
free(u.display);
u.display = strdup(info);
free(u->display);
u->display = strdup(info);
}
static bool
get_flag(const unit& u, const char * name)
get_flag(const unit * u, const char * name)
{
int flag = atoi36(name);
attrib * a = find_key(u.attribs, flag);
attrib * a = find_key(u->attribs, flag);
return (a!=NULL);
}
static void
set_flag(unit& u, const char * name, bool value)
set_flag(unit * u, const char * name, bool value)
{
int flag = atoi36(name);
attrib * a = find_key(u.attribs, flag);
attrib * a = find_key(u->attribs, flag);
if (a==NULL && value) {
add_key(&u.attribs, flag);
add_key(&u->attribs, flag);
} else if (a!=NULL && !value) {
a_remove(&u.attribs, a);
a_remove(&u->attribs, a);
}
}
@ -434,74 +433,74 @@ operator<<(std::ostream& stream, const unit& u)
}
static bool
operator==(const unit& a, const unit&b)
operator==(const unit& a, const unit &b)
{
return a.no==b.no;
}
static int
unit_getaura(const unit& u)
unit_getaura(const unit * u)
{
return get_spellpoints(&u);
return get_spellpoints(u);
}
static void
unit_setaura(unit& u, int points)
unit_setaura(unit * u, int points)
{
return set_spellpoints(&u, points);
return set_spellpoints(u, points);
}
static faction *
unit_getfaction(const unit& u)
unit_getfaction(const unit * u)
{
return u.faction;
return u->faction;
}
static void
unit_setfaction(unit& u, faction& f)
unit_setfaction(unit * u, faction * f)
{
u_setfaction(&u, &f);
u_setfaction(u, f);
}
static const char *
unit_getmagic(const unit& u)
unit_getmagic(const unit * u)
{
sc_mage * mage = get_mage(&u);
sc_mage * mage = get_mage(u);
return mage?magietypen[mage->magietyp]:NULL;
}
static void
unit_setmagic(unit& u, const char * type)
unit_setmagic(unit * u, const char * type)
{
sc_mage * mage = get_mage(&u);
sc_mage * mage = get_mage(u);
magic_t mtype;
for (mtype=0;mtype!=MAXMAGIETYP;++mtype) {
if (strcmp(magietypen[mtype], type)==0) break;
}
if (mtype==MAXMAGIETYP) return;
if (mage==NULL) {
mage = create_mage(&u, mtype);
mage = create_mage(u, mtype);
}
}
static void
unit_addorder(unit& u, const char * str)
unit_addorder(unit * u, const char * str)
{
order * ord = parse_order(str, u.faction->locale);
addlist(&u.orders, ord);
u.faction->lastorders = turn;
order * ord = parse_order(str, u->faction->locale);
addlist(&u->orders, ord);
u->faction->lastorders = turn;
}
static void
unit_clearorders(unit& u)
unit_clearorders(unit * u)
{
free_orders(&u.orders);
free_orders(&u->orders);
}
static int
unit_weight(const struct unit& u)
unit_weight(const struct unit * u)
{
return weight(&u);
return weight(u);
}
typedef struct fctr_data {
@ -552,32 +551,32 @@ static struct trigger_type tt_functor = {
};
static trigger *
trigger_functor(struct unit& u, const object& f)
trigger_functor(struct unit * u, const object& f)
{
luabind::object * fptr = new luabind::object(f);
trigger * t = t_new(&tt_functor);
fctr_data * td = (fctr_data*)t->data.v;
td->target = &u;
td->target = u;
td->fptr = fptr;
return t;
}
static void
unit_addhandler(struct unit& u, const char * event, const object& f)
unit_addhandler(struct unit * u, const char * event, const object& f)
{
add_trigger(&u.attribs, event, trigger_functor(u, f));
add_trigger(&u->attribs, event, trigger_functor(u, f));
}
static int
unit_capacity(const struct unit& u)
unit_capacity(const struct unit * u)
{
return walkingcapacity(&u);
return walkingcapacity(u);
}
static void
unit_addnotice(unit& u, const char * str)
unit_addnotice(unit * u, const char * str)
{
addmessage(u.region, u.faction, str, MSG_MESSAGE, ML_IMPORTANT);
addmessage(u->region, u->faction, str, MSG_MESSAGE, ML_IMPORTANT);
}
void