diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index 1d91cc546..b06812d3e 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -203,18 +203,22 @@ free_mage(attrib * a) static int read_mage(attrib * a, FILE * F) { - int i; + int i, mtype; sc_mage * mage = (sc_mage*)a->data.v; spell_ptr ** sp = &mage->spellptr; - fscanf(F, "%d %d %d", &mage->magietyp, &mage->spellpoints, &mage->spchange); + fscanf(F, "%d %d %d", &mtype, &mage->spellpoints, &mage->spchange); + mage->magietyp = (magic_t)mtype; for (i=0;i!=MAXCOMBATSPELLS;++i) { - fscanf (F, "%d %d", &mage->combatspell[i], &mage->combatspelllevel[i]); + int spid; + fscanf (F, "%d %d", &spid, &mage->combatspelllevel[i]); + mage->combatspell[i] = (spellid_t)spid; } for (;;) { - fscanf (F, "%d", &i); - if (i < 0) break; - *sp = calloc (sizeof(spell_ptr), 1); - (*sp)->spellid = (spellid_t)i; + int spid; + fscanf (F, "%d", &spid); + if (spid < 0) break; + *sp = calloc (sizeof(spell_ptr), 1); + (*sp)->spellid = (spellid_t)spid; sp = &(*sp)->next; } return AT_READ_OK; diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 00310e617..617f9e716 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -1081,7 +1081,7 @@ travel(region * first, unit * u, region * next, int flucht) k -= BP_NORMAL; if (k<0) break; /* r2 -> Zielregion, r3 -> Momentane Region */ - if (dir>=0 && move_blocked(u, current, dir) + if ((dir>=0 && move_blocked(u, current, dir)) || curse_active(get_curse(current->attribs, fogtrap_ct))) { ADDMSG(&u->faction->msgs, msg_message("leavefail", diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index b6419fcd9..cefed6ff4 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -144,44 +144,6 @@ curse_emptiness(void) return 0; } -static int -convert_orders(void) -{ - region * r; - for (r=regions;r;r=r->next) { - unit * u; - for (u=r->units;u;u=u->next) { - strlist * o; - for (o=u->orders;o;o=o->next) { - int c = igetkeyword(o->s, u->faction->locale); - switch (c) { - case K_RESERVE: - case K_BUY: - case K_SELL: - case K_CAST: - sprintf(buf, "@%s", LOC(u->faction->locale, keywords[c])); - for (;;) { - const char * c = getstrtoken(); - if (c && *c) { - char * p = strchr(c, ' '); - if (p) { - char zText[128]; - c = strcpy(zText, c); - space_replace(zText, SPACE_REPLACEMENT); - } - strcat(buf, " "); - strcat(buf, c); - } else break; - } - set_string(&o->s, buf); - break; - } - } - } - } - return 0; -} - void french_testers(void) { @@ -1056,44 +1018,6 @@ update_gms(void) } } -static int -fix_gms(void) -{ - faction * f; - for (f=factions;f;f=f->next) { - attrib * permissions = a_find(f->attribs, &at_permissions); - if (permissions) { - const char * keys[] = { "gmgate", "gmmsgr", "gmmsgr", "gmmsgu", NULL }; - int k; - item_t i; - for (k=0;keys[k];++k) { - attrib * a = find_key((attrib*)permissions->data.v, atoi36("gmgate")); - if (a) { - attrib ** ap = &a->nexttype; - while (*ap) { - attrib * an = *ap; - if (a->data.i==an->data.i) a_remove(ap, an); - else ap = &an->next; - } - } - } - for (i=I_GREATSWORD;i!=I_KEKS;++i) { - attrib * a = a_find(permissions, &at_gmcreate); - while (a && a->data.v!=(void*)olditemtype[i]) a=a->nexttype; - if (a) { - attrib ** ap = &a->nexttype; - while (*ap) { - attrib * an = *ap; - if (a->data.v==an->data.v) a_remove(ap, an); - else ap = &an->next; - } - } - } - } - } - return 0; -} - #if 1 static int fix_demand(void) @@ -1439,47 +1363,6 @@ fix_herbtypes(void) } #endif -static int -fix_plainherbs(void) -{ -#define WINDOWSIZE 120 -#define DEVIATION 1.1 - herb_t window[WINDOWSIZE]; - int wbegin=0, wend=0; - region *r; - int c; - int count[6]; - for (c=0;c!=6;++c) count[c]=0; - for (r=regions;r;r=r->next) { - herb_t herb; - int wnext=(wend+1) % WINDOWSIZE; - const char * name; - terrain_t t = rterrain(r); - if (t!=T_PLAIN) continue; - name = LOC(default_locale, rherbtype(r)->itype->rtype->_name[0]); - for (herb=0;herb!=6;++herb) { - if (strcmp(terrain[t].herbs[herb], name)==0) break; - } - assert(herb!=6); - if (count[herb] > (wend+WINDOWSIZE-wbegin)%WINDOWSIZE/6*DEVIATION) { - const struct herb_type * htype; - do { - herb = rand() % 6; - } while (count[herb] > (wend+WINDOWSIZE-wbegin)%WINDOWSIZE/6*DEVIATION); - htype = resource2herb(finditemtype(terrain[t].herbs[herb], default_locale)->rtype); - rsetherbtype(r, htype); - } - ++count[herb]; - window[wend]=herb; - if (wbegin==wnext) { - --count[window[wbegin]]; - wbegin = (wbegin+1)%WINDOWSIZE; - } - wend = wnext; - } - return 0; -} - #ifdef SKILLFIX_SAVE typedef struct skillfix_data { unit * u; @@ -1825,50 +1708,6 @@ resize_plane(struct plane * p, int radius) return 0; } -static int -regatta_quest(void) -{ - plane * p = getplanebyname("Regatta"); - if (p) { - fset(p, PFL_NOMONSTERS); - fset(p, PFL_SEESPECIAL); - return resize_plane(p, 40); -#ifdef REGATTA_QUESTMASTER /* "gregorjochmann@gmx.de" */ - } else { - region * center; - p = gm_addplane(40, PFL_NORECRUITS|PFL_NOMONSTERS|PFL_SEESPECIAL, "Regatta"); - center = findregion(p->minx+(p->maxx-p->minx)/2, p->miny+(p->maxy-p->miny)/2); - gm_addfaction(REGATTA_QUESTMASTER, p, center); -#endif - } - return 0; -} - -static int -zero_quest(void) -{ - const char * name = "Sergint Saiquent"; - plane * p = getplanebyname(name); -#ifdef ZEROFOKS_QUESTMASTER /* "gregorjochmann@gmx.de" */ - if (p==NULL) { - region * center; - p = gm_addplane(4, 0, name); - center = findregion(p->minx+(p->maxx-p->minx)/2, p->miny+(p->maxy-p->miny)/2); - gm_addfaction(ZEROFOKS_QUESTMASTER, p, center); - return 0; - } -#endif - if (p!=NULL) { - fset(p, PFL_NORECRUITS); - fset(p, PFL_NOMAGIC); - fset(p, PFL_NOFEED); - fset(p, PFL_NOSTEALTH); - fset(p, PFL_NOMONSTERS); - return resize_plane(p, 4); - } - return 0; -} - static int secondfaction(faction * pf) { @@ -2054,205 +1893,9 @@ init_resourcefix(void) at_register(&at_resources); } -static int -read_resfix(void) -{ -#if 0 - FILE * F = fopen("resource.fix", "r"); - if (F==NULL) return; - while (!feof(F)) { - int x, y, stone, iron, laen, age; - int lstone, liron, llaen; /* level */ - region * r; - fscanf(F, "%d %d %d %d %d %d %d %d %d\n", &x, &y, &age, &stone, &iron, &laen, &lstone, &liron, &llaen); - r = findregion(x, y); - if (r) { - rawmaterial * rm = r->resources; - while (rm) { - if (rm->type==&rm_iron && liron>0) { - rm->amount = iron; - rm->level = liron; - } - else if (rm->type==&rm_laen && llaen>0) { - rm->amount = laen; - rm->level = llaen; - } - else if (rm->type==&rm_stones && lstone>0) { - rm->amount = stone; - rm->level = lstone; - } - rm = rm->next; - } - r->age = (unsigned short)age; - } - } - fclose(F); -#else - return -1; -#endif -} - -static int -convert_resources(void) -{ -#if 0 - region *r; - - for(r=regions;r;r=r->next) { - attrib *a = a_find(r->attribs, &at_resources); - r->resources = 0; - terraform_resources(r); - - if (a==NULL) continue; - else { - int INIT_STONE = 20; /* skip this many weeks */ - double ironmulti = 0.40; - double laenmulti = 0.50; - double stonemulti = 0.30; /* half the stones used */ - rawmaterial * rmiron = rm_get(r, rm_iron.rtype); - rawmaterial * rmlaen = rm_get(r, rm_laen.rtype); - rawmaterial * rmstone = rm_get(r, rm_stones.rtype); - - int oldiron; - int oldlaen = MAXLAENPERTURN * min(r->age, 100) / 2; - int oldstone = terrain[rterrain(r)].quarries * max(0, r->age - INIT_STONE); - int iron = a->data.sa[0]; - int laen = a->data.sa[1]; - int stone, level; - int i, base; - - /** STONE **/ - for (i=0;terrain[r->terrain].rawmaterials[i].type;++i) { - if (terrain[r->terrain].rawmaterials[i].type == &rm_stones) break; - } - if (terrain[r->terrain].rawmaterials[i].type) { - base = terrain[r->terrain].rawmaterials[i].base; - stone = max (0, (int)(oldstone * stonemulti)); - level = 1; - base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor)); - while (stone >= base) { - stone-=base; - ++level; - base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor)); - } - rmstone->level = level; - rmstone->amount = base - stone; - assert (rmstone->amount > 0); - log_printf("CONVERSION: %d stones @ level %d in %s\n", rmstone->amount, rmstone->level, regionname(r, NULL)); - } else { - log_error(("found stones in %s of %s\n", terrain[r->terrain].name, regionname(r, NULL))); - } - - /** IRON **/ - if (r_isglacier(r) || r->terrain==T_ICEBERG) { - oldiron = GLIRONPERTURN * min(r->age, 100) / 2; - } else { - oldiron = IRONPERTURN * r->age; - } - for (i=0;terrain[r->terrain].rawmaterials[i].type;++i) { - if (terrain[r->terrain].rawmaterials[i].type == &rm_iron) break; - } - if (terrain[r->terrain].rawmaterials[i].type) { - base = terrain[r->terrain].rawmaterials[i].base; - iron = max(0, (int)(oldiron * ironmulti - iron )); - level = 1; - base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor)); - while (iron >= base) { - iron-=base; - ++level; - base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor)); - } - rmiron->level = level; - rmiron->amount = base - iron; - assert (rmiron->amount > 0); - log_printf("CONVERSION: %d iron @ level %d in %s\n", rmiron->amount, rmiron->level, regionname(r, NULL)); - } else { - log_error(("found iron in %s of %s\n", terrain[r->terrain].name, regionname(r, NULL))); - } - - /** LAEN **/ - if (laen>=0) { - if (rmlaen==NULL) { - rmlaen = calloc(sizeof(rawmaterial), 1); - rmlaen->next = r->resources; - r->resources = rmlaen; - } - for (i=0;terrain[r->terrain].rawmaterials[i].type;++i) { - if (terrain[r->terrain].rawmaterials[i].type == &rm_laen) break; - } - if (terrain[r->terrain].rawmaterials[i].type) { - laen = max(0, (int)(oldlaen * laenmulti - laen)); - level = 1; - base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor)); - while (laen >= base) { - laen-=base; - ++level; - base = (int)(terrain[r->terrain].rawmaterials[i].base*(1+level*terrain[r->terrain].rawmaterials[i].divisor)); - } - rmlaen->level = level; - rmlaen->amount = base - laen; - assert(rmlaen->amount>0); - log_printf("CONVERSION: %d laen @ level %d in %s\n", rmlaen->amount, rmlaen->level, regionname(r, NULL)); - rmlaen = NULL; - } - } - if (rmlaen) { - struct rawmaterial *res; - struct rawmaterial ** pres = &r->resources; - if (laen!=-1) log_error(("found laen in %s of %s\n", terrain[r->terrain].name, regionname(r, NULL))); - while (*pres!=rmlaen) pres = &(*pres)->next; - res = *pres; - *pres = (*pres)->next; - free(res); - } -#ifndef NDEBUG - { - rawmaterial * res = r->resources; - while (res) { - assert(res->amount>0); - assert(res->level>0); - res = res->next; - } - } -#endif - } - } - return 0; -#else - return -1; -#endif -} - #endif #if 0 -static int -convert_resources(void) -{ - region *r; - attrib *a; - - for(r=regions;r;r=r->next) { - - /* Iron */ - if(rterrain(r) == T_MOUNTAIN) { - a_add(&r->attribs, a_new(&at_iron))->data.i = 25; - } else if(rterrain(r) == T_GLACIER || rterrain(r) == T_ICEBERG_SLEEP) { - a_add(&r->attribs, a_new(&at_iron))->data.i = 2; - } - /* Laen */ - if(rterrain(r) == T_MOUNTAIN) { - a = a_find(r->attribs, &at_laen); - if(a) a->data.i = 6; - } - /* Stone */ - if(terrain[rterrain(r)].quarries > 0) { - a_add(&r->attribs, a_new(&at_stone))->data.i = terrain[rterrain(r)].quarries; - } - } - return 0; -} - static void fix_negpotion(void) { @@ -2342,268 +1985,6 @@ fix_gates(void) } } -static int -dump_sql(void) -{ - faction * f; - if (sqlstream) for (f=factions;f;f=f->next) { - if (f->subscription==0) { - /* fprintf(sqlstream,) */ - } - } - return 0; -} - -#if NEW_RESOURCEGROWTH -static int -randomized_resources(void) -{ - region *r; - - for(r = regions; r; r=r->next) if(r->land) { - terrain_t ter = rterrain(r); - - /* Dieses if verhindert, das Laen nocheinmal verteilt wird. */ - if(ter == T_MOUNTAIN || ter == T_GLACIER || ter == T_ICEBERG || ter == T_ICEBERG_SLEEP) continue; - - terraform_resources(r); - } - return 0; -} -#endif - -static int -fix_idleout(void) -{ - faction *f; - - f = findfaction(0); - if(f){ - fset(f, FFL_NOIDLEOUT); - } - f = findfaction(atoi36("muse")); - if(f){ - fset(f, FFL_NOIDLEOUT); - } - return 0; -} - -static int -set_zip(void) -{ - faction *f; - for(f=factions;f;f=f->next) { - if(!(f->options & (1 << O_BZIP2)) && !(f->options & (1 << O_COMPRESS))) { - f->options = f->options | (1 << O_COMPRESS); - } - } - - f = findfaction(0); - f->options = f->options & ~(1 << O_COMPRESS); - f->options = f->options | (1 << O_BZIP2); - - return 0; -} - -static int -heal_all(void) -{ - region *r; - unit *u; - faction *f; - message *msg = msg_message("healall",""); - - for(f=factions; f; f=f->next) { - freset(f, FL_DH); - } - - for(r=regions; r; r=r->next) { - for(u=r->units;u;u=u->next) { - int max_hp = unit_max_hp(u) * u->number; - if(u->hp < max_hp) { - u->hp = max_hp; - fset(u->faction, FL_DH); - } - } - } - - for (f=factions; f; f=f->next) { - if(fval(f,FL_DH)) { - add_message(&f->msgs, msg); - freset(f, FL_DH); - } - } - - msg_release(msg); - return 0; -} - -#if PEASANT_ADJUSTMENT == 1 - -#define WEIGHT ((double)0.5) -#define PLWEIGHT ((double)0.80) - -static int -peasant_adjustment(void) -{ - terrain_t ter; - int sum, avg, c; - double freeall, pool; /* long long is illegal */ - double s; - region *r; - - s = 0; - for(r=regions; r; r=r->next) { - s += rpeasants(r); - } - log_printf("BAUERN vorher: %lld\n",s); - - for(ter = 0; ter < MAXTERRAINS; ter++) { - if(terrain[ter].production_max <= 0) continue; - - c = 0; - sum = 0; - pool = 0; - freeall = 0; - - for(r=regions; r; r=r->next) if(rterrain(r) == ter) { - unit *u; - - c++; - sum += rpeasants(r); - for(u = r->units; u; u=u->next) { - if(lifestyle(u) > 0) sum += u->number; - /* Sonderregel Bauernmob */ - if (u->race == new_race[RC_PEASANT]) sum += u->number; - } - } - if (c==0) continue; - avg = sum/c; - - for(r=regions; r; r=r->next) if(rterrain(r) == ter) { - unit *u; - int playerp = 0; - int p_weg; - int soll; - - for(u = r->units; u; u=u->next) { - if(lifestyle(u) > 0) playerp += u->number; - /* Sonderregel Bauernmob */ - if (u->race == new_race[RC_PEASANT]) playerp += u->number; - } - - soll = (int)((avg + playerp + rpeasants(r)) * WEIGHT); - - if(playerp * PLWEIGHT + rpeasants(r) > soll) { - p_weg = (int)(min(((playerp * PLWEIGHT) + rpeasants(r)) - soll, rpeasants(r))); - assert(p_weg >= 0); - if (p_weg > 0){ - log_printf("BAUERN %s: war %d, minus %d, playerp %d\n", - regionname(r, NULL), rpeasants(r), p_weg, playerp); - } - pool += p_weg; - rsetpeasants(r, rpeasants(r) - p_weg); - assert(rpeasants(r) >= 0); - } - - freeall += max(0,production(r) * MAXPEASANTS_PER_AREA - - ((rtrees(r,2)+rtrees(r,1)/2) * TREESIZE) - playerp); - } - - for(r=regions; r; r=r->next) if(rterrain(r) == ter) { - unit *u; - double free; - int newp; - int playerp = 0; - - for(u = r->units; u; u=u->next) { - if(lifestyle(u) > 0) playerp += u->number; - /* Sonderregel Bauernmob */ - if (u->race == new_race[RC_PEASANT]) playerp += u->number; - } - - free = max(0,production(r) * MAXPEASANTS_PER_AREA - - ((rtrees(r,2)+rtrees(r,1)/2) * TREESIZE) - playerp); - - newp = (int)((pool * free)/freeall); - - rsetpeasants(r, rpeasants(r)+newp); - - assert(rpeasants(r) >= 0); - } - } - - s = 0; - for(r=regions; r; r=r->next) { - s += rpeasants(r); - } - log_printf("BAUERN nachher: %lld\n",s); - - return 0; -} - -static int -orc_conversion2(void) -{ - faction *f; - unit *u; - region *r; - - for(f=factions; f; f=f->next) { - if(f->race == new_race[RC_ORC]) { - f->race = new_race[RC_URUK]; - } - } - - for(r=regions; r; r=r->next) { - for(u=r->units; u; u=u->next) { - if (u->race==new_race[RC_ORC] || u->race==new_race[RC_SNOTLING]) { - /* convert to either uruk or snotling */ - if (has_skill(u, SK_MAGIC) || has_skill(u, SK_ALCHEMY)) { - u->race = new_race[RC_URUK]; - u->irace = new_race[RC_URUK]; - } - } - } - } - - return 0; -} - -static int -orc_conversion(void) -{ - faction *f; - unit *u; - region *r; - - for(f=factions; f; f=f->next) { - if(f->race == new_race[RC_ORC]) { - f->race = new_race[RC_URUK]; - } - } - - for(r=regions; r; r=r->next) { - for(u=r->units; u; u=u->next) { - if(u->race == new_race[RC_ORC]) { - /* convert to either uruk or snotling */ - if(effskill(u, SK_MAGIC) >= 1 - || effskill(u, SK_ALCHEMY) >= 1 - || get_item(u, I_CHASTITY_BELT) >= u->number) { - u->race = new_race[RC_URUK]; - u->irace = new_race[RC_URUK]; - } else { - u->race = new_race[RC_SNOTLING]; - u->irace = new_race[RC_SNOTLING]; - } - } - } - } - - return 0; -} -#endif - static int fix_astralplane(void) { @@ -2661,43 +2042,6 @@ fix_astralplane(void) return 0; } -static int -fix_watchers(void) -{ - plane * p = getplanebyid (1094969858); - if (p) { - faction * f = findfaction(atoi36("rega")); - watcher * w = calloc(sizeof(watcher), 1); - w->faction = f; - w->mode = see_unit; - w->next = p->watchers; - p->watchers = w; - } - return 0; -} - -static int -fix_questcoors(void) -{ - plane * p = getplanebyid (59034966); - if (p) { - faction * f; - region * eternath = findregion(-8750, 3631); - if (eternath) for (f=factions;f;f=f->next) { - ursprung * u = f->ursprung; - while (u) { - if (u->id == p->id) { - u->x = 0; - u->y = 0; - break; - } - u=u->next; - } - } - } - return 0; -} - static int warn_password(void) { @@ -2720,84 +2064,6 @@ warn_password(void) return 0; } -static int -fix_seeds(void) -{ - region *r; - - for(r=regions; r; r=r->next) { - if(rtrees(r,0) > 25 && rtrees(r,0) > rtrees(r,2)/2) { - rsettrees(r,0,rtrees(r,2)/2); - } - } - - return 0; -} - -static int -guard_conversion(void) -{ - faction *f; - unit *u; - int mask = GUARD_CREWS | GUARD_LANDING | GUARD_TRAVELTHRU | GUARD_TAX; - - for(f=factions; f; f=f->next) { - for(u=f->units; u; u=u->nextF) { - int g = getguard(u); - - if( (g & mask) == mask) { - setguard(u, g | GUARD_PRODUCE | GUARD_RECRUIT); - } - } - } - - return 0; -} - -static int -questportal_init(void) -{ - region *r1 = findregion(43,-39); - region *r2 = findregion(44,-39); - border *bo; - unit *u; - - if(r1 == NULL || r2 == NULL) return 0; - bo = new_border(&bt_questportal, r1, r2); - bo->data = (void *)3; - - u = findunit(atoi36("L0sc")); - if(u) i_change(&u->items, &it_questkey1, 1); - - u = findunit(atoi36("xi7m")); - if(u) i_change(&u->items, &it_questkey2, 1); - return 0; -} - -static int -xe_init(void) -{ - faction *f = findfaction(atoi36("a5q")); - - if(f) { - a_add(&f->attribs, a_new(&at_xontormiaexpress)); - } - - return 0; -} - -static int -fix_restart_flag(void) -{ - faction *f; - - for(f=factions; f; f=f->next) { - freset(f, FFL_RESTART); - } - - return 0; -} - extern border *borders[]; static void @@ -2838,21 +2104,6 @@ fix_road_borders(void) } } -static int -give_cammo(void) -{ - faction *f; - unit *u; - - for(f=factions; f; f=f->next) { - for(u=f->units; u; u=u->nextF) { - i_change(&u->items, &it_catapultammo, i_get(u->items, olditemtype[I_CATAPULT])*2); - } - } - - return 0; -} - #ifdef WDW_PHOENIX static region * random_land_region(void)