forked from github/server
reduce dependence on platform.h.
gradually stop using MAX and MIN (mistakes were made).
This commit is contained in:
parent
3c16267246
commit
5b1d27542a
53 changed files with 288 additions and 220 deletions
|
@ -28,7 +28,7 @@ IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
|||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
|
||||
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89")
|
||||
ELSEIF(MSVC)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG
|
||||
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE
|
||||
|
|
|
@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/log.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
|
@ -69,7 +70,7 @@ static int dict_read(attrib * a, void *owner, gamedata *data)
|
|||
int n;
|
||||
|
||||
READ_STR(store, name, sizeof(name));
|
||||
dd->name = strdup(name);
|
||||
dd->name = str_strdup(name);
|
||||
READ_INT(store, &n);
|
||||
dd->type = (dict_type)n;
|
||||
if (dd->type == TINTEGER) {
|
||||
|
@ -170,7 +171,7 @@ attrib_type at_dict = {
|
|||
void dict_set(attrib * a, const char * name, int value)
|
||||
{
|
||||
dict_data *dd = (dict_data *)a->data.v;
|
||||
dd->name = strdup(name);
|
||||
dd->name = str_strdup(name);
|
||||
dd->type = TINTEGER;
|
||||
dd->data.i = value;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "racename.h"
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <stdlib.h>
|
||||
|
@ -43,7 +44,7 @@ void set_racename(attrib ** palist, const char *name)
|
|||
attrib *a = a_find(*palist, &at_racename);
|
||||
if (!a && name) {
|
||||
a = a_add(palist, a_new(&at_racename));
|
||||
a->data.v = strdup(name);
|
||||
a->data.v = str_strdup(name);
|
||||
}
|
||||
else if (a && !name) {
|
||||
a_remove(palist, a);
|
||||
|
@ -51,7 +52,7 @@ void set_racename(attrib ** palist, const char *name)
|
|||
else if (a) {
|
||||
if (strcmp(a->data.v, name) != 0) {
|
||||
free(a->data.v);
|
||||
a->data.v = strdup(name);
|
||||
a->data.v = str_strdup(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "raceprefix.h"
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
@ -41,7 +42,7 @@ void set_prefix(attrib ** ap, const char *str)
|
|||
free(a->data.v);
|
||||
}
|
||||
assert(a->type == &at_raceprefix);
|
||||
a->data.v = strdup(str);
|
||||
a->data.v = str_strdup(str);
|
||||
}
|
||||
|
||||
const char *get_prefix(attrib * a)
|
||||
|
@ -53,7 +54,7 @@ const char *get_prefix(attrib * a)
|
|||
str = (char *)a->data.v;
|
||||
/* conversion of old prefixes */
|
||||
if (strncmp(str, "prefix_", 7) == 0) {
|
||||
((attrib *)a)->data.v = strdup(str + 7);
|
||||
((attrib *)a)->data.v = str_strdup(str + 7);
|
||||
free(str);
|
||||
str = (char *)a->data.v;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <util/log.h>
|
||||
#include <util/language.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <tolua.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -84,7 +85,7 @@ static int tolua_building_set_info(lua_State * L)
|
|||
const char *info = tolua_tostring(L, 2, 0);
|
||||
free(self->display);
|
||||
if (info)
|
||||
self->display = strdup(info);
|
||||
self->display = str_strdup(info);
|
||||
else
|
||||
self->display = NULL;
|
||||
return 0;
|
||||
|
|
|
@ -39,6 +39,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <critbit.h>
|
||||
|
||||
|
@ -635,7 +636,7 @@ static int tolua_plane_set_name(lua_State * L)
|
|||
const char *str = tolua_tostring(L, 2, 0);
|
||||
free(self->name);
|
||||
if (str)
|
||||
self->name = strdup(str);
|
||||
self->name = str_strdup(str);
|
||||
else
|
||||
self->name = 0;
|
||||
return 0;
|
||||
|
|
|
@ -25,6 +25,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <tolua.h>
|
||||
#include <string.h>
|
||||
|
@ -109,7 +110,7 @@ static int tolua_ship_set_display(lua_State * L)
|
|||
{
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, NULL);
|
||||
free(self->display);
|
||||
self->display = strdup(tolua_tostring(L, 2, NULL));
|
||||
self->display = str_strdup(tolua_tostring(L, 2, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ static const char *translate(const char *key, const char *value)
|
|||
}
|
||||
else
|
||||
t = malloc(sizeof(translation));
|
||||
t->key = strdup(key);
|
||||
t->key = str_strdup(key);
|
||||
t->value = value;
|
||||
t->next = translation_table[kk];
|
||||
translation_table[kk] = t;
|
||||
|
|
|
@ -31,6 +31,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <util/language.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
|
||||
#include <selist.h>
|
||||
|
@ -83,7 +84,7 @@ alliance *new_alliance(int id, const char *name) {
|
|||
al = calloc(1, sizeof(alliance));
|
||||
al->id = id;
|
||||
if (name) {
|
||||
al->name = strdup(name);
|
||||
al->name = str_strdup(name);
|
||||
}
|
||||
else {
|
||||
al->flags |= ALF_NON_ALLIED;
|
||||
|
@ -434,7 +435,7 @@ void alliance_setname(alliance * self, const char *name)
|
|||
{
|
||||
free(self->name);
|
||||
if (name)
|
||||
self->name = strdup(name);
|
||||
self->name = str_strdup(name);
|
||||
else
|
||||
self->name = NULL;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "plane.h"
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/gamedata.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -103,7 +104,7 @@ int AllianceAuto(void)
|
|||
const char *str = config_get("alliance.auto");
|
||||
value = 0;
|
||||
if (str != NULL) {
|
||||
char *sstr = strdup(str);
|
||||
char *sstr = str_strdup(str);
|
||||
char *tok = strtok(sstr, " ");
|
||||
while (tok) {
|
||||
value |= ally_flag(tok, -1);
|
||||
|
@ -163,7 +164,7 @@ int HelpMask(void)
|
|||
if (config_changed(&config)) {
|
||||
const char *str = config_get("rules.help.mask");
|
||||
if (str != NULL) {
|
||||
char *sstr = strdup(str);
|
||||
char *sstr = str_strdup(str);
|
||||
char *tok = strtok(sstr, " ");
|
||||
while (tok) {
|
||||
rule |= ally_flag(tok, -1);
|
||||
|
@ -183,7 +184,7 @@ static int AllianceRestricted(void)
|
|||
const char *str = config_get("alliance.restricted");
|
||||
int rule = 0;
|
||||
if (str != NULL) {
|
||||
char *sstr = strdup(str);
|
||||
char *sstr = str_strdup(str);
|
||||
char *tok = strtok(sstr, " ");
|
||||
while (tok) {
|
||||
rule |= ally_flag(tok, -1);
|
||||
|
|
|
@ -44,6 +44,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -134,7 +135,7 @@ building_type *bt_get_or_create(const char *name)
|
|||
building_type *btype = bt_find_i(name);
|
||||
if (btype == NULL) {
|
||||
btype = calloc(sizeof(building_type), 1);
|
||||
btype->_name = strdup(name);
|
||||
btype->_name = str_strdup(name);
|
||||
btype->auraregen = 1.0;
|
||||
btype->maxsize = -1;
|
||||
btype->capacity = 1;
|
||||
|
@ -373,7 +374,7 @@ building *new_building(const struct building_type * btype, region * r,
|
|||
}
|
||||
assert(bname);
|
||||
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
|
||||
b->name = strdup(bname);
|
||||
b->name = str_strdup(bname);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -569,7 +570,7 @@ void building_setname(building * self, const char *name)
|
|||
{
|
||||
free(self->name);
|
||||
if (name)
|
||||
self->name = strdup(name);
|
||||
self->name = str_strdup(name);
|
||||
else
|
||||
self->name = NULL;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/language.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
@ -564,7 +565,7 @@ static void test_buildingtype(CuTest *tc) {
|
|||
btype = test_create_buildingtype("hodor");
|
||||
CuAssertPtrNotNull(tc, btype->construction);
|
||||
CuAssertStrEquals(tc, "hodor", buildingtype(btype, NULL, 1));
|
||||
btype->construction->name = strdup("castle");
|
||||
btype->construction->name = str_strdup("castle");
|
||||
CuAssertStrEquals(tc, "castle", buildingtype(btype, NULL, 1));
|
||||
btype = bt_get_or_create("portal");
|
||||
CuAssertPtrEquals(tc, NULL, btype->construction);
|
||||
|
|
|
@ -65,6 +65,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/translation.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/xml.h>
|
||||
|
@ -381,7 +382,7 @@ static void init_magic(struct locale *lang)
|
|||
str = "gwyrrd illaun draig cerddor tybied";
|
||||
}
|
||||
|
||||
sstr = strdup(str);
|
||||
sstr = str_strdup(str);
|
||||
tok = strtok(sstr, " ");
|
||||
while (tok) {
|
||||
variant var;
|
||||
|
@ -488,7 +489,7 @@ int check_param(const struct param *p, const char *key, const char *searchvalue)
|
|||
if (!value) {
|
||||
return 0;
|
||||
}
|
||||
p_value = strdup(value);
|
||||
p_value = str_strdup(value);
|
||||
v = strtok(p_value, " ,;");
|
||||
|
||||
while (v != NULL) {
|
||||
|
|
|
@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
|
@ -43,7 +44,7 @@ void equipment_setskill(equipment * eq, skill_t sk, const char *value)
|
|||
{
|
||||
if (eq != NULL) {
|
||||
if (value != NULL) {
|
||||
eq->skills[sk] = strdup(value);
|
||||
eq->skills[sk] = str_strdup(value);
|
||||
}
|
||||
else if (eq->skills[sk]) {
|
||||
free(eq->skills[sk]);
|
||||
|
@ -78,7 +79,7 @@ equipment_setitem(equipment * eq, const item_type * itype, const char *value)
|
|||
if (idata == NULL) {
|
||||
idata = (itemdata *)malloc(sizeof(itemdata));
|
||||
idata->itype = itype;
|
||||
idata->value = strdup(value);
|
||||
idata->value = str_strdup(value);
|
||||
idata->next = eq->items;
|
||||
eq->items = idata;
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ faction *addfaction(const char *email, const char *password,
|
|||
fhash(f);
|
||||
|
||||
slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
|
||||
f->name = strdup(buf);
|
||||
f->name = str_strdup(buf);
|
||||
|
||||
if (!f->race) {
|
||||
log_warning("creating a faction that has no race", itoa36(f->no));
|
||||
|
@ -597,7 +597,7 @@ void faction_setname(faction * self, const char *name)
|
|||
{
|
||||
free(self->name);
|
||||
if (name)
|
||||
self->name = strdup(name);
|
||||
self->name = str_strdup(name);
|
||||
}
|
||||
|
||||
const char *faction_getemail(const faction * self)
|
||||
|
@ -609,7 +609,7 @@ void faction_setemail(faction * self, const char *email)
|
|||
{
|
||||
free(self->email);
|
||||
if (email)
|
||||
self->email = strdup(email);
|
||||
self->email = str_strdup(email);
|
||||
else
|
||||
self->email = NULL;
|
||||
}
|
||||
|
@ -623,14 +623,14 @@ void faction_setbanner(faction * self, const char *banner)
|
|||
{
|
||||
free(self->banner);
|
||||
if (banner)
|
||||
self->banner = strdup(banner);
|
||||
self->banner = str_strdup(banner);
|
||||
}
|
||||
|
||||
void faction_setpassword(faction * f, const char *pwhash)
|
||||
{
|
||||
assert(pwhash);
|
||||
free(f->_password);
|
||||
f->_password = strdup(pwhash);
|
||||
f->_password = str_strdup(pwhash);
|
||||
}
|
||||
|
||||
bool valid_race(const struct faction *f, const struct race *rc)
|
||||
|
|
|
@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/base36.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -59,7 +60,7 @@ group *new_group(faction * f, const char *name, int gid)
|
|||
*gp = g;
|
||||
|
||||
maxgid = MAX(gid, maxgid);
|
||||
g->name = strdup(name);
|
||||
g->name = str_strdup(name);
|
||||
g->gid = gid;
|
||||
|
||||
g->nexthash = ghash[index];
|
||||
|
|
|
@ -43,6 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
|
||||
#include <critbit.h>
|
||||
|
@ -196,7 +197,7 @@ resource_type *rt_get_or_create(const char *name) {
|
|||
perror("resource_type allocation failed");
|
||||
}
|
||||
else {
|
||||
rtype->_name = strdup(name);
|
||||
rtype->_name = str_strdup(name);
|
||||
rt_register(rtype);
|
||||
}
|
||||
}
|
||||
|
@ -279,8 +280,8 @@ weapon_type *new_weapontype(item_type * itype,
|
|||
|
||||
wtype = calloc(sizeof(weapon_type), 1);
|
||||
if (damage) {
|
||||
wtype->damage[0] = strdup(damage[0]);
|
||||
wtype->damage[1] = strdup(damage[1]);
|
||||
wtype->damage[0] = str_strdup(damage[0]);
|
||||
wtype->damage[1] = str_strdup(damage[1]);
|
||||
}
|
||||
wtype->defmod = defmod;
|
||||
wtype->flags |= wflags;
|
||||
|
@ -339,9 +340,9 @@ void it_set_appearance(item_type *itype, const char *appearance) {
|
|||
assert(itype->rtype);
|
||||
if (appearance) {
|
||||
char plural[32];
|
||||
itype->_appearance[0] = strdup(appearance);
|
||||
itype->_appearance[0] = str_strdup(appearance);
|
||||
snprintf(plural, sizeof(plural), "%s_p", appearance);
|
||||
itype->_appearance[1] = strdup(plural);
|
||||
itype->_appearance[1] = str_strdup(plural);
|
||||
} else {
|
||||
itype->_appearance[0] = 0;
|
||||
itype->_appearance[1] = 0;
|
||||
|
|
|
@ -45,6 +45,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/xml.h>
|
||||
|
||||
/* external libraries */
|
||||
|
@ -228,7 +229,7 @@ static void json_terrain_production(cJSON *json, terrain_production *prod) {
|
|||
if (dst) {
|
||||
free(*dst);
|
||||
assert(child->type == cJSON_String);
|
||||
*dst = strdup(child->valuestring);
|
||||
*dst = str_strdup(child->valuestring);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +453,7 @@ static void json_race(cJSON *json, race *rc) {
|
|||
switch (child->type) {
|
||||
case cJSON_String:
|
||||
if (strcmp(child->string, "damage") == 0) {
|
||||
rc->def_damage = strdup(child->valuestring);
|
||||
rc->def_damage = str_strdup(child->valuestring);
|
||||
}
|
||||
break;
|
||||
case cJSON_Number:
|
||||
|
@ -592,7 +593,7 @@ static void json_spells(cJSON *json) {
|
|||
continue;
|
||||
}
|
||||
else if (strcmp(item->string, "syntax") == 0) {
|
||||
sp->syntax = strdup(item->valuestring);
|
||||
sp->syntax = str_strdup(item->valuestring);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -703,7 +704,7 @@ static void json_calendar(cJSON *json) {
|
|||
weeknames = malloc(sizeof(char *) * weeks_per_month);
|
||||
for (i = 0, entry = child->child; entry; entry = entry->next, ++i) {
|
||||
if (entry->type == cJSON_String) {
|
||||
weeknames[i] = strdup(entry->valuestring);
|
||||
weeknames[i] = str_strdup(entry->valuestring);
|
||||
}
|
||||
else {
|
||||
log_error("calendar.weeks[%d] is not a string: %d", i, json->type);
|
||||
|
|
|
@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/lists.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -234,7 +235,7 @@ plane *create_new_plane(int id, const char *name, int minx, int maxx, int miny,
|
|||
pl->next = NULL;
|
||||
pl->id = id;
|
||||
if (name)
|
||||
pl->name = strdup(name);
|
||||
pl->name = str_strdup(name);
|
||||
pl->minx = minx;
|
||||
pl->maxx = maxx;
|
||||
pl->miny = miny;
|
||||
|
|
|
@ -44,6 +44,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -132,7 +133,7 @@ static void rc_setoption(race *rc, int k, const char *value) {
|
|||
v->v = rc_get_or_create(value);
|
||||
}
|
||||
else if (key == RCO_HUNGER) {
|
||||
v->v = strdup(value);
|
||||
v->v = str_strdup(value);
|
||||
}
|
||||
else if (key == RCO_TRADEHERB) {
|
||||
v->i = atoi(value);
|
||||
|
@ -359,7 +360,7 @@ race *rc_create(const char *zName)
|
|||
log_error("race '%s' has an invalid name. remove spaces\n", zName);
|
||||
assert(strchr(zName, ' ') == NULL);
|
||||
}
|
||||
rc->_name = strdup(zName);
|
||||
rc->_name = str_strdup(zName);
|
||||
|
||||
rc->attack[0].type = AT_COMBATSPELL;
|
||||
for (i = 1; i < RACE_ATTACKS; ++i)
|
||||
|
|
|
@ -52,6 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/language.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
|
@ -1419,7 +1420,7 @@ void region_setinfo(struct region *r, const char *info)
|
|||
{
|
||||
assert(r->land);
|
||||
free(r->land->display);
|
||||
r->land->display = (info && info[0]) ? strdup(info) : 0;
|
||||
r->land->display = (info && info[0]) ? str_strdup(info) : 0;
|
||||
}
|
||||
|
||||
const char *region_getinfo(const region * r)
|
||||
|
@ -1431,7 +1432,7 @@ void region_setname(struct region *r, const char *name)
|
|||
{
|
||||
if (r->land) {
|
||||
free(r->land->name);
|
||||
r->land->name = name ? strdup(name) : 0;
|
||||
r->land->name = name ? str_strdup(name) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/rand.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
|
@ -157,7 +158,7 @@ void read_planes(gamedata *data) {
|
|||
}
|
||||
pl->id = id;
|
||||
READ_STR(store, name, sizeof(name));
|
||||
pl->name = strdup(name);
|
||||
pl->name = str_strdup(name);
|
||||
READ_INT(store, &pl->minx);
|
||||
READ_INT(store, &pl->maxx);
|
||||
READ_INT(store, &pl->miny);
|
||||
|
@ -421,12 +422,12 @@ unit *read_unit(gamedata *data)
|
|||
if (unicode_utf8_trim(obuf)!=0) {
|
||||
log_warning("trim unit %s name to '%s'", itoa36(u->no), obuf);
|
||||
}
|
||||
u->_name = obuf[0] ? strdup(obuf) : 0;
|
||||
u->_name = obuf[0] ? str_strdup(obuf) : 0;
|
||||
READ_STR(data->store, obuf, sizeof(obuf));
|
||||
if (unicode_utf8_trim(obuf)!=0) {
|
||||
log_warning("trim unit %s info to '%s'", itoa36(u->no), obuf);
|
||||
}
|
||||
u->display = obuf[0] ? strdup(obuf) : 0;
|
||||
u->display = obuf[0] ? str_strdup(obuf) : 0;
|
||||
READ_INT(data->store, &number);
|
||||
set_number(u, number);
|
||||
|
||||
|
@ -648,7 +649,7 @@ static region *readregion(gamedata *data, int x, int y)
|
|||
if (unicode_utf8_trim(name) != 0) {
|
||||
log_warning("trim region %d name to '%s'", uid, name);
|
||||
};
|
||||
r->land->name = strdup(name);
|
||||
r->land->name = str_strdup(name);
|
||||
}
|
||||
if (r->land) {
|
||||
int i;
|
||||
|
@ -888,7 +889,7 @@ static char * getpasswd(int fno) {
|
|||
assert(line[slen] == '\n');
|
||||
line[slen] = 0;
|
||||
fclose(F);
|
||||
return strdup(line + len + 1);
|
||||
return str_strdup(line + len + 1);
|
||||
}
|
||||
}
|
||||
fclose(F);
|
||||
|
@ -980,12 +981,12 @@ faction *read_faction(gamedata * data)
|
|||
if (unicode_utf8_trim(name)!=0) {
|
||||
log_warning("trim faction %s name to '%s'", itoa36(f->no), name);
|
||||
};
|
||||
f->name = strdup(name);
|
||||
f->name = str_strdup(name);
|
||||
READ_STR(data->store, name, sizeof(name));
|
||||
if (unicode_utf8_trim(name)!=0) {
|
||||
log_warning("trim faction %s banner to '%s'", itoa36(f->no), name);
|
||||
};
|
||||
f->banner = strdup(name);
|
||||
f->banner = str_strdup(name);
|
||||
|
||||
log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no));
|
||||
|
||||
|
@ -1210,12 +1211,12 @@ struct building *read_building(gamedata *data) {
|
|||
if (unicode_utf8_trim(name)!=0) {
|
||||
log_warning("trim building %s name to '%s'", itoa36(b->no), name);
|
||||
}
|
||||
b->name = strdup(name);
|
||||
b->name = str_strdup(name);
|
||||
READ_STR(store, name, sizeof(name));
|
||||
if (unicode_utf8_trim(name)!=0) {
|
||||
log_warning("trim building %s info to '%s'", itoa36(b->no), name);
|
||||
}
|
||||
b->display = strdup(name);
|
||||
b->display = str_strdup(name);
|
||||
READ_INT(store, &b->size);
|
||||
READ_STR(store, name, sizeof(name));
|
||||
b->type = bt_find(name);
|
||||
|
@ -1264,12 +1265,12 @@ ship *read_ship(gamedata *data)
|
|||
if (unicode_utf8_trim(name)!=0) {
|
||||
log_warning("trim ship %s name to '%s'", itoa36(sh->no), name);
|
||||
}
|
||||
sh->name = strdup(name);
|
||||
sh->name = str_strdup(name);
|
||||
READ_STR(store, name, sizeof(name));
|
||||
if (unicode_utf8_trim(name)!=0) {
|
||||
log_warning("trim ship %s info to '%s'", itoa36(sh->no), name);
|
||||
}
|
||||
sh->display = strdup(name);
|
||||
sh->display = str_strdup(name);
|
||||
READ_STR(store, name, sizeof(name));
|
||||
sh->type = st_find(name);
|
||||
if (sh->type == NULL) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/race.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
#include "save.h"
|
||||
|
@ -20,9 +18,11 @@
|
|||
#include <triggers/createunit.h>
|
||||
#include <triggers/timeout.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/event.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/password.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <storage.h>
|
||||
#include <memstream.h>
|
||||
|
@ -100,7 +100,7 @@ static void test_readwrite_faction(CuTest * tc)
|
|||
test_setup();
|
||||
f = test_create_faction(0);
|
||||
free(f->name);
|
||||
f->name = strdup(" Hodor ");
|
||||
f->name = str_strdup(" Hodor ");
|
||||
CuAssertStrEquals(tc, " Hodor ", f->name);
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
|
@ -130,7 +130,7 @@ static void test_readwrite_region(CuTest * tc)
|
|||
test_setup();
|
||||
r = test_create_region(0, 0, 0);
|
||||
free(r->land->name);
|
||||
r->land->name = strdup(" Hodor ");
|
||||
r->land->name = str_strdup(" Hodor ");
|
||||
CuAssertStrEquals(tc, " Hodor ", r->land->name);
|
||||
region_setinfo(r, lipsum);
|
||||
CuAssertStrEquals(tc, lipsum, r->land->display);
|
||||
|
@ -163,7 +163,7 @@ static void test_readwrite_building(CuTest * tc)
|
|||
r = test_create_region(0, 0, 0);
|
||||
b = test_create_building(r, 0);
|
||||
free(b->name);
|
||||
b->name = strdup(" Hodor ");
|
||||
b->name = str_strdup(" Hodor ");
|
||||
CuAssertStrEquals(tc, " Hodor ", b->name);
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
|
@ -196,7 +196,7 @@ static void test_readwrite_ship(CuTest * tc)
|
|||
r = test_create_region(0, 0, 0);
|
||||
sh = test_create_ship(r, 0);
|
||||
free(sh->name);
|
||||
sh->name = strdup(" Hodor ");
|
||||
sh->name = str_strdup(" Hodor ");
|
||||
CuAssertStrEquals(tc, " Hodor ", sh->name);
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
|
|
|
@ -40,6 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/xml.h>
|
||||
|
||||
|
@ -124,7 +125,7 @@ ship_type *st_get_or_create(const char * name) {
|
|||
assert(!snames);
|
||||
if (!st) {
|
||||
st = (ship_type *)calloc(sizeof(ship_type), 1);
|
||||
st->_name = strdup(name);
|
||||
st->_name = str_strdup(name);
|
||||
st->storm = 1.0;
|
||||
st_register(st);
|
||||
}
|
||||
|
@ -217,7 +218,7 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
|
|||
}
|
||||
assert(sname);
|
||||
snprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no));
|
||||
sh->name = strdup(buffer);
|
||||
sh->name = str_strdup(buffer);
|
||||
shash(sh);
|
||||
if (r) {
|
||||
addlist(&r->ships, sh);
|
||||
|
@ -491,7 +492,7 @@ void write_ship_reference(const struct ship *sh, struct storage *store)
|
|||
void ship_setname(ship * self, const char *name)
|
||||
{
|
||||
free(self->name);
|
||||
self->name = name ? strdup(name) : 0;
|
||||
self->name = name ? str_strdup(name) : 0;
|
||||
}
|
||||
|
||||
const char *ship_getname(const ship * self)
|
||||
|
|
|
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/strings.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <selist.h>
|
||||
|
||||
|
@ -124,7 +125,7 @@ spell * create_spell(const char * name)
|
|||
sp = (spell *)calloc(1, sizeof(spell));
|
||||
len = cb_new_kv(name, len, &sp, sizeof(sp), buffer);
|
||||
if (cb_insert(&cb_spells, buffer, len) == CB_SUCCESS) {
|
||||
sp->sname = strdup(name);
|
||||
sp->sname = str_strdup(name);
|
||||
add_spell(&spells, sp);
|
||||
return sp;
|
||||
}
|
||||
|
@ -173,10 +174,10 @@ struct spellref *spellref_create(spell *sp, const char *name)
|
|||
|
||||
if (sp) {
|
||||
spref->sp = sp;
|
||||
spref->name = strdup(sp->sname);
|
||||
spref->name = str_strdup(sp->sname);
|
||||
}
|
||||
else if (name) {
|
||||
spref->name = strdup(name);
|
||||
spref->name = str_strdup(name);
|
||||
spref->sp = NULL;
|
||||
}
|
||||
return spref;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <selist.h>
|
||||
|
||||
#include <util/log.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include "spellbook.h"
|
||||
|
||||
#include <selist.h>
|
||||
#include <storage.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -16,7 +17,7 @@
|
|||
spellbook * create_spellbook(const char * name)
|
||||
{
|
||||
spellbook *result = (spellbook *)malloc(sizeof(spellbook));
|
||||
result->name = name ? strdup(name) : 0;
|
||||
result->name = name ? str_strdup(name) : 0;
|
||||
result->spells = 0;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <util/log.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
|
@ -123,7 +124,7 @@ terrain_type * get_or_create_terrain(const char *name) {
|
|||
++terrain_changes;
|
||||
terrain = (terrain_type *)calloc(sizeof(terrain_type), 1);
|
||||
if (terrain) {
|
||||
terrain->_name = strdup(name);
|
||||
terrain->_name = str_strdup(name);
|
||||
terrain->next = registered_terrains;
|
||||
registered_terrains = terrain;
|
||||
if (strcmp("plain", name) == 0) {
|
||||
|
|
|
@ -61,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/rand.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
@ -509,7 +510,7 @@ int a_readprivate(attrib * a, void *owner, gamedata *data)
|
|||
struct storage *store = data->store;
|
||||
char lbuf[DISPLAYSIZE];
|
||||
READ_STR(store, lbuf, sizeof(lbuf));
|
||||
a->data.v = strdup(lbuf);
|
||||
a->data.v = str_strdup(lbuf);
|
||||
return (a->data.v) ? AT_READ_OK : AT_READ_FAIL;
|
||||
}
|
||||
|
||||
|
@ -567,7 +568,7 @@ void usetprivate(unit * u, const char *str)
|
|||
if (a->data.v) {
|
||||
free(a->data.v);
|
||||
}
|
||||
a->data.v = strdup(str);
|
||||
a->data.v = str_strdup(str);
|
||||
}
|
||||
|
||||
/*********************/
|
||||
|
@ -1512,7 +1513,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
|
|||
}
|
||||
|
||||
if (dname) {
|
||||
u->_name = strdup(dname);
|
||||
u->_name = str_strdup(dname);
|
||||
}
|
||||
else if (urace->name_unit || playerrace(urace)) {
|
||||
name_unit(u);
|
||||
|
@ -1615,7 +1616,7 @@ void unit_setname(unit * u, const char *name)
|
|||
{
|
||||
free(u->_name);
|
||||
if (name && name[0])
|
||||
u->_name = strdup(name);
|
||||
u->_name = str_strdup(name);
|
||||
else
|
||||
u->_name = NULL;
|
||||
}
|
||||
|
@ -1629,7 +1630,7 @@ void unit_setinfo(unit * u, const char *info)
|
|||
{
|
||||
free(u->display);
|
||||
if (info)
|
||||
u->display = strdup(info);
|
||||
u->display = str_strdup(info);
|
||||
else
|
||||
u->display = NULL;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <spells/regioncurse.h>
|
||||
#include <alchemy.h>
|
||||
#include <laws.h>
|
||||
|
@ -397,7 +398,7 @@ static void test_unit_description(CuTest *tc) {
|
|||
|
||||
CuAssertPtrEquals(tc, 0, u->display);
|
||||
CuAssertStrEquals(tc, 0, u_description(u, lang));
|
||||
u->display = strdup("Hodor");
|
||||
u->display = str_strdup("Hodor");
|
||||
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
|
||||
CuAssertStrEquals(tc, "Hodor", u_description(u, lang));
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/xml.h>
|
||||
|
||||
/* libxml includes */
|
||||
|
@ -248,7 +249,7 @@ construction ** consPtr, construct_t type)
|
|||
if (type == CONS_BUILDING) {
|
||||
propValue = xmlGetProp(node, BAD_CAST "name");
|
||||
if (propValue != NULL) {
|
||||
con->name = strdup((const char *)propValue);
|
||||
con->name = str_strdup((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
}
|
||||
|
@ -573,7 +574,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
|||
xmlFree(propValue);
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "value");
|
||||
wtype->damage[pos] = strdup((const char *)propValue); /* TODO: this is a memory leak */
|
||||
wtype->damage[pos] = str_strdup((const char *)propValue); /* TODO: this is a memory leak */
|
||||
if (k == 0)
|
||||
wtype->damage[1 - pos] = wtype->damage[pos];
|
||||
xmlFree(propValue);
|
||||
|
@ -1200,13 +1201,13 @@ static int parse_spells(xmlDocPtr doc)
|
|||
|
||||
propValue = xmlGetProp(node, BAD_CAST "parameters");
|
||||
if (propValue) {
|
||||
sp->parameter = strdup((const char *)propValue);
|
||||
sp->parameter = str_strdup((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "syntax");
|
||||
if (propValue) {
|
||||
sp->syntax = strdup((const char *)propValue);
|
||||
sp->syntax = str_strdup((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
#ifdef TODO /* no longer need it, spellbooks! */
|
||||
|
@ -1355,7 +1356,7 @@ static int parse_races(xmlDocPtr doc)
|
|||
|
||||
propValue = xmlGetProp(node, BAD_CAST "damage");
|
||||
assert(propValue != NULL);
|
||||
rc->def_damage = strdup((const char *)propValue);
|
||||
rc->def_damage = str_strdup((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
|
||||
rc->magres = frac_make(xml_ivalue(node, "magres", 100), 100);
|
||||
|
@ -1550,7 +1551,7 @@ static int parse_races(xmlDocPtr doc)
|
|||
|
||||
propValue = xmlGetProp(node, BAD_CAST "damage");
|
||||
if (propValue != NULL) {
|
||||
attack->data.dice = strdup((const char *)propValue);
|
||||
attack->data.dice = str_strdup((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
else {
|
||||
|
@ -1613,7 +1614,7 @@ static int parse_messages(xmlDocPtr doc)
|
|||
(const char *)propType);
|
||||
xmlFree(propName);
|
||||
xmlFree(propType);
|
||||
argv[k] = strdup(zBuffer);
|
||||
argv[k] = str_strdup(zBuffer);
|
||||
}
|
||||
argv[result->nodesetval->nodeNr] = NULL;
|
||||
}
|
||||
|
|
|
@ -1586,7 +1586,7 @@ int display_cmd(unit * u, struct order *ord)
|
|||
|
||||
free(*s);
|
||||
if (s2) {
|
||||
char * str = strdup(s2);
|
||||
char * str = str_strdup(s2);
|
||||
if (unicode_utf8_trim(str) != 0) {
|
||||
log_info("trimming info: %s", s2);
|
||||
}
|
||||
|
@ -1636,7 +1636,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2)
|
|||
}
|
||||
|
||||
free(*s);
|
||||
*s = strdup(name);
|
||||
*s = str_strdup(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2119,7 +2119,7 @@ int banner_cmd(unit * u, struct order *ord)
|
|||
free(u->faction->banner);
|
||||
init_order_depr(ord);
|
||||
s = getstrtoken();
|
||||
u->faction->banner = s ? strdup(s) : 0;
|
||||
u->faction->banner = s ? str_strdup(s) : 0;
|
||||
add_message(&u->faction->msgs, msg_message("changebanner", "value",
|
||||
u->faction->banner));
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "gmtool_structs.h"
|
||||
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -27,7 +28,7 @@ insert_selection(list_selection ** p_sel, list_selection * prev,
|
|||
const char *str, void *payload)
|
||||
{
|
||||
list_selection *sel = calloc(sizeof(list_selection), 1);
|
||||
sel->str = strdup(str);
|
||||
sel->str = str_strdup(str);
|
||||
sel->data = payload;
|
||||
if (*p_sel) {
|
||||
list_selection *s;
|
||||
|
|
182
src/magic.c
182
src/magic.c
|
@ -17,7 +17,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "magic.h"
|
||||
|
||||
|
@ -61,19 +60,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
#include <selist.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
|
||||
#include <selist.h>
|
||||
#include <critbit.h>
|
||||
#include <storage.h>
|
||||
|
||||
|
@ -126,7 +126,7 @@ static double MagicPower(double force)
|
|||
if (force > 0) {
|
||||
const char *str = config_get("magic.power");
|
||||
double value = str ? atof(str) : 1.0;
|
||||
return MAX(value * force, 1.0f);
|
||||
return fmax(value * force, 1.0f);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -141,6 +141,8 @@ static int a_readicastle(attrib * a, void *owner, struct gamedata *data)
|
|||
storage *store = data->store;
|
||||
icastle_data *idata = (icastle_data *)a->data.v;
|
||||
char token[32];
|
||||
|
||||
(void)owner;
|
||||
READ_TOK(store, token, sizeof(token));
|
||||
if (data->version < ATTRIBOWNER_VERSION) {
|
||||
READ_INT(store, NULL);
|
||||
|
@ -154,7 +156,7 @@ static void
|
|||
a_writeicastle(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
icastle_data *data = (icastle_data *)a->data.v;
|
||||
UNUSED_ARG(owner);
|
||||
(void)owner;
|
||||
WRITE_TOK(store, data->type->_name);
|
||||
WRITE_INT(store, data->time);
|
||||
}
|
||||
|
@ -213,7 +215,7 @@ extern int dice(int count, int value);
|
|||
/* ------------------------------------------------------------- */
|
||||
/* aus dem alten System übriggebliegene Funktionen, die bei der
|
||||
* Umwandlung von alt nach neu gebraucht werden */
|
||||
/* ------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
static void init_mage(attrib * a)
|
||||
{
|
||||
|
@ -254,6 +256,7 @@ static int read_mage(attrib * a, void *owner, struct gamedata *data)
|
|||
sc_mage *mage = (sc_mage *)a->data.v;
|
||||
char spname[64];
|
||||
|
||||
(void)owner;
|
||||
READ_INT(store, &mtype);
|
||||
mage->magietyp = (magic_t)mtype;
|
||||
READ_INT(store, &mage->spellpoints);
|
||||
|
@ -299,6 +302,7 @@ write_mage(const attrib * a, const void *owner, struct storage *store)
|
|||
int i;
|
||||
sc_mage *mage = (sc_mage *)a->data.v;
|
||||
|
||||
(void)owner;
|
||||
WRITE_INT(store, mage->magietyp);
|
||||
WRITE_INT(store, mage->spellpoints);
|
||||
WRITE_INT(store, mage->spchange);
|
||||
|
@ -360,6 +364,7 @@ static int read_seenspell(attrib * a, void *owner, struct gamedata *data)
|
|||
spell *sp = 0;
|
||||
char token[32];
|
||||
|
||||
(void)owner;
|
||||
READ_TOK(store, token, sizeof(token));
|
||||
if (data->version < UNIQUE_SPELLS_VERSION) {
|
||||
READ_INT(store, 0); /* ignore mtype */
|
||||
|
@ -377,6 +382,7 @@ static void
|
|||
write_seenspell(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
const spell *sp = (const spell *)a->data.v;
|
||||
(void)owner;
|
||||
WRITE_TOK(store, sp->sname);
|
||||
}
|
||||
|
||||
|
@ -448,7 +454,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
|
|||
int maxspell = numspells;
|
||||
int spellno = -1;
|
||||
spellbook_entry *sbe = 0;
|
||||
while (!sbe && maxspell>0) {
|
||||
while (!sbe && maxspell > 0) {
|
||||
spellno = rng_int() % maxspell;
|
||||
sbe = commonspells[spellno];
|
||||
if (sbe->level > f->max_spelllevel) {
|
||||
|
@ -519,7 +525,10 @@ int get_combatspelllevel(const unit * u, int nr)
|
|||
assert(nr < MAXCOMBATSPELLS);
|
||||
if (m) {
|
||||
int level = effskill(u, SK_MAGIC, 0);
|
||||
return MIN(m->combatspells[nr].level, level);
|
||||
if (level < m->combatspells[nr].level) {
|
||||
return level;
|
||||
}
|
||||
return m->combatspells[nr].level;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -651,9 +660,13 @@ int change_spellpoints(unit * u, int mp)
|
|||
}
|
||||
|
||||
/* verhindere negative Magiepunkte */
|
||||
sp = MAX(m->spellpoints + mp, 0);
|
||||
m->spellpoints = sp;
|
||||
|
||||
sp = m->spellpoints + mp;
|
||||
if (sp > 0) {
|
||||
m->spellpoints = sp;
|
||||
}
|
||||
else {
|
||||
m->spellpoints = 0;
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
||||
|
@ -678,10 +691,10 @@ static int get_spchange(const unit * u)
|
|||
* entstehen
|
||||
*/
|
||||
|
||||
/* Artefakt der Stärke
|
||||
* Ermöglicht dem Magier mehr Magiepunkte zu 'speichern'
|
||||
*/
|
||||
/** TODO: at_skillmod daraus machen */
|
||||
/* Artefakt der Stärke
|
||||
* Ermöglicht dem Magier mehr Magiepunkte zu 'speichern'
|
||||
*/
|
||||
/** TODO: at_skillmod daraus machen */
|
||||
static int use_item_aura(const region * r, const unit * u)
|
||||
{
|
||||
int sk, n;
|
||||
|
@ -711,7 +724,7 @@ int max_spellpoints(const region * r, const unit * u)
|
|||
if (n > 0) {
|
||||
msp = (msp * n) / 100;
|
||||
}
|
||||
return MAX((int)msp, 0);
|
||||
return (msp > 0) ? (int)msp : 0;
|
||||
}
|
||||
|
||||
int change_maxspellpoints(unit * u, int csp)
|
||||
|
@ -745,9 +758,7 @@ int countspells(unit * u, int step)
|
|||
|
||||
count = m->spellcount + step;
|
||||
|
||||
/* negative Werte abfangen. */
|
||||
m->spellcount = MAX(0, count);
|
||||
|
||||
m->spellcount = (count > 0) ? count : 0;
|
||||
return m->spellcount;
|
||||
}
|
||||
|
||||
|
@ -827,7 +838,7 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
|
|||
}
|
||||
maxlevel =
|
||||
get_pooled(u, sp->components[k].type, GET_DEFAULT,
|
||||
needplevel * cast_level) / needplevel;
|
||||
needplevel * cast_level) / needplevel;
|
||||
|
||||
/* sind die Kosten fix, so muss die Komponente nur einmal vorhanden
|
||||
* sein und der cast_level ändert sich nicht */
|
||||
|
@ -839,7 +850,9 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
|
|||
}
|
||||
else if (sp->components[k].cost == SPC_LEVEL) {
|
||||
costtyp = SPC_LEVEL;
|
||||
cast_level = MIN(cast_level, maxlevel);
|
||||
if (maxlevel < cast_level) {
|
||||
cast_level = maxlevel;
|
||||
}
|
||||
/* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden
|
||||
* sein, ansonsten schlägt der Spruch fehl */
|
||||
}
|
||||
|
@ -856,11 +869,13 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
|
|||
spellbook * sb = unit_get_spellbook(u);
|
||||
if (sb) {
|
||||
spellbook_entry * sbe = spellbook_get(sb, sp);
|
||||
if (sbe) {
|
||||
return MIN(cast_level, sbe->level);
|
||||
if (sbe && cast_level > sbe->level) {
|
||||
return sbe->level;
|
||||
}
|
||||
}
|
||||
log_error("spell %s is not in the spellbook for %s\n", sp->sname, unitname(u));
|
||||
else {
|
||||
log_error("spell %s is not in the spellbook for %s\n", sp->sname, unitname(u));
|
||||
}
|
||||
}
|
||||
return cast_level;
|
||||
}
|
||||
|
@ -904,7 +919,7 @@ void pay_spell(unit * u, const spell * sp, int cast_level, int range)
|
|||
*/
|
||||
bool knowsspell(const region * r, const unit * u, const spell * sp)
|
||||
{
|
||||
/* Ist überhaupt ein gültiger Spruch angegeben? */
|
||||
(void)r;
|
||||
assert(sp);
|
||||
/* steht der Spruch in der Spruchliste? */
|
||||
return u_hasspell(u, sp) != 0;
|
||||
|
@ -1073,7 +1088,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
|
|||
}
|
||||
}
|
||||
}
|
||||
return MAX(force, 0);
|
||||
return (force > 0) ? (int)force : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
@ -1120,7 +1135,7 @@ variant magic_resistance(unit * target)
|
|||
bool bad_resist = true;
|
||||
|
||||
if (rc == get_race(RC_HIRNTOETER) && !pl) {
|
||||
prob = frac_mul(prob, frac_make(1, 2));
|
||||
prob = frac_mul(prob, frac_make(1, 2));
|
||||
}
|
||||
assert(target->number > 0);
|
||||
/* Magier haben einen Resistenzbonus vom Magietalent * 5% */
|
||||
|
@ -1146,8 +1161,10 @@ variant magic_resistance(unit * target)
|
|||
/* Auswirkungen von Zaubern auf der Region */
|
||||
a = a_find(target->region->attribs, &at_curse);
|
||||
while (a && a->type == &at_curse) {
|
||||
curse *c = (curse *)a->data.v;
|
||||
unit *mage = c->magician;
|
||||
unit *mage;
|
||||
|
||||
c = (curse *)a->data.v;
|
||||
mage = c->magician;
|
||||
|
||||
if (mage != NULL) {
|
||||
if (good_resist && c->type == &ct_goodmagicresistancezone) {
|
||||
|
@ -1311,7 +1328,8 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade)
|
|||
int fumble_enabled = config_get_int("magic.fumble.enable", 1);
|
||||
sc_mage * mage;
|
||||
|
||||
if (effsk<=0 || !fumble_enabled) {
|
||||
(void)sp;
|
||||
if (effsk <= 0 || !fumble_enabled) {
|
||||
return false;
|
||||
}
|
||||
fumble_chance = (int)((cast_grade * 40.0 / (double)effsk) - 20.0);
|
||||
|
@ -1366,10 +1384,10 @@ static void do_fumble(castorder * co)
|
|||
int level = co->level;
|
||||
int duration;
|
||||
double effect;
|
||||
static const race *rc_toad;
|
||||
static const race *rc_toad;
|
||||
static int rc_cache;
|
||||
fumble_f fun;
|
||||
|
||||
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_message("patzer", "unit region spell", u, r, sp));
|
||||
switch (rng_int() % 10) {
|
||||
|
@ -1413,7 +1431,8 @@ static void do_fumble(castorder * co)
|
|||
|
||||
case 2:
|
||||
/* temporary skill loss */
|
||||
duration = MAX(rng_int() % level / 2, 2);
|
||||
duration = rng_int() % level / 2;
|
||||
if (duration < 2) duration = 2;
|
||||
effect = level / -2.0;
|
||||
c = create_curse(u, &u->attribs, &ct_skillmod, level,
|
||||
duration, effect, 1);
|
||||
|
@ -1519,16 +1538,18 @@ void regenerate_aura(void)
|
|||
* mindestens 1 Aura pro Monat */
|
||||
regen = (int)reg_aura;
|
||||
reg_aura -= regen;
|
||||
if (chance(reg_aura))
|
||||
if (chance(reg_aura)) {
|
||||
++regen;
|
||||
regen = MAX(1, regen);
|
||||
regen = MIN((auramax - aura), regen);
|
||||
}
|
||||
if (regen < 1) regen = 1;
|
||||
if (regen > auramax - aura) regen = auramax - aura;
|
||||
|
||||
aura += regen;
|
||||
ADDMSG(&u->faction->msgs, msg_message("regenaura",
|
||||
"unit region amount", u, r, regen));
|
||||
}
|
||||
set_spellpoints(u, MIN(aura, auramax));
|
||||
if (aura > auramax) aura = auramax;
|
||||
set_spellpoints(u, aura);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1536,7 +1557,7 @@ void regenerate_aura(void)
|
|||
|
||||
static bool
|
||||
verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj,
|
||||
order * ord)
|
||||
order * ord)
|
||||
{
|
||||
ship *sh = findship(spobj->data.i);
|
||||
|
||||
|
@ -1559,7 +1580,7 @@ order * ord)
|
|||
|
||||
static bool
|
||||
verify_building(region * r, unit * mage, const spell * sp, spllprm * spobj,
|
||||
order * ord)
|
||||
order * ord)
|
||||
{
|
||||
building *b = findbuilding(spobj->data.i);
|
||||
|
||||
|
@ -1602,7 +1623,7 @@ message *msg_unitnotfound(const struct unit * mage, struct order * ord,
|
|||
|
||||
static bool
|
||||
verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj,
|
||||
order * ord)
|
||||
order * ord)
|
||||
{
|
||||
unit *u = NULL;
|
||||
switch (spobj->typ) {
|
||||
|
@ -1648,8 +1669,8 @@ order * ord)
|
|||
* Sichtbarkeit. Dabei zählen wir die magieresistenten (resists)
|
||||
* Objekte. Alle anderen werten wir als Erfolge (success) */
|
||||
|
||||
/* gibt bei Misserfolg 0 zurück, bei Magieresistenz zumindeste eines
|
||||
* Objektes 1 und bei Erfolg auf ganzer Linie 2 */
|
||||
/* gibt bei Misserfolg 0 zurück, bei Magieresistenz zumindeste eines
|
||||
* Objektes 1 und bei Erfolg auf ganzer Linie 2 */
|
||||
static void
|
||||
verify_targets(castorder * co, int *invalid, int *resist, int *success)
|
||||
{
|
||||
|
@ -1845,7 +1866,7 @@ static int addparam_string(const char *const param[], spllprm ** spobjp)
|
|||
|
||||
spobj->flag = 0;
|
||||
spobj->typ = SPP_STRING;
|
||||
spobj->data.xs = strdup(param[0]);
|
||||
spobj->data.xs = str_strdup(param[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1884,7 +1905,7 @@ static int addparam_building(const char *const param[], spllprm ** spobjp)
|
|||
|
||||
static int
|
||||
addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
|
||||
order * ord)
|
||||
order * ord)
|
||||
{
|
||||
assert(param[0]);
|
||||
if (param[1] == 0) {
|
||||
|
@ -1920,7 +1941,7 @@ order * ord)
|
|||
|
||||
static int
|
||||
addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u,
|
||||
order * ord)
|
||||
order * ord)
|
||||
{
|
||||
spllprm *spobj;
|
||||
int i = 0;
|
||||
|
@ -2156,6 +2177,7 @@ static void
|
|||
a_write_unit(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
unit *u = (unit *)a->data.v;
|
||||
(void)owner;
|
||||
write_unit_reference(u, store);
|
||||
}
|
||||
|
||||
|
@ -2258,6 +2280,7 @@ void create_newfamiliar(unit * mage, unit * fam)
|
|||
}
|
||||
|
||||
static void * resolve_familiar(int id, void *data) {
|
||||
(void)id;
|
||||
if (data) {
|
||||
unit *familiar = (unit *)data;
|
||||
attrib *a = a_find(familiar->attribs, &at_familiarmage);
|
||||
|
@ -2271,6 +2294,7 @@ static void * resolve_familiar(int id, void *data) {
|
|||
|
||||
static int read_familiar(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
(void)owner;
|
||||
if (read_unit_reference(data, (unit **)&a->data.v, resolve_familiar) <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
@ -2303,7 +2327,7 @@ void create_newclone(unit * mage, unit * clone)
|
|||
/* Wenn der Magier stirbt, wird das in destroy_unit abgefangen.
|
||||
* Kein Trigger, zu kompliziert. */
|
||||
|
||||
/* Wenn der Klon stirbt, dann bekommt der Magier einen Schock */
|
||||
/* Wenn der Klon stirbt, dann bekommt der Magier einen Schock */
|
||||
add_trigger(&clone->attribs, "destroy", trigger_clonedied(mage));
|
||||
}
|
||||
|
||||
|
@ -2337,6 +2361,7 @@ unit *has_clone(unit * mage)
|
|||
}
|
||||
|
||||
static void * resolve_clone(int id, void *data) {
|
||||
(void)id;
|
||||
if (data) {
|
||||
unit *clone = (unit *)data;
|
||||
attrib *a = a_find(clone->attribs, &at_clonemage);
|
||||
|
@ -2350,6 +2375,7 @@ static void * resolve_clone(int id, void *data) {
|
|||
|
||||
static int read_clone(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
(void)owner;
|
||||
if (read_unit_reference(data, (unit **)&a->data.v, resolve_clone) <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
@ -2358,6 +2384,7 @@ static int read_clone(attrib * a, void *owner, struct gamedata *data)
|
|||
|
||||
/* mages */
|
||||
static void * resolve_mage(int id, void *data) {
|
||||
(void)id;
|
||||
if (data) {
|
||||
unit *mage = (unit *)data;
|
||||
attrib *a = a_find(mage->attribs, &at_familiar);
|
||||
|
@ -2371,6 +2398,7 @@ static void * resolve_mage(int id, void *data) {
|
|||
|
||||
static int read_magician(attrib * a, void *owner, struct gamedata *data)
|
||||
{
|
||||
(void)owner;
|
||||
if (read_unit_reference(data, (unit **)&a->data.v, resolve_mage) <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
@ -2381,7 +2409,7 @@ static int age_unit(attrib * a, void *owner)
|
|||
/* if unit is gone or dead, remove the attribute */
|
||||
{
|
||||
unit *u = (unit *)a->data.v;
|
||||
UNUSED_ARG(owner);
|
||||
(void)owner;
|
||||
return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
|
@ -2433,9 +2461,9 @@ unit *get_familiar(const unit * u)
|
|||
{
|
||||
attrib *a = a_find(u->attribs, &at_familiar);
|
||||
if (a != NULL) {
|
||||
unit *u = (unit *)a->data.v;
|
||||
if (u->number > 0)
|
||||
return u;
|
||||
unit *uf = (unit *)a->data.v;
|
||||
if (uf->number > 0)
|
||||
return uf;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2444,9 +2472,9 @@ unit *get_familiar_mage(const unit * u)
|
|||
{
|
||||
attrib *a = a_find(u->attribs, &at_familiarmage);
|
||||
if (a != NULL) {
|
||||
unit *u = (unit *)a->data.v;
|
||||
if (u->number > 0)
|
||||
return u;
|
||||
unit *um = (unit *)a->data.v;
|
||||
if (um->number > 0)
|
||||
return um;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2455,9 +2483,9 @@ unit *get_clone(const unit * u)
|
|||
{
|
||||
attrib *a = a_find(u->attribs, &at_clone);
|
||||
if (a != NULL) {
|
||||
unit *u = (unit *)a->data.v;
|
||||
if (u->number > 0)
|
||||
return u;
|
||||
unit *uc = (unit *)a->data.v;
|
||||
if (uc->number > 0)
|
||||
return uc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2466,14 +2494,14 @@ unit *get_clone_mage(const unit * u)
|
|||
{
|
||||
attrib *a = a_find(u->attribs, &at_clonemage);
|
||||
if (a != NULL) {
|
||||
unit *u = (unit *)a->data.v;
|
||||
if (u->number > 0)
|
||||
return u;
|
||||
unit *um = (unit *)a->data.v;
|
||||
if (um->number > 0)
|
||||
return um;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool is_moving_ship(const region * r, ship * sh)
|
||||
static bool is_moving_ship(ship * sh)
|
||||
{
|
||||
const unit *u = ship_owner(sh);
|
||||
|
||||
|
@ -2485,7 +2513,7 @@ static bool is_moving_ship(const region * r, ship * sh)
|
|||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2507,7 +2535,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
cmistake(u, ord, 224, MSG_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
pl = rplane(r);
|
||||
pl = getplane(r);
|
||||
if (pl && fval(pl, PFL_NOMAGIC)) {
|
||||
cmistake(u, ord, 269, MSG_MAGIC);
|
||||
return 0;
|
||||
|
@ -2520,7 +2548,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
/* für Syntax ' STUFE x REGION y z ' */
|
||||
if (param == P_LEVEL) {
|
||||
int p = getint();
|
||||
level = MIN(p, level);
|
||||
if (level > p) level = p;
|
||||
if (level < 1) {
|
||||
/* Fehler "Das macht wenig Sinn" */
|
||||
syntax_error(u, ord);
|
||||
|
@ -2532,7 +2560,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
if (param == P_REGION) {
|
||||
int t_x = getint();
|
||||
int t_y = getint();
|
||||
plane *pl = getplane(u->region);
|
||||
|
||||
t_x = rel_to_abs(pl, u->faction, t_x, 0);
|
||||
t_y = rel_to_abs(pl, u->faction, t_y, 1);
|
||||
pnormalize(&t_x, &t_y, pl);
|
||||
|
@ -2550,7 +2578,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
* hier nach REGION nochmal auf STUFE prüfen */
|
||||
if (param == P_LEVEL) {
|
||||
int p = getint();
|
||||
level = MIN(p, level);
|
||||
if (level > p) level = p;
|
||||
if (level < 1) {
|
||||
/* Fehler "Das macht wenig Sinn" */
|
||||
syntax_error(u, ord);
|
||||
|
@ -2569,7 +2597,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
/* Vertraute können auch Zauber sprechen, die sie selbst nicht
|
||||
* können. unit_getspell findet aber nur jene Sprüche, die
|
||||
* die Einheit beherrscht. */
|
||||
if (!sp && is_familiar(u)) {
|
||||
if (!sp && is_familiar(u)) {
|
||||
caster = get_familiar_mage(u);
|
||||
if (caster) {
|
||||
familiar = u;
|
||||
|
@ -2619,7 +2647,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
* ONSHIPCAST deklarierte Zauber sprechen */
|
||||
}
|
||||
else if (u->ship) {
|
||||
if (is_moving_ship(r, u->ship)) {
|
||||
if (is_moving_ship(u->ship)) {
|
||||
if (!(sp->sptyp & ONSHIPCAST)) {
|
||||
/* Fehler: "Diesen Spruch kann man nicht auf einem sich
|
||||
* bewegenden Schiff stehend zaubern" */
|
||||
|
@ -2666,12 +2694,14 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
return 0;
|
||||
}
|
||||
if (caster != familiar) { /* Magier zaubert durch Vertrauten */
|
||||
int sk;
|
||||
if (range > 1) { /* Fehler! Versucht zu Farcasten */
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "familiar_farcast",
|
||||
"mage", caster));
|
||||
return 0;
|
||||
}
|
||||
if (distance(caster->region, r) > effskill(caster, SK_MAGIC, 0)) {
|
||||
sk = effskill(caster, SK_MAGIC, 0);
|
||||
if (distance(caster->region, r) > sk) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "familiar_toofar",
|
||||
"mage", caster));
|
||||
return 0;
|
||||
|
@ -2681,7 +2711,8 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
* löschen, zaubern kann er noch */
|
||||
range *= 2;
|
||||
set_order(&caster->thisorder, NULL);
|
||||
level = MIN(level, effskill(caster, SK_MAGIC, 0) / 2);
|
||||
sk /= 2;
|
||||
if (level > sk) level = sk;
|
||||
}
|
||||
}
|
||||
/* Weitere Argumente zusammenbasteln */
|
||||
|
@ -2704,7 +2735,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
break;
|
||||
}
|
||||
}
|
||||
params[p++] = strdup(s);
|
||||
params[p++] = str_strdup(s);
|
||||
}
|
||||
params[p] = 0;
|
||||
args =
|
||||
|
@ -2744,7 +2775,6 @@ void magic(void)
|
|||
{
|
||||
region *r;
|
||||
int rank;
|
||||
castorder *co;
|
||||
spellrank spellranks[MAX_SPELLRANK];
|
||||
const race *rc_insect = get_race(RC_INSECT);
|
||||
|
||||
|
@ -2787,6 +2817,7 @@ void magic(void)
|
|||
* Spruch gezaubert wird) */
|
||||
|
||||
for (rank = 0; rank < MAX_SPELLRANK; rank++) {
|
||||
castorder *co;
|
||||
for (co = spellranks[rank].begin; co; co = co->next) {
|
||||
order *ord = co->order;
|
||||
int invalid, resist, success, cast_level = co->level;
|
||||
|
@ -3000,7 +3031,7 @@ spellbook * get_spellbook(const char * name)
|
|||
const void * match;
|
||||
|
||||
if (len >= SBNAMELEN) {
|
||||
log_error("spellbook name is longer than %d bytes: %s", SBNAMELEN-1, name);
|
||||
log_error("spellbook name is longer than %d bytes: %s", SBNAMELEN - 1, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -3026,6 +3057,9 @@ void free_spellbook(spellbook *sb) {
|
|||
|
||||
static int free_spellbook_cb(const void *match, const void *key, size_t keylen, void *data) {
|
||||
const sb_entry *ent = (const sb_entry *)match;
|
||||
(void)data;
|
||||
(void)keylen;
|
||||
(void)key;
|
||||
free_spellbook(ent->value);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <selist.h>
|
||||
|
@ -476,7 +477,7 @@ static void test_illusioncastle(CuTest *tc)
|
|||
CuAssertPtrEquals(tc, btype, (void *)icastle_type(a));
|
||||
CuAssertPtrEquals(tc, bt_icastle, (void *)b->type);
|
||||
CuAssertStrEquals(tc, "castle", buildingtype(btype, b, b->size));
|
||||
btype->construction->name = strdup("site");
|
||||
btype->construction->name = str_strdup("site");
|
||||
CuAssertStrEquals(tc, "site", buildingtype(btype, b, b->size));
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <util/log.h>
|
||||
#include <selist.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
/* libc includes */
|
||||
|
@ -186,13 +187,13 @@ newfaction *read_newfactions(const char *filename)
|
|||
}
|
||||
nf = calloc(sizeof(newfaction), 1);
|
||||
if (check_email(email) == 0) {
|
||||
nf->email = strdup(email);
|
||||
nf->email = str_strdup(email);
|
||||
} else {
|
||||
log_error("Invalid email address for subscription %s: %s\n", itoa36(subscription), email);
|
||||
free(nf);
|
||||
continue;
|
||||
}
|
||||
nf->password = strdup(password);
|
||||
nf->password = str_strdup(password);
|
||||
nf->race = rc_find(race);
|
||||
nf->subscription = subscription;
|
||||
if (alliances != NULL) {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "piracy.h"
|
||||
|
||||
#include "direction.h"
|
||||
|
@ -68,8 +66,9 @@ static attrib *mk_piracy(const faction * pirate, const faction * target,
|
|||
static bool validate_pirate(unit *u, order *ord) {
|
||||
assert(u);
|
||||
assert(ord);
|
||||
if (fval(u_race(u), RCF_SWIM | RCF_FLY))
|
||||
if (u_race(u)->flags & (RCF_SWIM | RCF_FLY)) {
|
||||
return true;
|
||||
}
|
||||
if (!u->ship) {
|
||||
cmistake(u, ord, 144, MSG_MOVE);
|
||||
return false;
|
||||
|
@ -155,8 +154,8 @@ void piracy_cmd(unit * u)
|
|||
/* TODO this could still result in an illegal movement order (through a wall or whatever)
|
||||
* which will be prevented by move_cmd below */
|
||||
if (rc &&
|
||||
((sh && !fval(rc->terrain, FORBIDDEN_REGION) && can_takeoff(sh, r, rc))
|
||||
|| (canswim(u) && fval(rc->terrain, SWIM_INTO) && fval(rc->terrain, SEA_REGION)))) {
|
||||
((sh && !(rc->terrain->flags & FORBIDDEN_REGION) && can_takeoff(sh, r, rc))
|
||||
|| (canswim(u) && ((rc->terrain->flags & (SWIM_INTO|SEA_REGION)) == (SWIM_INTO | SEA_REGION))))) {
|
||||
|
||||
for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
|
||||
unit *cap = ship_owner(sh2);
|
||||
|
|
|
@ -4,17 +4,11 @@
|
|||
#define _LP64 0 /* fix a warning in pdcurses 3.4 */
|
||||
#endif
|
||||
|
||||
#ifndef UNILIB_H
|
||||
#define UNILIB_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __STDC__
|
||||
#define __STDC__ 1 // equivalent to /Za
|
||||
#endif
|
||||
#define NO_STRDUP
|
||||
#define NO_MKDIR
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _USE_MATH_DEFINES
|
||||
#if _MSC_VER >= 1900
|
||||
#pragma warning(disable: 4710 4820)
|
||||
#pragma warning(disable: 4100) // unreferenced formal parameter
|
||||
|
@ -42,10 +36,6 @@
|
|||
|
||||
#define TOLUA_CAST (char*)
|
||||
|
||||
#ifdef NO_STRDUP
|
||||
char * strdup(const char *s);
|
||||
#endif
|
||||
|
||||
#ifdef NO_MKDIR
|
||||
int mkdir(const char *pathname, int mode);
|
||||
#endif
|
||||
|
@ -54,6 +44,3 @@ int mkdir(const char *pathname, int mode);
|
|||
#define PI_F 3.1415926535897932384626433832795F
|
||||
#define PI_D 3.1415926535897932384626433832795
|
||||
#define PI_L 3.1415926535897932384626433832795L
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "prefix.h"
|
||||
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
|
@ -30,7 +31,7 @@ int add_raceprefix(const char *prefix)
|
|||
race_prefixes = tmp;
|
||||
size *= 2;
|
||||
}
|
||||
race_prefixes[next++] = strdup(prefix);
|
||||
race_prefixes[next++] = str_strdup(prefix);
|
||||
race_prefixes[next] = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -85,8 +85,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include <selist.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <selist.h>
|
||||
#include <filestream.h>
|
||||
#include <stream.h>
|
||||
|
||||
|
@ -936,7 +938,7 @@ void report_region(struct stream *out, const region * r, faction * f)
|
|||
}
|
||||
if (!e) {
|
||||
e = calloc(sizeof(struct edge), 1);
|
||||
e->name = strdup(name);
|
||||
e->name = str_strdup(name);
|
||||
e->transparent = transparent;
|
||||
e->next = edges;
|
||||
edges = e;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/message.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <stream.h>
|
||||
#include <memstream.h>
|
||||
|
@ -223,7 +224,7 @@ static void cleanup_spell_fixture(spell_fixture *spf) {
|
|||
|
||||
static void set_parameter(spell_fixture spell, char *value) {
|
||||
free(spell.sp->parameter);
|
||||
spell.sp->parameter = strdup(value);
|
||||
spell.sp->parameter = str_strdup(value);
|
||||
}
|
||||
|
||||
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
|
||||
|
@ -294,14 +295,14 @@ static void test_write_spell_syntax(CuTest *tc) {
|
|||
|
||||
set_parameter(spell, "bc");
|
||||
free(spell.sp->syntax);
|
||||
spell.sp->syntax = strdup("hodor");
|
||||
spell.sp->syntax = str_strdup("hodor");
|
||||
check_spell_syntax(tc, "bc hodor", &spell, " ZAUBERE \"Testzauber\" <bnr> <Hodor>");
|
||||
free(spell.sp->syntax);
|
||||
spell.sp->syntax = 0;
|
||||
|
||||
set_parameter(spell, "c?");
|
||||
free(spell.sp->syntax);
|
||||
spell.sp->syntax = strdup("hodor");
|
||||
spell.sp->syntax = str_strdup("hodor");
|
||||
check_spell_syntax(tc, "c?", &spell, " ZAUBERE \"Testzauber\" [<Hodor>]");
|
||||
free(spell.sp->syntax);
|
||||
spell.sp->syntax = 0;
|
||||
|
|
|
@ -60,14 +60,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/translation.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/translation.h>
|
||||
#include <stream.h>
|
||||
#include <selist.h>
|
||||
|
||||
|
@ -1667,7 +1668,7 @@ int reports(void)
|
|||
|
||||
static variant var_copy_string(variant x)
|
||||
{
|
||||
x.v = x.v ? strdup((const char *)x.v) : 0;
|
||||
x.v = x.v ? str_strdup((const char *)x.v) : 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <util/log.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
#include <selist.h>
|
||||
#include <sqlite3.h>
|
||||
#include <assert.h>
|
||||
|
@ -41,9 +42,9 @@ read_factions(sqlite3 * db, int game_id) {
|
|||
text = (const char *)sqlite3_column_text(stmt, 1);
|
||||
if (text) dbf->no = atoi36(text);
|
||||
text = (const char *)sqlite3_column_text(stmt, 2);
|
||||
if (text) dbf->name = strdup(text);
|
||||
if (text) dbf->name = str_strdup(text);
|
||||
text = (const char *)sqlite3_column_text(stmt, 3);
|
||||
if (text) dbf->email = strdup(text);
|
||||
if (text) dbf->email = str_strdup(text);
|
||||
selist_push(&result, dbf);
|
||||
res = sqlite3_step(stmt);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
#pragma warning(disable: 4210)
|
||||
|
@ -35,7 +36,7 @@ static void add_suite(CuSuite *(*csuite)(void), const char *name, int argc, char
|
|||
}
|
||||
if (s) {
|
||||
s->next = suites;
|
||||
s->name = strdup(name);
|
||||
s->name = str_strdup(name);
|
||||
s->csuite = csuite();
|
||||
suites = s;
|
||||
}
|
||||
|
|
|
@ -19,10 +19,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include "attrib.h"
|
||||
|
||||
#include "gamedata.h"
|
||||
#include "log.h"
|
||||
#include "storage.h"
|
||||
#include "strings.h"
|
||||
|
||||
#include <util/gamedata.h>
|
||||
#include <critbit.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -129,7 +130,7 @@ int a_readstring(attrib * a, void *owner, struct gamedata *data)
|
|||
len += DISPLAYSIZE - 1;
|
||||
}
|
||||
else {
|
||||
result = strdup(buf);
|
||||
result = str_strdup(buf);
|
||||
}
|
||||
} while (e == ENOMEM);
|
||||
a->data.v = result;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "attrib.h"
|
||||
|
||||
#include <util/gamedata.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <storage.h>
|
||||
#include <memstream.h>
|
||||
|
@ -119,7 +120,7 @@ static void test_attrib_rwstring(CuTest *tc) {
|
|||
attrib a = { 0 };
|
||||
|
||||
test_setup();
|
||||
a.data.v = strdup("Hello World");
|
||||
a.data.v = str_strdup("Hello World");
|
||||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
a_writestring(&a, NULL, &store);
|
||||
|
|
|
@ -23,7 +23,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "attrib.h"
|
||||
#include "gamedata.h"
|
||||
#include "log.h"
|
||||
#include "storage.h"
|
||||
#include "strings.h"
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
|
@ -153,7 +155,7 @@ static int read_handler(attrib * a, void *owner, gamedata *data)
|
|||
handler_info *hi = (handler_info *)a->data.v;
|
||||
|
||||
READ_TOK(store, zText, sizeof(zText));
|
||||
hi->event = strdup(zText);
|
||||
hi->event = str_strdup(zText);
|
||||
read_triggers(data, &hi->triggers);
|
||||
if (hi->triggers != NULL) {
|
||||
return AT_READ_OK;
|
||||
|
@ -200,7 +202,7 @@ void add_trigger(struct attrib **ap, const char *eventname, struct trigger *t)
|
|||
if (a == NULL || a->type != &at_eventhandler) {
|
||||
a = a_add(ap, a_new(&at_eventhandler));
|
||||
td = (handler_info *)a->data.v;
|
||||
td->event = strdup(eventname);
|
||||
td->event = str_strdup(eventname);
|
||||
}
|
||||
tp = &td->triggers;
|
||||
while (*tp)
|
||||
|
|
|
@ -16,7 +16,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
#include "language.h"
|
||||
|
||||
#include "log.h"
|
||||
|
@ -83,7 +82,7 @@ locale *get_or_create_locale(const char *name)
|
|||
*lp = l = (locale *)calloc(sizeof(locale), 1);
|
||||
assert_alloc(l);
|
||||
l->hashkey = hkey;
|
||||
l->name = strdup(name);
|
||||
l->name = str_strdup(name);
|
||||
l->index = nextlocaleindex++;
|
||||
assert(nextlocaleindex <= MAXLOCALES);
|
||||
if (default_locale == NULL) default_locale = l;
|
||||
|
@ -206,15 +205,15 @@ void locale_setstring(locale * lang, const char *key, const char *value)
|
|||
find->nexthash = lang->strings[id];
|
||||
lang->strings[id] = find;
|
||||
find->hashkey = hkey;
|
||||
find->key = strdup(key);
|
||||
find->str = strdup(value);
|
||||
find->key = str_strdup(key);
|
||||
find->str = str_strdup(value);
|
||||
}
|
||||
else {
|
||||
if (strcmp(find->str, value) != 0) {
|
||||
log_warning("multiple translations for key %s\n", key);
|
||||
}
|
||||
free(find->str);
|
||||
find->str = strdup(value);
|
||||
find->str = str_strdup(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
#include "lists.h"
|
||||
|
||||
#include "strings.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -117,7 +118,7 @@ void addstrlist(strlist ** SP, const char *s)
|
|||
{
|
||||
strlist *slist = malloc(sizeof(strlist));
|
||||
slist->next = NULL;
|
||||
slist->s = strdup(s);
|
||||
slist->s = str_strdup(s);
|
||||
addlist(SP, slist);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ message_type *mt_new(const char *name, const char *args[])
|
|||
}
|
||||
mtype = (message_type *)malloc(sizeof(message_type));
|
||||
mtype->key = 0;
|
||||
mtype->name = strdup(name);
|
||||
mtype->name = str_strdup(name);
|
||||
mtype->nparameters = nparameters;
|
||||
if (nparameters > 0) {
|
||||
mtype->pnames = (char **)malloc(sizeof(char *) * nparameters);
|
||||
|
|
|
@ -91,7 +91,7 @@ const nrsection *section_add(const char *name)
|
|||
}
|
||||
if (!*mcp) {
|
||||
nrsection *mc = calloc(sizeof(nrsection), 1);
|
||||
mc->name = strdup(name);
|
||||
mc->name = str_strdup(name);
|
||||
*mcp = mc;
|
||||
}
|
||||
return *mcp;
|
||||
|
@ -130,14 +130,14 @@ const char *string, int level, const char *section)
|
|||
nrt->section = NULL;
|
||||
nrtypes[hash] = nrt;
|
||||
assert(string && *string);
|
||||
nrt->string = strdup(string);
|
||||
nrt->string = str_strdup(string);
|
||||
*c = '\0';
|
||||
for (i = 0; i != mtype->nparameters; ++i) {
|
||||
if (i != 0)
|
||||
*c++ = ' ';
|
||||
c += strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames));
|
||||
}
|
||||
nrt->vars = strdup(zNames);
|
||||
nrt->vars = str_strdup(zNames);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
|
||||
#include "strings.h"
|
||||
#include "assert.h"
|
||||
|
||||
|
@ -168,3 +166,11 @@ unsigned int wang_hash(unsigned int a)
|
|||
a = a ^ (a >> 16);
|
||||
return a;
|
||||
}
|
||||
|
||||
char *str_strdup(const char *s) {
|
||||
#ifdef _MSC_VER
|
||||
return _strdup(s);
|
||||
#else
|
||||
return strdup(s);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
char *set_string(char **s, const char *neu);
|
||||
unsigned int str_hash(const char *s);
|
||||
size_t str_slprintf(char * dst, size_t size, const char * format, ...);
|
||||
char *str_strdup(const char *s);
|
||||
|
||||
unsigned int jenkins_hash(unsigned int a);
|
||||
unsigned int wang_hash(unsigned int a);
|
||||
|
|
11
src/vortex.c
11
src/vortex.c
|
@ -8,6 +8,7 @@
|
|||
#include <util/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
|
@ -43,7 +44,7 @@ void register_special_direction(struct locale *lang, const char *name)
|
|||
if (token) {
|
||||
void **tokens = get_translations(lang, UT_SPECDIR);
|
||||
variant var;
|
||||
char *str = strdup(name);
|
||||
char *str = str_strdup(name);
|
||||
|
||||
var.v = str;
|
||||
addtoken((struct tnode **)tokens, token, var);
|
||||
|
@ -96,9 +97,9 @@ static int a_readdirection(attrib * a, void *owner, struct gamedata *data)
|
|||
READ_INT(store, &d->y);
|
||||
READ_INT(store, &d->duration);
|
||||
READ_TOK(store, lbuf, sizeof(lbuf));
|
||||
d->desc = strdup(lbuf);
|
||||
d->desc = str_strdup(lbuf);
|
||||
READ_TOK(store, lbuf, sizeof(lbuf));
|
||||
d->keyword = strdup(lbuf);
|
||||
d->keyword = str_strdup(lbuf);
|
||||
d->active = true;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
@ -153,8 +154,8 @@ attrib *create_special_direction(region * r, region * rt, int duration,
|
|||
d->x = rt->x;
|
||||
d->y = rt->y;
|
||||
d->duration = duration;
|
||||
d->desc = strdup(desc);
|
||||
d->keyword = strdup(keyword);
|
||||
d->desc = str_strdup(desc);
|
||||
d->keyword = str_strdup(keyword);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue