sharing STUDY orders between units.

monsters: code cosmetics
This commit is contained in:
Enno Rehling 2005-05-11 16:12:42 +00:00
parent 498afe2ff2
commit 17419a3164
2 changed files with 72 additions and 47 deletions

View File

@ -595,8 +595,8 @@ absorbed_by_monster(unit * u)
static int
scareaway(region * r, int anzahl)
{
int n, p, d = 0, emigrants[MAXDIRECTIONS];
direction_t i;
int n, p, diff = 0, emigrants[MAXDIRECTIONS];
direction_t d;
anzahl = min(max(1, anzahl),rpeasants(r));
@ -605,8 +605,8 @@ scareaway(region * r, int anzahl)
* emigrants[] ist local, weil r->newpeasants durch die Monster
* vielleicht schon hochgezaehlt worden ist. */
for (i = 0; i != MAXDIRECTIONS; i++)
emigrants[i] = 0;
for (d = 0; d != MAXDIRECTIONS; d++)
emigrants[d] = 0;
p = rpeasants(r);
assert(p >= 0 && anzahl >= 0);
@ -615,14 +615,14 @@ scareaway(region * r, int anzahl)
region * c = rconnect(r, dir);
if (c && landregion(rterrain(c))) {
d++;
++diff;
c->land->newpeasants++;
emigrants[dir]++;
}
}
rsetpeasants(r, p-d);
assert(p >= d);
return d;
rsetpeasants(r, p-diff);
assert(p >= diff);
return diff;
}
static void
@ -650,9 +650,8 @@ scared_by_monster(unit * u)
if(n > 0) {
n = scareaway(u->region, n);
if(n > 0) {
add_message(&u->region->msgs,
new_message(NULL,
"fleescared%i:amount%u:unit", n, u));
ADDMSG(&u->region->msgs, msg_message("fleescared",
"amount unit", n, u));
}
}
}

View File

@ -27,6 +27,7 @@
typedef struct locale_data {
#ifdef SHARE_ORDERS
struct order_data * short_orders[MAXKEYWORDS];
struct order_data * study_orders[MAXSKILLS];
#endif
const struct locale * lang;
} locale_data;
@ -137,6 +138,50 @@ free_orders(order ** olist)
}
}
static order_data *
create_data(keyword_t kwd, const char * s, const char * sptr, int lindex)
{
order_data * data;
#ifdef SHARE_ORDERS
const struct locale * lang = locale_array[lindex]->lang;
if (kwd==K_STUDY) {
skill_t sk = findskill(parse_token(&sptr), lang);
if (sk!=NOSKILL) {
data = locale_array[lindex]->study_orders[sk];
if (data==NULL) {
data = (order_data*)malloc(sizeof(order_data));
locale_array[lindex]->study_orders[sk] = data;
data->_keyword = kwd;
data->_lindex = lindex;
data->_str = s?strdup(s):NULL;
data->_refcount = 1;
}
++data->_refcount;
return data;
}
}
if (kwd!=NOKEYWORD && *sptr == 0) {
data = locale_array[lindex]->short_orders[kwd];
if (data == NULL) {
data = (order_data*)malloc(sizeof(order_data));
locale_array[lindex]->short_orders[kwd] = data;
data->_keyword = kwd;
data->_lindex = lindex;
data->_str = s?strdup(s):NULL;
data->_refcount = 1;
}
++data->_refcount;
return data;
}
#endif
data = (order_data*)malloc(sizeof(order_data));
data->_keyword = kwd;
data->_lindex = lindex;
data->_str = s?strdup(s):NULL;
data->_refcount = 1;
return data;
}
order *
parse_order(const char * s, const struct locale * lang)
{
@ -147,7 +192,7 @@ parse_order(const char * s, const struct locale * lang)
const char * sptr;
order * ord = NULL;
int persistent = 0;
int i;
int lindex;
#ifdef AT_PERSISTENT
while (*s=='@') {
@ -170,10 +215,10 @@ parse_order(const char * s, const struct locale * lang)
}
}
for (i=0;i!=nlocales;++i) {
if (locale_array[i]->lang==lang) break;
for (lindex=0;lindex!=nlocales;++lindex) {
if (locale_array[lindex]->lang==lang) break;
}
if (i==nlocales) {
if (lindex==nlocales) {
locale_array[nlocales] = (locale_data*)calloc(1, sizeof(locale_data));
locale_array[nlocales]->lang = lang;
++nlocales;
@ -182,41 +227,22 @@ parse_order(const char * s, const struct locale * lang)
ord = (order*)malloc(sizeof(order));
ord->_persistent = persistent;
ord->next = NULL;
ord->data = NULL;
#ifdef SHARE_ORDERS
if (kwd!=NOKEYWORD && *sptr == 0) {
ord->data = locale_array[i]->short_orders[kwd];
if (ord->data != NULL) {
++ord->data->_refcount;
}
}
#endif
if (ord->data==NULL) {
ord->data = (order_data*)malloc(sizeof(order_data));
ord->data->_lindex = (unsigned char)i;
ord->data->_str = NULL;
ord->data->_refcount = 1;
ord->data->_keyword = kwd;
#ifdef SHARE_ORDERS
if (kwd!=NOKEYWORD && *sptr == 0) {
locale_array[i]->short_orders[kwd] = ord->data;
++ord->data->_refcount;
}
#endif
#ifdef SHORT_STRINGS
if (ord->data->_keyword==NOKEYWORD) {
ord->data->_str = strdup(s);
} else {
if (*sptr) {
ord->data->_str = strdup(sptr);
}
if (kwd!=NOKEYWORD) {
if (*sptr) s = strdup(sptr);
else s = NULL;
}
#else
ord->data->_str = strdup(s);
#endif
}
#ifdef SHARE_ORDERS
ord->data = create_data(kwd, s, sptr, lindex);
#else
ord->data = NULL;
#endif
return ord;
}
}