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

View File

@ -27,6 +27,7 @@
typedef struct locale_data { typedef struct locale_data {
#ifdef SHARE_ORDERS #ifdef SHARE_ORDERS
struct order_data * short_orders[MAXKEYWORDS]; struct order_data * short_orders[MAXKEYWORDS];
struct order_data * study_orders[MAXSKILLS];
#endif #endif
const struct locale * lang; const struct locale * lang;
} locale_data; } 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 * order *
parse_order(const char * s, const struct locale * lang) 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; const char * sptr;
order * ord = NULL; order * ord = NULL;
int persistent = 0; int persistent = 0;
int i; int lindex;
#ifdef AT_PERSISTENT #ifdef AT_PERSISTENT
while (*s=='@') { while (*s=='@') {
@ -170,10 +215,10 @@ parse_order(const char * s, const struct locale * lang)
} }
} }
for (i=0;i!=nlocales;++i) { for (lindex=0;lindex!=nlocales;++lindex) {
if (locale_array[i]->lang==lang) break; 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] = (locale_data*)calloc(1, sizeof(locale_data));
locale_array[nlocales]->lang = lang; locale_array[nlocales]->lang = lang;
++nlocales; ++nlocales;
@ -182,41 +227,22 @@ parse_order(const char * s, const struct locale * lang)
ord = (order*)malloc(sizeof(order)); ord = (order*)malloc(sizeof(order));
ord->_persistent = persistent; ord->_persistent = persistent;
ord->next = NULL; 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 #ifdef SHORT_STRINGS
if (ord->data->_keyword==NOKEYWORD) { if (kwd!=NOKEYWORD) {
ord->data->_str = strdup(s); if (*sptr) s = strdup(sptr);
} else { else s = NULL;
if (*sptr) {
ord->data->_str = strdup(sptr);
}
}
#else
ord->data->_str = strdup(s);
#endif
} }
#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; return ord;
} }
} }