HELP GIVE

GIVE only for luxuries and herbs
This commit is contained in:
Enno Rehling 2009-07-24 19:35:54 +00:00
parent 521719e239
commit 3b6a4fd3ba
5 changed files with 58 additions and 19 deletions

View file

@ -403,6 +403,32 @@ do_recruiting(recruitment * recruits, int available)
return recruited; return recruited;
} }
static void
feedback_give_not_allowed(unit * u, order * ord)
{
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_give_forbidden", ""));
}
static boolean check_give(unit * u, unit * u2, const item_type * itype, int mask)
{
if (u2) {
if (u->faction!=u2->faction) {
int rule = rule_give();
if (itype) {
assert(mask==0);
if (itype->rtype->ltype) mask |= GIVE_LUXURIES;
else if (fval(itype, ITF_HERB)) mask |= GIVE_HERBS;
else mask |= GIVE_GOODS;
}
return (rule&mask)!=0;
}
} else {
int rule = rule_give();
return (rule & GIVE_PEASANTS)!=0;
}
return true;
}
void void
free_recruitments(recruitment * recruits) free_recruitments(recruitment * recruits)
{ {
@ -614,7 +640,7 @@ give_cmd(unit * u, order * ord)
region * r = u->region; region * r = u->region;
unit *u2; unit *u2;
const char *s; const char *s;
int i, n, rule = rule_give(); int i, n;
const item_type * itype; const item_type * itype;
param_t p; param_t p;
plane * pl; plane * pl;
@ -628,11 +654,8 @@ give_cmd(unit * u, order * ord)
return; return;
} }
if (getunitpeasants && (rule & GIVE_PEASANTS)==0) { if (!check_give(u, u2, NULL, GIVE_ALLITEMS)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_give_forbidden", "")); feedback_give_not_allowed(u, ord);
return;
} else if (u2 && u2->faction!=u->faction && (rule & GIVE_OTHERS)==0) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_give_forbidden", ""));
return; return;
} }
@ -714,6 +737,10 @@ give_cmd(unit * u, order * ord)
msg_feedback(u, ord, "race_nogive", "race", u->race)); msg_feedback(u, ord, "race_nogive", "race", u->race));
return; return;
} }
if (!check_give(u, u2, NULL, GIVE_HERBS)) {
feedback_give_not_allowed(u, ord);
return;
}
if (u2 && !(u2->race->ec_flags & GETITEM)) { if (u2 && !(u2->race->ec_flags & GETITEM)) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_notake", "race", u2->race)); msg_feedback(u, ord, "race_notake", "race", u2->race));
@ -765,6 +792,10 @@ give_cmd(unit * u, order * ord)
else if (p==P_ANY) { else if (p==P_ANY) {
const char * s = getstrtoken(); const char * s = getstrtoken();
if (!check_give(u, u2, NULL, GIVE_ALLITEMS)) {
feedback_give_not_allowed(u, ord);
return;
}
if (*s == 0) { /* Alle Gegenstände übergeben */ if (*s == 0) { /* Alle Gegenstände übergeben */
/* do these checks once, not for each item we have: */ /* do these checks once, not for each item we have: */
@ -826,8 +857,12 @@ give_cmd(unit * u, order * ord)
if (itype!=NULL) { if (itype!=NULL) {
item * i = *i_find(&u->items, itype); item * i = *i_find(&u->items, itype);
if (i!=NULL) { if (i!=NULL) {
n = i->number - get_reservation(u, itype->rtype); if (check_give(u, u2, itype, 0)) {
give_item(n, itype, u, u2, ord); n = i->number - get_reservation(u, itype->rtype);
give_item(n, itype, u, u2, ord);
} else {
feedback_give_not_allowed(u, ord);
}
return; return;
} }
} }
@ -852,10 +887,6 @@ give_cmd(unit * u, order * ord)
return; return;
} }
if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) {
cmistake(u, ord, 40, MSG_COMMERCE);
return;
}
i = findparam(s, u->faction->locale); i = findparam(s, u->faction->locale);
if (i == P_PERSON) { if (i == P_PERSON) {
if (!(u->race->ec_flags & GIVEPERSON)) { if (!(u->race->ec_flags & GIVEPERSON)) {
@ -882,7 +913,11 @@ give_cmd(unit * u, order * ord)
itype = finditemtype(s, u->faction->locale); itype = finditemtype(s, u->faction->locale);
if (itype!=NULL) { if (itype!=NULL) {
give_item(n, itype, u, u2, ord); if (check_give(u, u2, itype, 0)) {
give_item(n, itype, u, u2, ord);
} else {
feedback_give_not_allowed(u, ord);
}
return; return;
} }
cmistake(u, ord, 123, MSG_COMMERCE); cmistake(u, ord, 123, MSG_COMMERCE);

View file

@ -3067,7 +3067,7 @@ int rule_give(void)
{ {
static int value = -1; static int value = -1;
if (value<0) { if (value<0) {
value = get_param_int(global.parameters, "rules.give", 7); value = get_param_int(global.parameters, "rules.give", GIVE_DEFAULT);
} }
return value; return value;
} }

View file

@ -422,9 +422,12 @@ extern int rule_give(void);
#define GIVE_SELF 1 #define GIVE_SELF 1
#define GIVE_PEASANTS 2 #define GIVE_PEASANTS 2
#define GIVE_OTHERS 4 #define GIVE_LUXURIES 4
#define GIVE_ONDEATH 8 #define GIVE_HERBS 8
#define GIVE_ANY (GIVE_SELF|GIVE_PEASANTS|GIVE_OTHERS) #define GIVE_GOODS 16
#define GIVE_ONDEATH 32
#define GIVE_ALLITEMS (GIVE_GOODS|GIVE_HERBS|GIVE_LUXURIES)
#define GIVE_DEFAULT (GIVE_SELF|GIVE_PEASANTS|GIVE_LUXURIES|GIVE_HERBS|GIVE_GOODS)
extern struct attrib_type at_guard; extern struct attrib_type at_guard;
extern void free_gamedata(void); extern void free_gamedata(void);

View file

@ -217,7 +217,7 @@ gift_items(unit * u, int flags)
int rule = rule_give(); int rule = rule_give();
if ((u->faction->flags&FFL_QUIT)==0 || (rule&GIVE_ONDEATH)==0) { if ((u->faction->flags&FFL_QUIT)==0 || (rule&GIVE_ONDEATH)==0) {
if ((rule&GIVE_OTHERS)==0 && (flags&GIFT_FRIENDS)) flags-=GIFT_FRIENDS; if ((rule&GIVE_ALLITEMS)==0 && (flags&GIFT_FRIENDS)) flags-=GIFT_FRIENDS;
if ((rule&GIVE_PEASANTS)==0 && (flags&GIFT_PEASANTS)) flags-=GIFT_PEASANTS; if ((rule&GIVE_PEASANTS)==0 && (flags&GIFT_PEASANTS)) flags-=GIFT_PEASANTS;
if ((rule&GIVE_SELF)==0 && (flags&GIFT_SELF)) flags-=GIFT_SELF; if ((rule&GIVE_SELF)==0 && (flags&GIFT_SELF)) flags-=GIFT_SELF;
} }

View file

@ -165,9 +165,10 @@
<param name="rules.economy.wages" value="1"/> <param name="rules.economy.wages" value="1"/>
<param name="rules.economy.roqf" value="5"/> <param name="rules.economy.roqf" value="5"/>
<param name="rules.economy.herbrot" value="0"/> <param name="rules.economy.herbrot" value="0"/>
<param name="rules.give" value="15"/> <!-- self + peasants + herbs + lux - goods -->
<param name="rules.economy.grow" value="1"/> <param name="rules.economy.grow" value="1"/>
<param name="rules.tactics.formula" value="1"/> <!-- 10% per skilldiff --> <param name="rules.tactics.formula" value="1"/> <!-- 10% per skilldiff -->
<param name="rules.help.mask" value="fight guard money"/> <param name="rules.help.mask" value="fight guard money give"/>
<param name="movement.shipspeed.skillbonus" value="6"/> <param name="movement.shipspeed.skillbonus" value="6"/>
<param name="alliance.auto" value="fight"/> <param name="alliance.auto" value="fight"/>
<param name="alliance.restricted" value="fight"/> <param name="alliance.restricted" value="fight"/>