forked from github/server
Bugfix leave_trail. Aufsplitten von move_ship - Änderung von get_param (liefert NULL für undeklarierte params) in Vorbereitung auf "mehr config, weniger define" Diverse indenting-anpassungen (space statt tabs)
This commit is contained in:
parent
77a00514ae
commit
e319698a43
|
@ -110,11 +110,12 @@ static request *oa;
|
|||
|
||||
static int
|
||||
giverestriction(void) {
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
value = atoi(get_param(global.parameters, "GiveRestriction"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "GiveRestriction");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -2990,43 +2991,48 @@ expandentertainment(region * r)
|
|||
void
|
||||
entertain(region * r, unit * u)
|
||||
{
|
||||
int max_e;
|
||||
request *o;
|
||||
static int entertainbase = 0;
|
||||
static int entertainperlevel = 0;
|
||||
if (!entertainbase) entertainbase = atoi(get_param(global.parameters, "entertain.base"));
|
||||
if (!entertainperlevel) entertainperlevel = atoi(get_param(global.parameters, "entertain.perlevel"));
|
||||
int max_e;
|
||||
request *o;
|
||||
static int entertainbase = 0;
|
||||
static int entertainperlevel = 0;
|
||||
if (!entertainbase) {
|
||||
const char * str = get_param(global.parameters, "entertain.base");
|
||||
entertainbase = str?atoi(str):0;
|
||||
}
|
||||
if (!entertainperlevel) {
|
||||
const char * str = get_param(global.parameters, "entertain.perlevel");
|
||||
entertainperlevel = str?atoi(str):0;
|
||||
}
|
||||
if (fval(u, UFL_WERE)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 58, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fval(u, UFL_WERE)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 58, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (!effskill(u, SK_ENTERTAINMENT)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 58, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (besieged(u)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 60, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 69, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (is_cursed(r->attribs, C_DEPRESSION, 0)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 28, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!effskill(u, SK_ENTERTAINMENT)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 58, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (besieged(u)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 60, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 69, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
if (is_cursed(r->attribs, C_DEPRESSION, 0)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 28, MSG_INCOME);
|
||||
return;
|
||||
}
|
||||
u->wants = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT) * entertainperlevel);
|
||||
if ((max_e = geti()) != 0)
|
||||
u->wants = min(u->wants,max_e);
|
||||
|
||||
u->wants = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT) * entertainperlevel);
|
||||
if ((max_e = geti()) != 0)
|
||||
u->wants = min(u->wants,max_e);
|
||||
|
||||
o = nextentertainer++;
|
||||
o->unit = u;
|
||||
o->qty = u->wants;
|
||||
entertaining += o->qty;
|
||||
o = nextentertainer++;
|
||||
o->unit = u;
|
||||
o->qty = u->wants;
|
||||
entertaining += o->qty;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
|
|
@ -106,39 +106,40 @@ boolean nomonsters = false;
|
|||
|
||||
static int
|
||||
RemoveNMRNewbie(void) {
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
value = atoi(get_param(global.parameters, "nmr.removenewbie"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "nmr.removenewbie");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static void
|
||||
restart(unit *u, const race * rc)
|
||||
{
|
||||
faction *f = addfaction(u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription);
|
||||
faction *f = addfaction(u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription);
|
||||
unit * nu = addplayer(u->region, f);
|
||||
strlist ** o=&u->orders;
|
||||
strlist ** o=&u->orders;
|
||||
f->subscription = u->faction->subscription;
|
||||
fset(f, FFL_RESTART);
|
||||
if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set faction='%s', race='%s' where id=%u;\n",
|
||||
fset(f, FFL_RESTART);
|
||||
if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set faction='%s', race='%s' where id=%u;\n",
|
||||
itoa36(f->no), dbrace(rc), f->subscription);
|
||||
f->magiegebiet = u->faction->magiegebiet;
|
||||
f->options = u->faction->options;
|
||||
freestrlist(nu->orders);
|
||||
nu->orders = u->orders;
|
||||
u->orders = NULL;
|
||||
while (*o) {
|
||||
strlist * S = *o;
|
||||
if (igetkeyword(S->s, u->faction->locale) == K_RESTART) {
|
||||
*o = S->next;
|
||||
S->next = NULL;
|
||||
freestrlist(S);
|
||||
} else {
|
||||
o = &S->next;
|
||||
}
|
||||
}
|
||||
destroyfaction(u->faction);
|
||||
f->magiegebiet = u->faction->magiegebiet;
|
||||
f->options = u->faction->options;
|
||||
freestrlist(nu->orders);
|
||||
nu->orders = u->orders;
|
||||
u->orders = NULL;
|
||||
while (*o) {
|
||||
strlist * S = *o;
|
||||
if (igetkeyword(S->s, u->faction->locale) == K_RESTART) {
|
||||
*o = S->next;
|
||||
S->next = NULL;
|
||||
freestrlist(S);
|
||||
} else {
|
||||
o = &S->next;
|
||||
}
|
||||
}
|
||||
destroyfaction(u->faction);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
|
|
@ -57,59 +57,58 @@
|
|||
void
|
||||
spy(region * r, unit * u)
|
||||
{
|
||||
unit *target;
|
||||
int spy, observe;
|
||||
unit *target;
|
||||
int spy, observe;
|
||||
double spychance, observechance;
|
||||
|
||||
target = getunit(r, u->faction);
|
||||
target = getunit(r, u->faction);
|
||||
|
||||
if (!target) {
|
||||
cmistake(u, findorder(u, u->thisorder), 63, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
if (!can_contact(r, u, target)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 24, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
if (eff_skill(u, SK_SPY, r) < 1) {
|
||||
cmistake(u, findorder(u, u->thisorder), 39, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
/* Die Grundchance für einen erfolgreichen Spionage-Versuch ist 10%.
|
||||
* Für jeden Talentpunkt, den das Spionagetalent das Tarnungstalent
|
||||
* des Opfers übersteigt, erhöht sich dieses um 5%*/
|
||||
spy = eff_skill(u, SK_SPY, r) - eff_skill(target, SK_STEALTH, r);
|
||||
spychance = 0.1 + max(spy*0.05, 0.0);
|
||||
if (!target) {
|
||||
cmistake(u, findorder(u, u->thisorder), 63, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
if (!can_contact(r, u, target)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 24, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
if (eff_skill(u, SK_SPY, r) < 1) {
|
||||
cmistake(u, findorder(u, u->thisorder), 39, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
/* Die Grundchance für einen erfolgreichen Spionage-Versuch ist 10%.
|
||||
* Für jeden Talentpunkt, den das Spionagetalent das Tarnungstalent
|
||||
* des Opfers übersteigt, erhöht sich dieses um 5%*/
|
||||
spy = eff_skill(u, SK_SPY, r) - eff_skill(target, SK_STEALTH, r);
|
||||
spychance = 0.1 + max(spy*0.05, 0.0);
|
||||
|
||||
if (chance(spychance)) {
|
||||
spy_message(spy, u, target);
|
||||
} else {
|
||||
add_message(&u->faction->msgs, new_message(u->faction,
|
||||
"spyfail%u:spy%u:target", u, target));
|
||||
}
|
||||
if (chance(spychance)) {
|
||||
spy_message(spy, u, target);
|
||||
} else {
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyfail", "spy target", u, target));
|
||||
}
|
||||
|
||||
/* der Spion kann identifiziert werden, wenn das Opfer bessere
|
||||
* Wahrnehmung als das Ziel Tarnung + Spionage/2 hat */
|
||||
observe = eff_skill(target, SK_OBSERVATION, r)
|
||||
- (effskill(u, SK_STEALTH) + eff_skill(u, SK_SPY, r)/2);
|
||||
/* der Spion kann identifiziert werden, wenn das Opfer bessere
|
||||
* Wahrnehmung als das Ziel Tarnung + Spionage/2 hat */
|
||||
observe = eff_skill(target, SK_OBSERVATION, r)
|
||||
- (effskill(u, SK_STEALTH) + eff_skill(u, SK_SPY, r)/2);
|
||||
|
||||
#if NEWATSROI == 0
|
||||
if (invisible(u) >= u->number &&
|
||||
get_item(target, I_AMULET_OF_TRUE_SEEING) == 0) {
|
||||
observe = min(observe, 0);
|
||||
}
|
||||
if (invisible(u) >= u->number &&
|
||||
get_item(target, I_AMULET_OF_TRUE_SEEING) == 0) {
|
||||
observe = min(observe, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Anschließend wird - unabhängig vom Erfolg - gewürfelt, ob der
|
||||
* Spionageversuch bemerkt wurde. Die Wahrscheinlich dafür ist (100 -
|
||||
* SpionageSpion*5 + WahrnehmungOpfer*2)%. */
|
||||
observechance = 1.0 - (eff_skill(u, SK_SPY, r) * 0.05)
|
||||
+ (eff_skill(target, SK_OBSERVATION, r) * 0.02);
|
||||
/* Anschließend wird - unabhängig vom Erfolg - gewürfelt, ob der
|
||||
* Spionageversuch bemerkt wurde. Die Wahrscheinlich dafür ist (100 -
|
||||
* SpionageSpion*5 + WahrnehmungOpfer*2)%. */
|
||||
observechance = 1.0 - (eff_skill(u, SK_SPY, r) * 0.05)
|
||||
+ (eff_skill(target, SK_OBSERVATION, r) * 0.02);
|
||||
|
||||
if (chance(observechance)){
|
||||
add_message(&target->faction->msgs, new_message(target->faction,
|
||||
"spydetect%u:spy%u:target", observe>0?u:NULL, target));
|
||||
}
|
||||
if (chance(observechance)){
|
||||
add_message(&target->faction->msgs, new_message(target->faction,
|
||||
"spydetect%u:spy%u:target", observe>0?u:NULL, target));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -109,58 +109,63 @@ static attrib_type at_creator = {
|
|||
};
|
||||
static int
|
||||
MaxAge(void) {
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
value = atoi(get_param(global.parameters, "MaxAge"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "MaxAge");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
LongHunger(void) {
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
value = atoi(get_param(global.parameters, "hunger.long"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "hunger.long");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
SkillCap(skill_t sk) {
|
||||
static int value = -1;
|
||||
if (sk==SK_MAGIC) return 0; /* no caps on magic */
|
||||
if (value<0) {
|
||||
value = atoi(get_param(global.parameters, "skill.maxlevel"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (sk==SK_MAGIC) return 0; /* no caps on magic */
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "skill.maxlevel");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
boolean
|
||||
TradeDisabled(void) {
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
value = (boolean)atoi(get_param(global.parameters, "trade.disabled"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "trade.disabled");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
NMRTimeout(void) {
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
value = atoi(get_param(global.parameters, "nmr.timeout"));
|
||||
}
|
||||
return value;
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "nmr.timeout");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
race_t
|
||||
old_race(const struct race * rc)
|
||||
{
|
||||
race_t i;
|
||||
for (i=0;i!=MAXRACES;++i) {
|
||||
if (new_race[i]==rc) return i;
|
||||
}
|
||||
return NORACE;
|
||||
race_t i;
|
||||
for (i=0;i!=MAXRACES;++i) {
|
||||
if (new_race[i]==rc) return i;
|
||||
}
|
||||
return NORACE;
|
||||
}
|
||||
|
||||
const char *directions[MAXDIRECTIONS+2] =
|
||||
|
@ -378,7 +383,8 @@ allied_skillcount(const faction * f, skill_t sk)
|
|||
int
|
||||
allied_skilllimit(const faction * f, skill_t sk)
|
||||
{
|
||||
return atoi(get_param(global.parameters, "allied.skilllimit"));
|
||||
const char * str = get_param(global.parameters, "allied.skilllimit");
|
||||
return str?atoi(str):0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -2174,37 +2180,37 @@ init_tokens(const struct locale * lang)
|
|||
}
|
||||
|
||||
typedef struct param {
|
||||
struct param * next;
|
||||
char * name;
|
||||
char * data;
|
||||
struct param * next;
|
||||
char * name;
|
||||
char * data;
|
||||
} param;
|
||||
|
||||
const char *
|
||||
get_param(const struct param * p, const char * key)
|
||||
{
|
||||
while (p!=NULL) {
|
||||
if (strcmp(p->name, key)==0) return p->data;
|
||||
p = p->next;
|
||||
}
|
||||
return "0";
|
||||
while (p!=NULL) {
|
||||
if (strcmp(p->name, key)==0) return p->data;
|
||||
p = p->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_param(struct param ** p, const char * key, const char * data)
|
||||
{
|
||||
while (*p!=NULL) {
|
||||
if (strcmp((*p)->name, key)==0) {
|
||||
free((*p)->data);
|
||||
(*p)->data = strdup(data);
|
||||
return;
|
||||
}
|
||||
p=&(*p)->next;
|
||||
}
|
||||
*p = malloc(sizeof(param));
|
||||
(*p)->name = strdup(key);
|
||||
(*p)->data = strdup(data);
|
||||
(*p)->next = NULL;
|
||||
while (*p!=NULL) {
|
||||
if (strcmp((*p)->name, key)==0) {
|
||||
free((*p)->data);
|
||||
(*p)->data = strdup(data);
|
||||
return;
|
||||
}
|
||||
p=&(*p)->next;
|
||||
}
|
||||
*p = malloc(sizeof(param));
|
||||
(*p)->name = strdup(key);
|
||||
(*p)->data = strdup(data);
|
||||
(*p)->next = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -435,74 +435,83 @@ do_maelstrom(region *r, unit *u)
|
|||
void
|
||||
travelthru(unit * u, region * r)
|
||||
{
|
||||
attrib *ru = a_add(&r->attribs, a_new(&at_travelunit));
|
||||
attrib *ru = a_add(&r->attribs, a_new(&at_travelunit));
|
||||
|
||||
ru->data.v = u;
|
||||
u->faction->first = 0;
|
||||
u->faction->last = 0;
|
||||
ru->data.v = u;
|
||||
|
||||
/* the first and last region of the faction gets reset, because travelthrough
|
||||
* could be in regions that are located before the [first, last] interval,
|
||||
* and recalculation is needed */
|
||||
u->faction->first = 0;
|
||||
u->faction->last = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
leave_trail(ship * sh, region **route)
|
||||
{
|
||||
region **ri = route;
|
||||
|
||||
while (*ri) {
|
||||
region *r = *ri;
|
||||
direction_t dir = reldirection(*ri, *rn);
|
||||
attrib * a = a_find((*ri)->attribs, &at_traveldir_new);
|
||||
traveldir * td = NULL;
|
||||
|
||||
while (a!=NULL) {
|
||||
td = (traveldir *)a->data.v;
|
||||
if (td->no == sh->no) break;
|
||||
a = a->nexttype;
|
||||
}
|
||||
|
||||
if (a!=NULL) {
|
||||
a = a_add(&((*ri)->attribs), a_new(&at_traveldir_new));
|
||||
td = (traveldir *)a->data.v;
|
||||
td->no = sh->no;
|
||||
}
|
||||
td->dir = dir;
|
||||
td->age = 2;
|
||||
|
||||
travelthru(u, r);
|
||||
++ri;
|
||||
}
|
||||
}
|
||||
|
||||
ship *
|
||||
move_ship(ship * sh, region * from, region * to, region ** route)
|
||||
{
|
||||
unit *u = from->units;
|
||||
unit **ulist = &to->units;
|
||||
direction_t dir;
|
||||
attrib *a;
|
||||
unit **iunit = &from->units;
|
||||
unit **ulist = &to->units;
|
||||
direction_t dir;
|
||||
attrib *a;
|
||||
boolean trail = (route==NULL);
|
||||
|
||||
if (from!=to) {
|
||||
translist(&from->ships, &to->ships, sh);
|
||||
sh->region = to;
|
||||
}
|
||||
if (from!=to) {
|
||||
translist(&from->ships, &to->ships, sh);
|
||||
sh->region = to;
|
||||
}
|
||||
|
||||
while (u) {
|
||||
unit *nu = u->next;
|
||||
while (*iunit!=NULL) {
|
||||
unit *u = *iunit;
|
||||
assert(u->region==from);
|
||||
|
||||
if (u->ship == sh)
|
||||
{
|
||||
if (route) {
|
||||
region **ri = route;
|
||||
region **rn;
|
||||
|
||||
while (*ri) {
|
||||
rn = ri+1;
|
||||
if(*rn) {
|
||||
dir = reldirection(*ri, *rn);
|
||||
a = a_find((*ri)->attribs, &at_traveldir_new);
|
||||
while (a) {
|
||||
if(((traveldir *)(a->data.v))->no == sh->no) break;
|
||||
a = a->nexttype;
|
||||
}
|
||||
if(!a) {
|
||||
a = a_add(&((*ri)->attribs), a_new(&at_traveldir_new));
|
||||
{
|
||||
traveldir *t = (traveldir *)(a->data.v);
|
||||
t->no = sh->no;
|
||||
t->dir = dir;
|
||||
t->age = 2;
|
||||
}
|
||||
} else {
|
||||
traveldir *t = (traveldir *)(a->data.v);
|
||||
t->dir = dir;
|
||||
t->age = 2;
|
||||
}
|
||||
}
|
||||
travelthru(u, *ri++);
|
||||
}
|
||||
}
|
||||
if (from!=to) {
|
||||
u->ship = NULL; /* damit move_unit() kein leave() macht */
|
||||
move_unit(u, to, ulist);
|
||||
ulist = &u->next;
|
||||
u->ship = sh;
|
||||
}
|
||||
if (route && eff_skill(u, SK_SAILING, from) >= 1) {
|
||||
produceexp(u, SK_SAILING, u->number);
|
||||
}
|
||||
}
|
||||
u = nu;
|
||||
}
|
||||
return sh;
|
||||
if (u->ship == sh) {
|
||||
if (!trail) {
|
||||
leave_trail(sh, from, to, route);
|
||||
trail=true;
|
||||
}
|
||||
if (from!=to) {
|
||||
u->ship = NULL; /* damit move_unit() kein leave() macht */
|
||||
move_unit(u, to, ulist);
|
||||
ulist = &u->next;
|
||||
u->ship = sh;
|
||||
}
|
||||
if (route && eff_skill(u, SK_SAILING, from) >= 1) {
|
||||
produceexp(u, SK_SAILING, u->number);
|
||||
}
|
||||
}
|
||||
if (*iunit==u) iunit=&u->next;
|
||||
}
|
||||
return sh;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1941,15 +1950,15 @@ age_traveldir(region *r)
|
|||
static direction_t
|
||||
hunted_dir(attrib *at, int id)
|
||||
{
|
||||
attrib *a = a_find(at, &at_traveldir_new);
|
||||
attrib *a = a_find(at, &at_traveldir_new);
|
||||
|
||||
while(a) {
|
||||
traveldir *t = (traveldir *)(a->data.v);
|
||||
if(t->no == id) return t->dir;
|
||||
a = a->nexttype;
|
||||
}
|
||||
while (a!=NULL) {
|
||||
traveldir *t = (traveldir *)(a->data.v);
|
||||
if (t->no == id) return t->dir;
|
||||
a = a->nexttype;
|
||||
}
|
||||
|
||||
return NODIRECTION;
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
static boolean
|
||||
|
@ -1963,67 +1972,66 @@ can_move(const unit * u)
|
|||
static int
|
||||
hunt(unit *u)
|
||||
{
|
||||
region *rc = u->region;
|
||||
int moves, id;
|
||||
char command[256];
|
||||
direction_t dir;
|
||||
region *rc = u->region;
|
||||
int moves, id;
|
||||
char command[256];
|
||||
direction_t dir;
|
||||
|
||||
if(!u->ship) {
|
||||
cmistake(u, findorder(u, u->thisorder), 144, MSG_MOVE);
|
||||
return 0;
|
||||
} else if(!fval(u, UFL_OWNER)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 146, MSG_MOVE);
|
||||
return 0;
|
||||
} else if(attacked(u)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 52, MSG_MOVE);
|
||||
return 0;
|
||||
} else if (!can_move(u)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 55, MSG_MOVE);
|
||||
return 0;
|
||||
}
|
||||
if(!u->ship) {
|
||||
cmistake(u, findorder(u, u->thisorder), 144, MSG_MOVE);
|
||||
return 0;
|
||||
} else if(!fval(u, UFL_OWNER)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 146, MSG_MOVE);
|
||||
return 0;
|
||||
} else if(attacked(u)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 52, MSG_MOVE);
|
||||
return 0;
|
||||
} else if (!can_move(u)) {
|
||||
cmistake(u, findorder(u, u->thisorder), 55, MSG_MOVE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
id = getshipid();
|
||||
id = getshipid();
|
||||
|
||||
if (id <= 0) {
|
||||
cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE);
|
||||
return 0;
|
||||
}
|
||||
if (id <= 0) {
|
||||
cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dir = hunted_dir(rc->attribs, id);
|
||||
dir = hunted_dir(rc->attribs, id);
|
||||
|
||||
if(dir == NODIRECTION) {
|
||||
ship * sh = findship(id);
|
||||
if (sh->region!=rc) {
|
||||
cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (dir == NODIRECTION) {
|
||||
ship * sh = findship(id);
|
||||
if (sh->region!=rc) {
|
||||
cmistake(u, findorder(u, u->thisorder), 20, MSG_MOVE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sprintf(command, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
||||
locale_string(u->faction->locale, directions[dir]));
|
||||
moves = 1;
|
||||
sprintf(command, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
||||
locale_string(u->faction->locale, directions[dir]));
|
||||
moves = 1;
|
||||
|
||||
rc = rconnect(rc, dir);
|
||||
while(moves < shipspeed(u->ship, u)
|
||||
&& (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) {
|
||||
strcat(command, " ");
|
||||
strcat(command, locale_string(u->faction->locale, directions[dir]));
|
||||
moves++;
|
||||
rc = rconnect(rc, dir);
|
||||
}
|
||||
rc = rconnect(rc, dir);
|
||||
while (moves < shipspeed(u->ship, u) && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION)
|
||||
{
|
||||
strcat(command, " ");
|
||||
strcat(command, locale_string(u->faction->locale, directions[dir]));
|
||||
moves++;
|
||||
rc = rconnect(rc, dir);
|
||||
}
|
||||
|
||||
/* In command steht jetzt das NACH-Kommando. */
|
||||
/* In command steht jetzt das NACH-Kommando. */
|
||||
|
||||
igetkeyword(command, u->faction->locale); /* NACH ignorieren und Parsing initialisieren. */
|
||||
igetkeyword(command, u->faction->locale); /* NACH ignorieren und Parsing initialisieren. */
|
||||
|
||||
/* NACH ausführen */
|
||||
if (move(u->region, u, false)!=0) {
|
||||
/* niemand sollte auf einen kapitän direkt ein folge haben, oder? */
|
||||
assert(1==0);
|
||||
}
|
||||
fset(u, UFL_LONGACTION); /* Von Hand setzen, um Endlosschleife zu vermeiden,
|
||||
wenn Verfolgung nicht erfolgreich */
|
||||
return 1; /* true -> Einheitenliste von vorne durchgehen */
|
||||
fset(u, UFL_LONGACTION); /* Von Hand setzen, um Endlosschleife zu vermeiden, wenn Verfolgung nicht erfolgreich */
|
||||
return 1; /* true -> Einheitenliste von vorne durchgehen */
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -23,53 +23,59 @@
|
|||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/** rolls a number of n-sided dice.
|
||||
* Usage: 3d6-3d4+5 = dice(3,6)-dice(3,4)+5 */
|
||||
int
|
||||
dice(int count, int value)
|
||||
{ /* Usage: 3d6-3d4+5 = dice(3,6)-dice(3,4)+5 */
|
||||
int d = 0, c;
|
||||
{
|
||||
int d = 0, c;
|
||||
|
||||
if (value<=0) return 0; /* (enno) %0 geht nicht. echt wahr. */
|
||||
if (count >= 0)
|
||||
for (c = count; c > 0; c--)
|
||||
d += rand() % value + 1;
|
||||
else
|
||||
for (c = count; c < 0; c++)
|
||||
d -= rand() % value + 1;
|
||||
if (value<=0) return 0; /* (enno) %0 geht nicht. echt wahr. */
|
||||
if (count >= 0)
|
||||
for (c = count; c > 0; c--)
|
||||
d += rand() % value + 1;
|
||||
else
|
||||
for (c = count; c < 0; c++)
|
||||
d -= rand() % value + 1;
|
||||
|
||||
return d;
|
||||
return d;
|
||||
}
|
||||
|
||||
/** Parses a string of the form "2d6+8"
|
||||
* Kann nur simple Strings der Form "xdy[+-]z" parsen!
|
||||
* Schöner wäre eine flexibele Routine, die z.B. auch Sachen wie 2d6+3d4-1
|
||||
* parsen kann. */
|
||||
int
|
||||
dice_rand(const char *s)
|
||||
{
|
||||
const char *c = s;
|
||||
int m = 0, d = 0, k = 0, multi = 1;
|
||||
int state = 1;
|
||||
const char *c = s;
|
||||
int m = 0, d = 0, k = 0, multi = 1;
|
||||
int state = 1;
|
||||
|
||||
for (;;) {
|
||||
if (isdigit((int)*c)) {
|
||||
k = k*10+(*c-'0');
|
||||
} else if (*c=='+' || *c=='-' || *c==0) {
|
||||
if (state==1) /* konstante k addieren */
|
||||
m+=k*multi;
|
||||
else if (state==2) { /* dDk */
|
||||
int i;
|
||||
if (k == 0) k = 6; /* 3d == 3d6 */
|
||||
for (i=0;i!=d;++i) m += (1 + rand() % k)*multi;
|
||||
}
|
||||
else assert(!"dice_rand: illegal token");
|
||||
k = d = 0;
|
||||
state = 1;
|
||||
multi = (*c=='-')?-1:1;
|
||||
} else if (*c=='d' || *c=='D') {
|
||||
if (k==0) k = 1; /* d9 == 1d9 */
|
||||
assert(state==1 || !"dice_rand: illegal token");
|
||||
d = k;
|
||||
k = 0;
|
||||
state=2;
|
||||
} else assert(!"dice_rand: illegal token");
|
||||
if (*c==0) break;
|
||||
c++;
|
||||
}
|
||||
return m;
|
||||
for (;;) {
|
||||
if (isdigit((int)*c)) {
|
||||
k = k*10+(*c-'0');
|
||||
} else if (*c=='+' || *c=='-' || *c==0) {
|
||||
if (state==1) /* konstante k addieren */
|
||||
m+=k*multi;
|
||||
else if (state==2) { /* dDk */
|
||||
int i;
|
||||
if (k == 0) k = 6; /* 3d == 3d6 */
|
||||
for (i=0;i!=d;++i) m += (1 + rand() % k)*multi;
|
||||
}
|
||||
else assert(!"dice_rand: illegal token");
|
||||
k = d = 0;
|
||||
state = 1;
|
||||
multi = (*c=='-')?-1:1;
|
||||
} else if (*c=='d' || *c=='D') {
|
||||
if (k==0) k = 1; /* d9 == 1d9 */
|
||||
assert(state==1 || !"dice_rand: illegal token");
|
||||
d = k;
|
||||
k = 0;
|
||||
state=2;
|
||||
} else assert(!"dice_rand: illegal token");
|
||||
if (*c==0) break;
|
||||
c++;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
* permission from the authors.
|
||||
*/
|
||||
|
||||
/* Kann nur simple Strings der Form "xdy[+-]z" parsen!
|
||||
* Schöner wäre eine flexibele Routine, die z.B. auch Sachen wie 2d6+3d4-1
|
||||
* parsen kann. */
|
||||
|
||||
#include <config.h>
|
||||
#include "rand.h"
|
||||
|
||||
|
@ -35,67 +31,65 @@
|
|||
#define drand() (((double)rand())/(double)RAND_MAX)
|
||||
#define M_PIl 3.1415926535897932384626433832795029L /* pi */
|
||||
|
||||
static double nv_next;
|
||||
static char valid_next = 0;
|
||||
|
||||
/* NormalRand aus python, random.py geklaut, dort ist Referenz auf
|
||||
* den Algorithmus. mu = Mittelwert, sigma = Standardabweichung. */
|
||||
|
||||
double nv_next;
|
||||
char valid_next = 0;
|
||||
|
||||
* den Algorithmus. mu = Mittelwert, sigma = Standardabweichung. */
|
||||
double
|
||||
normalvariate(double mu, double sigma)
|
||||
{
|
||||
double x2pi, g2rad, z;
|
||||
double t1, t2;
|
||||
double fac=1;
|
||||
static double mu_alt, sigma_alt;
|
||||
double x2pi, g2rad, z;
|
||||
double t1, t2;
|
||||
double fac=1;
|
||||
static double mu_alt, sigma_alt;
|
||||
|
||||
if(mu < 10) {
|
||||
fac=0.01;
|
||||
mu*=100;
|
||||
sigma*=100;
|
||||
}
|
||||
if(mu < 10) {
|
||||
fac=0.01;
|
||||
mu*=100;
|
||||
sigma*=100;
|
||||
}
|
||||
|
||||
if(mu_alt!=mu || sigma_alt!= sigma)
|
||||
valid_next=0;
|
||||
if(mu_alt!=mu || sigma_alt!= sigma)
|
||||
valid_next=0;
|
||||
|
||||
mu_alt=mu;
|
||||
sigma_alt=sigma;
|
||||
mu_alt=mu;
|
||||
sigma_alt=sigma;
|
||||
|
||||
if (valid_next == 0) {
|
||||
x2pi = drand() * 2.0L * M_PIl;
|
||||
t1 = drand();
|
||||
t1 = 1.0 - t1;
|
||||
t2 = log(t1);
|
||||
g2rad = sqrt(-2.0 * t2);
|
||||
z = cos(x2pi) * g2rad;
|
||||
nv_next = sin(x2pi) * g2rad;
|
||||
valid_next = 1;
|
||||
} else {
|
||||
z = nv_next;
|
||||
valid_next = 0;
|
||||
}
|
||||
return (fac*(mu + z*sigma)); /* mu thorin */
|
||||
if (valid_next == 0) {
|
||||
x2pi = drand() * 2.0L * M_PIl;
|
||||
t1 = drand();
|
||||
t1 = 1.0 - t1;
|
||||
t2 = log(t1);
|
||||
g2rad = sqrt(-2.0 * t2);
|
||||
z = cos(x2pi) * g2rad;
|
||||
nv_next = sin(x2pi) * g2rad;
|
||||
valid_next = 1;
|
||||
} else {
|
||||
z = nv_next;
|
||||
valid_next = 0;
|
||||
}
|
||||
return (fac*(mu + z*sigma)); /* mu thorin */
|
||||
}
|
||||
|
||||
int
|
||||
ntimespprob(int n, double p, double mod)
|
||||
{
|
||||
int count = 0;
|
||||
int i;
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
for(i=0; i<n && p>0; i++)
|
||||
if(drand() < p) {
|
||||
count++;
|
||||
p += mod;
|
||||
}
|
||||
|
||||
return count;
|
||||
for(i=0; i<n && p>0; i++) {
|
||||
if(drand() < p) {
|
||||
count++;
|
||||
p += mod;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
boolean
|
||||
chance(double x)
|
||||
{
|
||||
if (x>=1.0) return true;
|
||||
return (boolean) (rand() % RAND_MAX < RAND_MAX * x);
|
||||
return (boolean) (rand() % RAND_MAX < RAND_MAX * x);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int dice_rand(const char *str);
|
||||
extern int dice(int count, int value);
|
||||
extern double normalvariate(double mu, double sigma);
|
||||
extern int ntimespprob(int n, double p, double mod);
|
||||
extern boolean chance(double x);
|
||||
/* in dice.c: */
|
||||
extern int dice_rand(const char *str);
|
||||
extern int dice(int count, int value);
|
||||
|
||||
/* in rand.c: */
|
||||
extern double normalvariate(double mu, double sigma);
|
||||
extern int ntimespprob(int n, double p, double mod);
|
||||
extern boolean chance(double x);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,44 +1,46 @@
|
|||
<?xml version="1.0"?>
|
||||
<eressea xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="messages.xml"/>
|
||||
<xi:include href="messages.xml"/>
|
||||
|
||||
<comment>Localization</comment>
|
||||
<comment>Strings MUST always be read first</comment>
|
||||
<comment>Localization</comment>
|
||||
<comment>Strings MUST always be read first</comment>
|
||||
|
||||
<xi:include href="de/strings.xml"/>
|
||||
<xi:include href="en/strings.xml"/>
|
||||
<xi:include href="de/strings.xml"/>
|
||||
<xi:include href="en/strings.xml"/>
|
||||
|
||||
<xi:include href="races.xml"/>
|
||||
<xi:include href="resources.xml"/>
|
||||
<xi:include href="ships.xml"/>
|
||||
<xi:include href="buildings.xml"/>
|
||||
<xi:include href="races.xml"/>
|
||||
<xi:include href="resources.xml"/>
|
||||
<xi:include href="ships.xml"/>
|
||||
<xi:include href="buildings.xml"/>
|
||||
|
||||
<game name="Wettstreit der Weisen" units="250" welcome="vinyambar">
|
||||
<comment>Game specific</comment>
|
||||
<order name="ARBEITEN" disable="yes"/>
|
||||
<order name="MEINUNG" disable="yes"/>
|
||||
<order name="MAGIEGEBIET" disable="yes"/>
|
||||
<param name="entertain.base" value="15"/>
|
||||
<param name="entertain.perlevel" value="5"/>
|
||||
<param name="nmr.timeout" value="5"/>
|
||||
<param name="nmr.removenewbie" value="0"/>
|
||||
<param name="GiveRestriction" value="0"/>
|
||||
<param name="database.gameid" value="3"/>
|
||||
<param name="hunger.long" value="0"/>
|
||||
<param name="allied.skilllimit" value="15"/>
|
||||
</game>
|
||||
<game name="Wettstreit der Weisen" units="250" welcome="vinyambar">
|
||||
<comment>Game specific</comment>
|
||||
<order name="ARBEITEN" disable="yes"/>
|
||||
<order name="MEINUNG" disable="yes"/>
|
||||
<order name="MAGIEGEBIET" disable="yes"/>
|
||||
<param name="entertain.base" value="15"/>
|
||||
<param name="entertain.perlevel" value="5"/>
|
||||
<param name="nmr.timeout" value="5"/>
|
||||
<param name="nmr.removenewbie" value="0"/>
|
||||
<param name="GiveRestriction" value="0"/>
|
||||
<param name="database.gameid" value="3"/>
|
||||
<param name="hunger.long" value="0"/>
|
||||
<param name="allied.skilllimit" value="15"/>
|
||||
<param name="atsroi.ats" value="2"/>
|
||||
<param name="atsroi.roi" value="4"/>
|
||||
</game>
|
||||
|
||||
<xi:include href="vinyambar/wdw-strings.xml"/>
|
||||
<xi:include href="vinyambar/wdw-resources.xml" />
|
||||
<xi:include href="vinyambar/wdw-races.xml"/>
|
||||
<xi:include href="vinyambar/de/strings.xml"/>
|
||||
<xi:include href="vinyambar/wdw-strings.xml"/>
|
||||
<xi:include href="vinyambar/wdw-resources.xml" />
|
||||
<xi:include href="vinyambar/wdw-races.xml"/>
|
||||
<xi:include href="vinyambar/de/strings.xml"/>
|
||||
|
||||
<strings>
|
||||
<string name="mailto">
|
||||
<text locale="de">vinyambar@eressea.amber.kn-bremen.de</text>
|
||||
</string>
|
||||
<string name="mailcmd">
|
||||
<text locale="de">WDW BEFEHLE</text>
|
||||
</string>
|
||||
</strings>
|
||||
<strings>
|
||||
<string name="mailto">
|
||||
<text locale="de">vinyambar@eressea.amber.kn-bremen.de</text>
|
||||
</string>
|
||||
<string name="mailcmd">
|
||||
<text locale="de">WDW BEFEHLE</text>
|
||||
</string>
|
||||
</strings>
|
||||
</eressea>
|
||||
|
|
Loading…
Reference in New Issue