forked from github/server
Bugfixes an replace_order
This commit is contained in:
parent
2a04a9a22c
commit
7ed6f06a15
|
@ -801,8 +801,9 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
|
||||||
building * b = NULL;
|
building * b = NULL;
|
||||||
/* einmalige Korrektur */
|
/* einmalige Korrektur */
|
||||||
static char buffer[8 + IDSIZE + 1 + NAMESIZE + 1];
|
static char buffer[8 + IDSIZE + 1 + NAMESIZE + 1];
|
||||||
const char *string2;
|
const char *btname = NULL;
|
||||||
order * new_order;
|
order * new_order = NULL;
|
||||||
|
const struct locale * lang = u->faction->locale;
|
||||||
|
|
||||||
if (eff_skill(u, SK_BUILDING, r) == 0) {
|
if (eff_skill(u, SK_BUILDING, r) == 0) {
|
||||||
cmistake(u, ord, 101, MSG_PRODUCE);
|
cmistake(u, ord, 101, MSG_PRODUCE);
|
||||||
|
@ -881,9 +882,7 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
|
||||||
if (c!=0) strcat(ch++, ",");
|
if (c!=0) strcat(ch++, ",");
|
||||||
n = cons->materials[c].number / cons->reqsize;
|
n = cons->materials[c].number / cons->reqsize;
|
||||||
sprintf(ch, " %d %s", n?n:1,
|
sprintf(ch, " %d %s", n?n:1,
|
||||||
locale_string(u->faction->locale,
|
LOC(lang, resname(cons->materials[c].type, cons->materials[c].number!=1)));
|
||||||
resname(cons->materials[c].type, cons->materials[c].number!=1))
|
|
||||||
);
|
|
||||||
ch = ch+strlen(ch);
|
ch = ch+strlen(ch);
|
||||||
}
|
}
|
||||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "build_required",
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "build_required",
|
||||||
|
@ -901,7 +900,7 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
|
||||||
/* at this point, the building size is increased. */
|
/* at this point, the building size is increased. */
|
||||||
if (b==NULL) {
|
if (b==NULL) {
|
||||||
/* build a new building */
|
/* build a new building */
|
||||||
b = new_building(btype, r, u->faction->locale);
|
b = new_building(btype, r, lang);
|
||||||
b->type = btype;
|
b->type = btype;
|
||||||
fset(b, BLD_MAINTAINED);
|
fset(b, BLD_MAINTAINED);
|
||||||
|
|
||||||
|
@ -910,31 +909,42 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
|
||||||
u->building = b;
|
u->building = b;
|
||||||
fset(u, UFL_OWNER);
|
fset(u, UFL_OWNER);
|
||||||
|
|
||||||
newbuilding = 1;
|
newbuilding = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->type->name) {
|
if (newbuilding) {
|
||||||
string2 = LOC(u->faction->locale, b->type->_name);
|
if (b->type->name==NULL) {
|
||||||
} else {
|
btname = LOC(lang, b->type->_name);
|
||||||
string2 = LOC(u->faction->locale, buildingtype(b, b->size));
|
} else {
|
||||||
if( newbuilding && b->type->maxsize != -1 )
|
btname = LOC(lang, buildingtype(b, b->size));
|
||||||
|
if (b->type->maxsize != -1) {
|
||||||
want = b->type->maxsize - b->size;
|
want = b->type->maxsize - b->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( want == INT_MAX )
|
if (want-built <= 0) {
|
||||||
sprintf(buffer, "%s %s %s", locale_string(u->faction->locale, keywords[K_MAKE]), string2, buildingid(b));
|
/* gebäude fertig */
|
||||||
else if( want-built <= 0 )
|
strcpy(buffer, locale_string(lang, "defaultorder"));
|
||||||
strcpy(buffer, locale_string(u->faction->locale, "defaultorder"));
|
new_order = parse_order(buffer, lang);
|
||||||
else
|
} else if (want!=INT_MAX) {
|
||||||
sprintf(buffer, "%s %d %s %s", locale_string(u->faction->locale, keywords[K_MAKE]), want-built, string2, buildingid(b));
|
/* reduzierte restgröße */
|
||||||
|
sprintf(buffer, "%s %d %s %s", LOC(lang, keywords[K_MAKE]), want-built, btname, buildingid(b));
|
||||||
|
new_order = parse_order(buffer, lang);
|
||||||
|
} else if (btname) {
|
||||||
|
/* Neues Haus, Befehl mit Gebäudename */
|
||||||
|
sprintf(buffer, "%s %s %s", LOC(lang, keywords[K_MAKE]), btname, buildingid(b));
|
||||||
|
new_order = parse_order(buffer, u->faction->locale);
|
||||||
|
}
|
||||||
|
|
||||||
new_order = parse_order(buffer, u->faction->locale);
|
if (new_order) {
|
||||||
#ifdef LASTORDER
|
#ifdef LASTORDER
|
||||||
set_order(&u->lastorder, new_order);
|
set_order(&u->lastorder, new_order);
|
||||||
#else
|
#else
|
||||||
replace_order(ord, new_order);
|
replace_order(&u->orders, ord, new_order);
|
||||||
free_order(new_order);
|
free_order(new_order);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
b->size += built;
|
b->size += built;
|
||||||
update_lighthouse(b);
|
update_lighthouse(b);
|
||||||
|
@ -1025,7 +1035,7 @@ create_ship(region * r, unit * u, const struct ship_type * newtype, int want, or
|
||||||
#ifdef LASTORDER
|
#ifdef LASTORDER
|
||||||
set_order(&u->lastorder, new_order);
|
set_order(&u->lastorder, new_order);
|
||||||
#else
|
#else
|
||||||
replace_order(ord, new_order);
|
replace_order(&u->orders, ord, new_order);
|
||||||
free_order(new_order);
|
free_order(new_order);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -914,7 +914,7 @@ cycle_route(order * ord, unit *u, int gereist)
|
||||||
#ifdef LASTORDER
|
#ifdef LASTORDER
|
||||||
set_order(&u->lastorder, norder);
|
set_order(&u->lastorder, norder);
|
||||||
#else
|
#else
|
||||||
replace_order(ord, norder);
|
replace_order(&u->orders, ord, norder);
|
||||||
free_order(norder);
|
free_order(norder);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "eressea.h"
|
#include "eressea.h"
|
||||||
|
|
||||||
#include "order.h"
|
#include "order.h"
|
||||||
|
#include "skill.h"
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#undef SHORT_STRINGS
|
#define SHORT_STRINGS
|
||||||
|
|
||||||
#ifdef SHARE_ORDERS
|
#ifdef SHARE_ORDERS
|
||||||
# define ORD_KEYWORD(ord) (ord)->data->_keyword
|
# define ORD_KEYWORD(ord) (ord)->data->_keyword
|
||||||
|
@ -68,16 +69,19 @@ release_data(order_data * data)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
replace_order(order * dst, const order * src)
|
replace_order(order ** dlist, order * orig, const order * src)
|
||||||
{
|
{
|
||||||
#ifdef SHARE_ORDERS
|
while (*dlist!=NULL) {
|
||||||
release_data(dst->data);
|
order * dst = *dlist;
|
||||||
++src->data->_refcount;
|
if (dst->data==orig->data) {
|
||||||
#else
|
order * cpy = copy_order(src);
|
||||||
if (dst->data._str) free(dst->data._str);
|
*dlist = cpy;
|
||||||
#endif
|
cpy->next = dst->next;
|
||||||
dst->data = src->data;
|
dst->next = 0;
|
||||||
dst->_persistent = src->_persistent;
|
free_order(dst);
|
||||||
|
}
|
||||||
|
dlist = &(*dlist)->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyword_t
|
keyword_t
|
||||||
|
@ -86,11 +90,7 @@ get_keyword(const order * ord)
|
||||||
if (ord==NULL) {
|
if (ord==NULL) {
|
||||||
return NOKEYWORD;
|
return NOKEYWORD;
|
||||||
}
|
}
|
||||||
#ifdef SHARE_ORDERS
|
return ORD_KEYWORD(ord);
|
||||||
return ord->data->_keyword;
|
|
||||||
#else
|
|
||||||
return ord->data._keyword;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -135,7 +135,7 @@ free_order(order * ord)
|
||||||
}
|
}
|
||||||
|
|
||||||
order *
|
order *
|
||||||
copy_order(order * src)
|
copy_order(const order * src)
|
||||||
{
|
{
|
||||||
if (src!=NULL) {
|
if (src!=NULL) {
|
||||||
order * ord = (order*)malloc(sizeof(order));
|
order * ord = (order*)malloc(sizeof(order));
|
||||||
|
@ -175,6 +175,8 @@ create_data(keyword_t kwd, const char * s, const char * sptr, int lindex)
|
||||||
{
|
{
|
||||||
order_data * data;
|
order_data * data;
|
||||||
const struct locale * lang = locale_array[lindex]->lang;
|
const struct locale * lang = locale_array[lindex]->lang;
|
||||||
|
|
||||||
|
/* learning, only one order_data per skill required */
|
||||||
if (kwd==K_STUDY) {
|
if (kwd==K_STUDY) {
|
||||||
skill_t sk = findskill(parse_token(&sptr), lang);
|
skill_t sk = findskill(parse_token(&sptr), lang);
|
||||||
if (sk!=NOSKILL) {
|
if (sk!=NOSKILL) {
|
||||||
|
@ -184,13 +186,20 @@ create_data(keyword_t kwd, const char * s, const char * sptr, int lindex)
|
||||||
locale_array[lindex]->study_orders[sk] = data;
|
locale_array[lindex]->study_orders[sk] = data;
|
||||||
data->_keyword = kwd;
|
data->_keyword = kwd;
|
||||||
data->_lindex = lindex;
|
data->_lindex = lindex;
|
||||||
data->_str = s?strdup(s):NULL;
|
#ifdef SHORT_STRINGS
|
||||||
|
data->_str = strdup(skillname(sk, lang));
|
||||||
|
#else
|
||||||
|
sprintf(buf, "%s %s", LOC(lang, keywords[kwd]), skillname(sk, lang));
|
||||||
|
data->_str = strdup(buf);
|
||||||
|
#endif
|
||||||
data->_refcount = 1;
|
data->_refcount = 1;
|
||||||
}
|
}
|
||||||
++data->_refcount;
|
++data->_refcount;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* orders with no parameter, only one order_data per order required */
|
||||||
if (kwd!=NOKEYWORD && *sptr == 0) {
|
if (kwd!=NOKEYWORD && *sptr == 0) {
|
||||||
data = locale_array[lindex]->short_orders[kwd];
|
data = locale_array[lindex]->short_orders[kwd];
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
|
@ -198,7 +207,11 @@ create_data(keyword_t kwd, const char * s, const char * sptr, int lindex)
|
||||||
locale_array[lindex]->short_orders[kwd] = data;
|
locale_array[lindex]->short_orders[kwd] = data;
|
||||||
data->_keyword = kwd;
|
data->_keyword = kwd;
|
||||||
data->_lindex = lindex;
|
data->_lindex = lindex;
|
||||||
data->_str = s?strdup(s):NULL;
|
#ifdef SHORT_STRINGS
|
||||||
|
data->_str = NULL;
|
||||||
|
#else
|
||||||
|
data->_str = strdup(LOC(lang, keywords[kwd]));
|
||||||
|
#endif
|
||||||
data->_refcount = 1;
|
data->_refcount = 1;
|
||||||
}
|
}
|
||||||
++data->_refcount;
|
++data->_refcount;
|
||||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
||||||
* implemented yet) saving approx. 50% of all string-related memory.
|
* implemented yet) saving approx. 50% of all string-related memory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#undef SHARE_ORDERS
|
#define SHARE_ORDERS
|
||||||
|
|
||||||
#ifdef SHARE_ORDERS
|
#ifdef SHARE_ORDERS
|
||||||
struct order_data;
|
struct order_data;
|
||||||
|
@ -52,23 +52,23 @@ typedef struct order {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* constructor */
|
/* constructor */
|
||||||
extern struct order * parse_order(const char * s, const struct locale * lang);
|
extern order * parse_order(const char * s, const struct locale * lang);
|
||||||
extern void replace_order(order * dst, const order * src);
|
extern void replace_order(order ** dst, order * orig, const order * src);
|
||||||
|
|
||||||
/* reference counted copies of orders: */
|
/* reference counted copies of orders: */
|
||||||
extern struct order * copy_order(struct order * ord);
|
extern order * copy_order(const order * ord);
|
||||||
extern void free_order(struct order * ord);
|
extern void free_order(order * ord);
|
||||||
extern void free_orders(struct order ** olist);
|
extern void free_orders(order ** olist);
|
||||||
|
|
||||||
/* access functions for orders */
|
/* access functions for orders */
|
||||||
extern keyword_t get_keyword(const struct order * ord);
|
extern keyword_t get_keyword(const order * ord);
|
||||||
extern void set_order(struct order ** destp, struct order * src);
|
extern void set_order(order ** destp, order * src);
|
||||||
extern char * getcommand(const struct order * ord);
|
extern char * getcommand(const order * ord);
|
||||||
extern boolean is_persistent(const struct order *ord);
|
extern boolean is_persistent(const order *ord);
|
||||||
extern boolean is_exclusive(const struct order *ord);
|
extern boolean is_exclusive(const order *ord);
|
||||||
extern boolean is_repeated(const order * ord);
|
extern boolean is_repeated(const order * ord);
|
||||||
|
|
||||||
extern char * write_order(const struct order * ord, const struct locale * lang, char * buffer, size_t size);
|
extern char * write_order(const order * ord, const struct locale * lang, char * buffer, size_t size);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue