char * loc_inside_string(int where) { char *name = NULL; char *trail = NULL; if (loc_depth(where) > LOC_region) { trail = loc_inside_string(loc(where)); }; switch (loc_depth(where)) { case LOC_region: name = just_name(region(where)); break; case LOC_province: if (!valid_box(where)) name = sout("adrift in the Cosmos"); else name = box_name(where); break; default: name = box_name(where); }; if (trail != NULL) return sout(", in %s%s", name, trail); return sout(", in %s", name); };
int is_port_city(int where) { int p; int n, s, e, w; if (subkind(where) != sub_city) return FALSE; assert(loc_depth(where) == LOC_subloc); p = province(where); if (subkind(p) == sub_mountain) return FALSE; n = location_direction(p, DIR_N); s = location_direction(p, DIR_S); e = location_direction(p, DIR_E); w = location_direction(p, DIR_W); if ((n && subkind(n) == sub_ocean) || (s && subkind(s) == sub_ocean) || (e && subkind(e) == sub_ocean) || (w && subkind(w) == sub_ocean)) return TRUE; return FALSE; }
int building_owner(int where) { assert(loc_depth(where) == LOC_build); return first_character(where); }
int region(int who) { while (who > 0 && (kind(who) != T_loc || loc_depth(who) != LOC_region)) who = loc(who); return who; }
int province(int who) { if (item_unique(who)) who = item_unique(who); while (who > 0 && (kind(who) != T_loc || loc_depth(who) != LOC_province)) who = loc(who); return who; }
char * loc_inside_string(int where) { char *reg_name; if (loc_depth(where) == LOC_build) { if (subkind(loc(where)) == sub_ocean) return sout(", in %s", box_name(province(where))); if (loc_depth(loc(where)) == LOC_province) return sout(", in province %s", box_name(province(where))); return sout(", in %s", box_name(province(where))); } else if (loc_depth(where) == LOC_subloc) { if (subkind(province(where)) == sub_ocean) return sout(", in %s", box_name(province(where))); else if (!valid_box(province(where))) return sout(", adrift in the Cosmos"); else return sout(", in province %s", box_name(province(where))); } else if (subkind(where) == sub_ocean) { reg_name = name(region(where)); if (reg_name && *reg_name) return sout(", in %s", reg_name); return ""; } else { reg_name = name(region(where)); if (reg_name && *reg_name) return sout(", in %s", reg_name); return ""; } }
int viewloc(int who) { while (who > 0 && loc_depth(who) != LOC_province && subkind(who) != sub_guild && subkind(who) != sub_city && subkind(who) != sub_graveyard && subkind(who) != sub_faery_hill) { who = loc(who); } return who; }
char * loc_civ_s(int where) { int n; if (loc_depth(where) != LOC_province || subkind(where) == sub_ocean || in_faery(where) || in_hades(where)) { return ""; } n = has_item(where, item_peasant); if (n < 100) return ", wilderness"; return sout(", peasants: %d", n); }
static char * liner_desc_loc(int n) { char buf[LEN]; sprintf(buf, "%s%s%s", box_name_kind(n), safe_haven_s(n), incomplete_string(n)); if (loc_depth(n) == LOC_province && rp_loc(n) && province_admin(n)) { if (rp_loc(n)->control.nobles) { strcat(buf, sout(", entrance fee %s per noble", gold_s(rp_loc(n)->control.nobles))); }; if (rp_loc(n)->control.weight) { strcat(buf, sout(", entrance fee %s per 1000 weight", gold_s(rp_loc(n)->control.weight))); }; if (rp_loc(n)->control.men) { strcat(buf, sout(", entrance fee %s per 100 men", gold_s(rp_loc(n)->control.men))); }; }; if (rp_subloc(n) && first_character(n)) { if (rp_subloc(n)->control.nobles) { strcat(buf, sout(", entrance fee %s per noble", gold_s(rp_subloc(n)->control.nobles))); }; if (rp_subloc(n)->control.weight) { strcat(buf, sout(", entrance fee %s per 1000 weight", gold_s(rp_subloc(n)->control.weight))); }; if (rp_subloc(n)->control.men) { strcat(buf, sout(", entrance fee %s per 100 men", gold_s(rp_subloc(n)->control.men))); }; }; if (loc_depth(n) == LOC_province && rp_loc(n) && province_admin(n)) { if (rp_loc(n)->control.closed) { strcat(buf, sout(", border closed")); }; }; if (rp_subloc(n) && first_character(n)) { if (rp_subloc(n)->control.closed) { strcat(buf, sout(", closed")); }; }; if (entrance_size(n)) { strcat(buf, sout(", entrance size: %d", entrance_size(n))); }; if (loc_depth(n) == LOC_build) { if (loc_defense(n)) strcat(buf, sout(", defense~%d", loc_defense(n))); if (get_effect(n, ef_improve_fort, 0, 0)) strcat(buf, sout(", magical defense~%d", get_effect(n, ef_improve_fort, 0, 0))); if (loc_moat(n)) strcat(buf, ", with moat"); if (loc_damage(n)) strcat(buf, sout(", %d%%~damaged", (100 * loc_damage(n)) / loc_hp(n))); } if (show_display_string) { char *s = banner(n); if (s && *s) strcat(buf, sout(", \"%s\"", s)); } if (loc_hidden(n)) strcat(buf, ", hidden"); if (subkind(n) == sub_mine_shaft) { struct entity_mine *mi = get_mine_info(n); if (mine_depth(n)) strcat(buf, sout(", depth~%d feet", (mine_depth(n) * 100) + 100)); if (mi) switch (mi->shoring[mine_depth(n)]) { case WOODEN_SHORING: strcat(buf, sout(", wooden shoring")); break; case IRON_SHORING: strcat(buf, sout(", iron shoring")); break; case NO_SHORING: default: strcat(buf, sout(", no shoring")); break; }; }; if (loc_depth(n) == LOC_subloc) { if (subkind(n) == sub_hades_pit) strcat(buf, ", 28 days"); else if (subkind(n) != sub_mine_shaft && subkind(n) != sub_mine_shaft_notdone) strcat(buf, ", 1 day"); } return sout("%s", buf); }
int exit_distance(int loc1, int loc2) { int dist; int w_d; /* where depth */ int d_d; /* dest depth */ if (subkind(loc1) == sub_hades_pit || subkind(loc2) == sub_hades_pit) return 28; if (loc_depth(loc1) > loc_depth(loc2)) { int tmp; tmp = loc1; loc1 = loc2; loc2 = tmp; } w_d = loc_depth(loc1); d_d = loc_depth(loc2); if (d_d == LOC_build) return 0; if (d_d == LOC_subloc) return 1; #if 0 /* * water-land links */ if (subkind(loc1) == sub_ocean && subkind(loc2) != sub_ocean) { if (loc_sea_lane(loc1)) return 2; return 3; } if (subkind(loc1) != sub_ocean && subkind(loc2) == sub_ocean) { if (loc_sea_lane(loc2)) return 2; return 3; } #else /* * water-land links are distance=2 */ if (subkind(loc1) == sub_ocean && subkind(loc2) != sub_ocean) return 2; if (subkind(loc1) != sub_ocean && subkind(loc2) == sub_ocean) return 2; #endif /* * Linked sublocs between regions */ if (province(loc1) != province(loc2)) { loc1 = province(loc1); loc2 = province(loc2); } switch (subkind(loc2)) { case sub_ocean: if (loc_sea_lane(loc1) && loc_sea_lane(loc2)) dist = 2; else dist = 3; break; case sub_mountain: dist = 10; break; case sub_forest: dist = 8; break; case sub_swamp: dist = 14; break; case sub_desert: dist = 8; break; case sub_plain: dist = 7; break; case sub_under: dist = 7; break; case sub_cloud: dist = 7; break; case sub_tunnel: dist = 5; break; case sub_chamber: dist = 5; break; default: fprintf(stderr, "exit_distance: subkind=%s, loc1=%d, loc2=%d, " "w_d=%d, d_d=%d\n", subkind_s[subkind(loc2)], loc1, loc2, w_d, d_d); assert(FALSE); } return dist; }
void location_production() { int where; int i, enclosed; int terr, encl_terr; int has_city; float pop_grow = 0.0; int pop_limit = 200, pop, dpop = 0; loop_loc(where) { terr = subkind(where); has_city = 0; for (i = 0; terr_prod[i].terr; i++) if (terr_prod[i].terr == terr) { replenish(where, terr_prod[i].item, terr_prod[i].qty, terr_prod[i].max); } /* * Mon Sep 16 11:42:22 1996 -- Scott Turner * * Now check for production from enclosed locations... * */ loop_here(where, enclosed) { encl_terr = subkind(enclosed); if (encl_terr == sub_city) has_city = 1; for (i = 0; terr_prod2[i].terr; i++) if (terr_prod2[i].terr == encl_terr) { replenish(where, terr_prod2[i].item, terr_prod2[i].qty, terr_prod2[i].max); }; } next_here; /* * First limit poppy fields to normal production level. * Then double opium if poppy field was specially tended. */ if (terr == sub_poppy_field) { int n; n = has_item(where, item_opium); if (n > POPPY_OPIUM) consume_item(where, item_opium, n - POPPY_OPIUM); if (rp_misc(where) && rp_misc(where)->opium_double) { rp_misc(where)->opium_double = FALSE; gen_item(where, item_opium, has_item(where, item_opium)); } } if (terr == sub_island || (loc_depth(where) == LOC_province && has_ocean_access(where))) replenish(where, item_flotsam, 30, 30); /* * Sun Dec 1 10:34:41 1996 -- Scott Turner * * Peasant production. Depends upon the location (and * whether it contains a city). * * Has_city is set up above... * * Tue Sep 22 13:20:18 1998 -- Scott Turner * * Faery ought not have peasants. It should have (I guess) * elf peasants, although what you can do with those is * open to conjecture :-) * */ if (pop = has_item(where, item_peasant)) { if (has_city) { pop_grow = 0.03; pop_limit = 10000; } else { switch (terr) { case sub_plain: case sub_forest: pop_grow = 0.01; pop_limit = 1000; break; case sub_mountain: case sub_swamp: pop_grow = 0.005; pop_limit = 1000; break; default: pop_grow = 0.000; pop_limit = 500; break; }; }; /* * Might be an effect here. * */ if (get_effect(where, ef_grow, 0, 0)) { wout(where, "The peasants seem particularly happy this month."); pop_grow += 0.02; }; dpop = pop * pop_grow; if (pop_grow > 0.0 && dpop < 1) dpop = 1; /* * Lose population at a reasonable rate. * */ if (pop > pop_limit) dpop = -(pop - pop_limit) / 10; if (p_subloc(province(where))->loot && dpop > 0) { wout(where, "Pillaging traumatizes the population and no growth occurs."); } else if (dpop > 0) { if (pop > 100) wout(where, "The population grows by %s peasant%s.", nice_num(dpop), add_s(dpop)); gen_item(where, item_peasant, dpop); } else { if (pop > 100) wout(where, "Overcrowding causes %s peasant death%s.", nice_num(-dpop), add_s(-dpop)); consume_item(where, item_peasant, -dpop); }; }; /* * Sat Apr 18 16:57:53 1998 -- Scott Turner * * Special case for gold production from peasants. * They generate 1 gold per 20 peasants (1/10 in cities) * which accumulates to be removed by various means. * * Only in civilized (> 100) provinces */ if ((pop = has_item(where, item_peasant)) > 100) { if (has_city) { dpop = pop * 0.10; } else { dpop = pop * 0.05; }; gen_item(where, item_gold, dpop); }; }
void fix_gates() { int where; struct exit_view **l; int set_one; int i; int dest; int m; clear_temps(T_loc); loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; if (!province_gate_here(where)) continue; fprintf(stderr, "Gate in %s\n", box_name(where)); l = exits_from_loc_nsew(0, where); for (i = 0; i < ilist_len(l); i++) { if (loc_depth(l[i]->destination) != LOC_province) continue; if (!province_gate_here(l[i]->destination)) { bx[l[i]->destination]->temp = 1; } } } next_province; m = 1; do { set_one = FALSE; loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; if (province_gate_here(where) || bx[where]->temp != m) continue; l = exits_from_loc_nsew(0, where); for (i = 0; i < ilist_len(l); i++) { dest = l[i]->destination; if (loc_depth(dest) != LOC_province) continue; if (!province_gate_here(dest) && bx[dest]->temp == 0) { bx[dest]->temp = m + 1; set_one = TRUE; } } } next_province; m++; } while (set_one); loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; if (!province_gate_here(where) && bx[where]->temp < 1) fprintf(stderr, "error on %d\n", where); } next_province; loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; p_loc(where)->dist_from_gate = bx[where]->temp; } next_province; }