static void test_dragon_attacks_the_rich(CuTest * tc) { faction *f, *f2; unit *u, *m; const item_type *i_silver; create_monsters(&f, &f2, &u, &m); init_resources(); setguard(m, true); set_level(m, SK_WEAPONLESS, 10); rsetmoney(findregion(0, 0), 1); rsetmoney(findregion(1, 0), 0); i_silver = it_find("money"); assert(i_silver); i_change(&u->items, i_silver, 5000); config_set("rules.monsters.attack_chance", "0.00001"); plan_monsters(f2); CuAssertPtrNotNull(tc, find_order("attack 1", m)); CuAssertPtrNotNull(tc, find_order("loot", m)); test_cleanup(); }
static void test_dragon_moves(CuTest * tc) { faction *f, *f2; region *r; unit *u, *m; struct message *msg; create_monsters(&f, &f2, &u, &m); rsetmoney(findregion(1, 0), 1000); r = findregion(0, 0); // plain rsetpeasants(r, 0); rsetmoney(r, 0); set_level(m, SK_WEAPONLESS, 10); config_set("rules.monsters.attack_chance", ".0"); plan_monsters(f2); CuAssertPtrNotNull(tc, find_order("move east", m)); mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", 0)); random_growl(m, findregion(1, 0), 3); msg = test_get_last_message(r->msgs); assert_message(tc, msg, "dragon_growl", 4); assert_pointer_parameter(tc, msg, 0, m); assert_int_parameter(tc, msg, 1, 1); assert_pointer_parameter(tc, msg, 2, findregion(1,0)); assert_string_parameter(tc, msg, 3, "growl3"); test_cleanup(); }
faction *gm_addquest(const char *email, const char *name, int radius, unsigned int flags) { plane *pl; watcher *w = calloc(sizeof(watcher), 1); region *center; bool invalid = false; int minx, miny, maxx, maxy, cx, cy; int x; faction *f; /* GM playfield */ do { minx = ((rng_int() % (2 * EXTENSION)) - EXTENSION); miny = ((rng_int() % (2 * EXTENSION)) - EXTENSION); for (x = 0; !invalid && x <= radius * 2; ++x) { int y; for (y = 0; !invalid && y <= radius * 2; ++y) { region *r = findregion(minx + x, miny + y); if (r) invalid = true; } } } while (invalid); maxx = minx + 2 * radius; cx = minx + radius; maxy = miny + 2 * radius; cy = miny + radius; pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags); center = new_region(cx, cy, pl, 0); for (x = 0; x <= 2 * radius; ++x) { int y; for (y = 0; y <= 2 * radius; ++y) { region *r = findregion(minx + x, miny + y); if (!r) { r = new_region(minx + x, miny + y, pl, 0); } freset(r, RF_ENCOUNTER); if (distance(r, center) == radius) { terraform_region(r, newterrain(T_FIREWALL)); } else if (r == center) { terraform_region(r, newterrain(T_PLAIN)); } else { terraform_region(r, newterrain(T_OCEAN)); } } } /* watcher: */ f = gm_addfaction(email, pl, center); w->faction = f; w->mode = see_unit; w->next = pl->watchers; pl->watchers = w; return f; }
void create_arena(void) { int x; arena_id = hashstring("arena"); arena = getplanebyid(arena_id); if (arena != NULL) return; score(); /* ist wichtig, damit alle Parteien einen score haben, wenn sie durchs Tor wollen. */ guardian_faction(arena, 999); if (arena) arena_center = findregion(plane_center_x(arena), plane_center_y(arena)); if (!arena_center) { newarena = 1; arena = create_new_plane(arena_id, "Arena", -10000, -10000, 0, BLOCKSIZE - 1, PFL_LOWSTEALING | PFL_NORECRUITS | PFL_NOALLIANCES); block_create(arena->minx, arena->miny, T_OCEAN); arena_center = findregion(plane_center_x(arena), plane_center_y(arena)); for (x = 0; x != BLOCKSIZE; ++x) { int y; for (y = 0; y != BLOCKSIZE; ++y) { region *r = findregion(arena->minx + x, arena->miny + y); freset(r, RF_ENCOUNTER); r->planep = arena; switch (distance(r, arena_center)) { case 4: terraform(r, T_FIREWALL); break; case 0: terraform(r, T_GLACIER); break; case 1: terraform(r, T_SWAMP); break; case 2: terraform(r, T_MOUNTAIN); break; } } } } make_temple(arena_center); #ifdef CENTRAL_VOLCANO init_volcano(); #else if (arena_center->terrain != T_DESERT) terraform(arena_center, T_DESERT); #endif rsetmoney(arena_center, 0); rsetpeasants(arena_center, 0); tower_init(); }
static void test_rename_building_twice(CuTest * tc) { region *r; building *b; unit *u; faction *f; building_type *btype; test_cleanup(); test_create_world(); btype = bt_get_or_create("castle"); r = findregion(-1, 0); b = new_building(btype, r, default_locale); f = test_create_faction(rc_find("human")); u = test_create_unit(f, r); u_set_building(u, b); rename_building(u, NULL, b, "Villa Nagel"); CuAssertStrEquals(tc, "Villa Nagel", b->name); rename_building(u, NULL, b, "Villa Kunterbunt"); CuAssertStrEquals(tc, "Villa Kunterbunt", b->name); }
void test_change_resource(CuTest * tc) { struct unit * u; struct faction * f; struct region * r; const char * names[] = { "money", "aura", "permaura", "horse", "hp", 0 }; int i; test_cleanup(); test_create_world(); skill_enabled[SK_MAGIC] = 1; r = findregion(0, 0); f = test_create_faction(0); u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); set_level(u, SK_MAGIC, 5); create_mage(u, M_DRAIG); for (i=0;names[i];++i) { const struct resource_type *rtype = rt_find(names[i]); int have = get_resource(u, rtype); CuAssertIntEquals(tc, have+1, change_resource(u, rtype, 1)); CuAssertIntEquals(tc, have+1, get_resource(u, rtype)); } }
void test_upkeep_from_pool(CuTest * tc) { region *r; unit *u1, *u2; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); u1 = test_create_unit(test_create_faction(test_create_race("human")), r); assert(u1); u2 = test_create_unit(u1->faction, r); assert(r && u1 && u2); set_param(&global.parameters, "rules.food.flags", "0"); i_change(&u1->items, i_silver, 30); get_food(r); CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, 0, fval(u2, UFL_HUNGER)); get_food(r); CuAssertIntEquals(tc, 0, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); test_cleanup(); }
void test_upkeep_hunger_damage(CuTest * tc) { region *r; unit *u1; faction *f1; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); f1 = test_create_faction(test_create_race("human")); u1 = test_create_unit(f1, r); assert(r && u1); set_param(&global.parameters, "rules.food.flags", "0"); u1->hp = 100; get_food(r); // since u1 and u2 are not allied, u1 should not help u2 with upkeep CuAssertTrue(tc, u1->hp < 100); test_cleanup(); }
void test_upkeep_default(CuTest * tc) { region *r; unit *u1, *u2; faction *f1, *f2; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); f1 = test_create_faction(test_create_race("human")); f2 = test_create_faction(test_create_race("human")); assert(f1 && f2); u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); assert(r && u1 && u2); set_param(&global.parameters, "rules.food.flags", "0"); i_change(&u1->items, i_silver, 20); get_food(r); // since u1 and u2 are not allied, u1 should not help u2 with upkeep CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); test_cleanup(); }
static int report_json(const char *filename, report_context * ctx, const char *charset) { if (config_get_int("jsreport.enabled", 0) != 0) { FILE * F = fopen(filename, "w"); if (F) { int x, y, minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN; seen_region *sr; region *r; /* traverse all regions */ for (sr = NULL, r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { sr = find_seen(ctx->f->seen, r); } for (; sr != NULL; sr = sr->next) { int tx = sr->r->x; int ty = sr->r->y; coor_to_tiled(&tx, &ty); if (ty < miny) miny = ty; else if (ty > maxy) maxy = ty; if (tx < minx) minx = tx; else if (tx > maxx) maxx = tx; } if (maxx >= minx && maxy >= miny) { int w = maxx - minx + 1, h = maxy - miny + 1; fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F); fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w); fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w); fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F); for (y = miny; y <= maxy; ++y) { for (x = minx; x <= maxx; ++x) { int data = 0; int tx = x, ty = y; coor_from_tiled(&tx, &ty); r = findregion(tx, ty); if (r) { sr = find_seen(ctx->f->seen, r); if (sr) { terrain_t ter = oldterrain(r->terrain); if (ter == NOTERRAIN) { data = 1 + r->terrain->_name[0]; } else { data = 1 + (int)ter; } } } fprintf(F, "%d", data); if (x != maxx || y != maxy) fputs(", ", F); } } fputs("]}], \"tilesets\": [{\"firstgid\": 1, \"image\": \"magellan.png\", \"imageheight\": 192, \"imagewidth\": 256," "\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, " "\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F); } fclose(F); return 0; } return -1; } return 0; }
/** ** GM: TELEPORT <unit> <x> <y> ** requires: permission-key "gmtele" **/ static void gm_teleport(const void *tnext, struct unit *u, struct order *ord) { const struct plane *p = rplane(u->region); unit *to = findunit(getid()); int x = rel_to_abs(p, u->faction, getint(), 0); int y = rel_to_abs(p, u->faction, getint(), 1); region *r = findregion(x, y); if (r == NULL || p != rplane(r)) { mistake(u, ord, "region is in another plane."); } else if (to == NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", "")); } else if (rplane(to->region) != rplane(r) && !ucontact(to, u)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact", "target", to)); } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !has_permission(permissions, atoi36("gmtele"))) { mistake(u, ord, "permission denied."); } else move_unit(to, r, NULL); } }
static void test_fishing_feeds_2_people(CuTest * tc) { const resource_type *rtype; region *r; faction *f; unit *u; ship *sh; test_cleanup(); test_create_world(); r = findregion(-1, 0); CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */ f = test_create_faction(rc_find("human")); u = test_create_unit(f, r); sh = new_ship(st_find("boat"), r, 0); u_set_ship(u, sh); rtype = get_resourcetype(R_SILVER); i_change(&u->items, rtype->itype, 42); scale_number(u, 1); sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype)); scale_number(u, 2); sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype)); scale_number(u, 3); sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 32, i_get(u->items, rtype->itype)); }
static void test_dragon_attacks_the_rich(CuTest * tc) { faction *f, *f2; region *r; unit *u, *m; const item_type *i_silver; init_language(); create_monsters(&f, &f2, &r, &u, &m); guard(m, GUARD_TAX); set_level(m, SK_WEAPONLESS, 10); rsetmoney(r, 1); rsetmoney(findregion(1, 0), 0); i_silver = it_find("money"); assert(i_silver); i_change(&u->items, i_silver, 5000); config_set("rules.monsters.attack_chance", "0.00001"); plan_monsters(f2); CuAssertPtrNotNull(tc, find_order("ATTACKIERE 1", m)); CuAssertPtrNotNull(tc, find_order("PLUENDERE", m)); test_cleanup(); }
static void test_group(CuTest * tc) { unit *u; region *r; faction *f; group *g; test_cleanup(); test_create_world(); r = findregion(0, 0); f = test_create_faction(0); assert(r && f); u = test_create_unit(f, r); assert(u); CuAssertTrue(tc, join_group(u, "hodor")); CuAssertPtrNotNull(tc, (g = get_group(u))); CuAssertStrEquals(tc, "hodor", g->name); CuAssertIntEquals(tc, 1, g->members); set_group(u, 0); CuAssertIntEquals(tc, 0, g->members); CuAssertPtrEquals(tc, 0, get_group(u)); set_group(u, g); CuAssertIntEquals(tc, 1, g->members); CuAssertPtrEquals(tc, g, get_group(u)); test_cleanup(); }
/** ** GM: GATE <id> <x> <y> ** requires: permission-key "gmgate" **/ static void gm_gate(const void *tnext, struct unit * u, struct order *ord) { const struct plane *pl = rplane(u->region); int id = getid(); int x = rel_to_abs(pl, u->faction, getint(), 0); int y = rel_to_abs(pl, u->faction, getint(), 1); building *b = findbuilding(id); region *r; pnormalize(&x, &y, pl); r = findregion(x, y); if (b == NULL || r == NULL || pl != rplane(b->region) || pl != rplane(r)) { mistake(u, ord, "the unit cannot transform this building."); return; } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (permissions && has_permission(permissions, atoi36("gmgate"))) { remove_triggers(&b->attribs, "timer", &tt_gate); remove_triggers(&b->attribs, "create", &tt_unguard); if (r != b->region) { add_trigger(&b->attribs, "timer", trigger_gate(b, r)); add_trigger(&b->attribs, "create", trigger_unguard(b)); fset(b, BLD_UNGUARDED); } } } }
static int tolua_region_create(lua_State * L) { int x = (int)tolua_tonumber(L, 1, 0); int y = (int)tolua_tonumber(L, 2, 0); const char *tname = tolua_tostring(L, 3, 0); if (tname) { plane *pl = findplane(x, y); const terrain_type *terrain = get_terrain(tname); region *r, *result; if (!terrain) { return 0; } assert(!pnormalize(&x, &y, pl)); r = result = findregion(x, y); if (r != NULL && r->units != NULL) { /* TODO: error message */ result = NULL; } else if (r == NULL) { result = new_region(x, y, pl, 0); } if (result) { terraform_region(result, terrain); if (result->land) { fix_demand(result); } } tolua_pushusertype(L, result, TOLUA_CAST "region"); return 1; } return 0; }
static int tolua_bindings_atlantis_regions_get00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isnumber(tolua_S,1,0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else #endif { int x = ((int) tolua_tonumber(tolua_S,1,0)); int y = ((int) tolua_tonumber(tolua_S,2,0)); { region* tolua_ret = (region*) findregion(x,y); tolua_pushusertype(tolua_S,(void*)tolua_ret,"region"); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'get'.",&tolua_err); return 0; #endif }
static void test_ship_set_owner(CuTest * tc) { struct region *r; struct ship *sh; struct unit *u1, *u2; struct faction *f; const struct ship_type *stype; const struct race *human; test_setup(); test_create_world(); human = rc_find("human"); stype = st_find("boat"); f = test_create_faction(human); r = findregion(0, 0); sh = test_create_ship(r, stype); u1 = test_create_unit(f, r); u_set_ship(u1, sh); CuAssertPtrEquals(tc, u1, ship_owner(sh)); u2 = test_create_unit(f, r); u_set_ship(u2, sh); CuAssertPtrEquals(tc, u1, ship_owner(sh)); ship_set_owner(u2); CuAssertPtrEquals(tc, u2, ship_owner(sh)); test_teardown(); }
static void test_shipowner_goes_to_other_when_empty(CuTest * tc) { struct region *r; struct ship *sh; struct unit *u, *u2; struct faction *f; const struct ship_type *stype; const struct race *human; test_setup(); test_create_world(); human = rc_find("human"); CuAssertPtrNotNull(tc, human); stype = st_find("boat"); CuAssertPtrNotNull(tc, stype); f = test_create_faction(human); r = findregion(0, 0); sh = test_create_ship(r, stype); CuAssertPtrNotNull(tc, sh); u2 = test_create_unit(f, r); u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); u_set_ship(u, sh); u_set_ship(u2, sh); CuAssertPtrEquals(tc, u, ship_owner(sh)); u->number = 0; CuAssertPtrEquals(tc, u2, ship_owner(sh)); test_teardown(); }
void test_hasspell(CuTest * tc) { spell *sp; struct unit * u; struct faction * f; struct region * r; test_cleanup(); test_create_world(); r = findregion(0, 0); f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); skill_enabled[SK_MAGIC] = 1; sp = create_spell("testspell", 0); sp->sptyp |= POSTCOMBATSPELL; unit_add_spell(u, 0, sp, 2); set_level(u, SK_MAGIC, 1); CuAssertTrue(tc, !u_hasspell(u, sp)); set_level(u, SK_MAGIC, 2); CuAssertTrue(tc, u_hasspell(u, sp)); set_level(u, SK_MAGIC, 1); CuAssertTrue(tc, !u_hasspell(u, sp)); }
void test_pay_spell(CuTest * tc) { spell *sp; unit * u; faction * f; region * r; int level; test_cleanup(); test_create_world(); r = findregion(0, 0); f = test_create_faction(0); u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); sp = test_magic_create_spell(); CuAssertPtrNotNull(tc, sp); set_level(u, SK_MAGIC, 5); unit_add_spell(u, 0, sp, 1); change_resource(u, rt_find("money"), 1); change_resource(u, rt_find("aura"), 3); change_resource(u, rt_find("horse"), 3); level = eff_spelllevel(u, sp, 3, 1); CuAssertIntEquals(tc, 3, level); pay_spell(u, sp, level, 1); CuAssertIntEquals(tc, 0, get_resource(u, rt_find("money"))); CuAssertIntEquals(tc, 0, get_resource(u, rt_find("aura"))); CuAssertIntEquals(tc, 0, get_resource(u, rt_find("horse"))); }
void test_set_post_combatspell(CuTest * tc) { spell *sp; struct unit * u; struct faction * f; struct region * r; const int index = 2; test_cleanup(); test_create_world(); r = findregion(0, 0); f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); skill_enabled[SK_MAGIC] = 1; set_level(u, SK_MAGIC, 1); sp = create_spell("testspell", 0); sp->sptyp |= POSTCOMBATSPELL; unit_add_spell(u, 0, sp, 1); set_combatspell(u, sp, 0, 2); CuAssertPtrEquals(tc, sp, (spell *)get_combatspell(u, index)); set_level(u, SK_MAGIC, 2); CuAssertIntEquals(tc, 2, get_combatspelllevel(u, index)); set_level(u, SK_MAGIC, 1); CuAssertIntEquals(tc, 1, get_combatspelllevel(u, index)); unset_combatspell(u, sp); CuAssertIntEquals(tc, 0, get_combatspelllevel(u, index)); CuAssertPtrEquals(tc, 0, (spell *)get_combatspell(u, index)); }
void test_getspell_school(CuTest * tc) { spell *sp; struct unit * u; struct faction * f; struct region * r; struct locale * lang; struct spellbook * book; test_cleanup(); test_create_world(); r = findregion(0, 0); f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); create_mage(u, f->magiegebiet); skill_enabled[SK_MAGIC] = 1; set_level(u, SK_MAGIC, 1); lang = find_locale("de"); sp = create_spell("testspell", 0); locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp"); CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang)); book = faction_get_spellbook(f); CuAssertPtrNotNull(tc, book); spellbook_add(book, sp, 1); CuAssertPtrEquals(tc, sp, unit_getspell(u, "Herp-a-derp", lang)); }
void test_getspell_unit(CuTest * tc) { spell *sp; struct unit * u; struct faction * f; struct region * r; struct locale * lang; test_cleanup(); test_create_world(); r = findregion(0, 0); f = test_create_faction(0); u = test_create_unit(f, r); create_mage(u, M_GRAY); skill_enabled[SK_MAGIC] = 1; set_level(u, SK_MAGIC, 1); lang = find_locale("de"); sp = create_spell("testspell", 0); locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp"); CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang)); unit_add_spell(u, 0, sp, 1); CuAssertPtrNotNull(tc, unit_getspell(u, "Herp-a-derp", lang)); }
/** ** GM: TERRAFORM <x> <y> <terrain> ** requires: permission-key "gmterf" **/ static void gm_terraform(const void *tnext, struct unit *u, struct order *ord) { const struct plane *p = rplane(u->region); int x = rel_to_abs(p, u->faction, getint(), 0); int y = rel_to_abs(p, u->faction, getint(), 1); const char *c = getstrtoken(); variant token; void **tokens = get_translations(u->faction->locale, UT_TERRAINS); region *r; pnormalize(&x, &y, p); r = findregion(x, y); if (r == NULL || p != rplane(r)) { mistake(u, ord, "region is in another plane."); return; } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !has_permission(permissions, atoi36("gmterf"))) return; } if (findtoken(*tokens, c, &token) != E_TOK_NOMATCH) { const terrain_type *terrain = (const terrain_type *)token.v; terraform_region(r, terrain); } }
static void test_tax_cmd(CuTest *tc) { order *ord; faction *f; region *r; unit *u; item_type *sword, *silver; request *taxorders = 0; test_cleanup(); config_set("taxing.perlevel", "20"); test_create_world(); f = test_create_faction(NULL); r = findregion(0, 0); assert(r && f); u = test_create_unit(f, r); ord = create_order(K_TAX, f->locale, ""); assert(ord); tax_cmd(u, ord, &taxorders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error48")); test_clear_messages(u->faction); silver = get_resourcetype(R_SILVER)->itype; sword = it_get_or_create(rt_get_or_create("sword")); new_weapontype(sword, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 1); i_change(&u->items, sword, 1); set_level(u, SK_MELEE, 1); tax_cmd(u, ord, &taxorders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_no_tax_skill")); test_clear_messages(u->faction); set_level(u, SK_TAXING, 1); tax_cmd(u, ord, &taxorders); CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill")); CuAssertPtrNotNull(tc, taxorders); rsetmoney(r, 11); expandtax(r, taxorders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "income")); /* taxing is in multiples of 10 */ CuAssertIntEquals(tc, 10, i_get(u->items, silver)); test_clear_messages(u->faction); i_change(&u->items, silver, -i_get(u->items, silver)); rsetmoney(r, 1000); taxorders = 0; tax_cmd(u, ord, &taxorders); expandtax(r, taxorders); CuAssertIntEquals(tc, 20, i_get(u->items, silver)); test_clear_messages(u->faction); free_order(ord); test_cleanup(); }
plane *gm_addplane(int radius, unsigned int flags, const char *name) { region *center; plane *pl; bool invalid = false; int minx, miny, maxx, maxy, cx, cy; int x; /* GM playfield */ do { minx = (rng_int() % (2 * EXTENSION)) - EXTENSION; miny = (rng_int() % (2 * EXTENSION)) - EXTENSION; for (x = 0; !invalid && x <= radius * 2; ++x) { int y; for (y = 0; !invalid && y <= radius * 2; ++y) { region *r = findregion(minx + x, miny + y); if (r) invalid = true; } } } while (invalid); maxx = minx + 2 * radius; cx = minx + radius; maxy = miny + 2 * radius; cy = miny + radius; pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags); center = new_region(cx, cy, pl, 0); for (x = 0; x <= 2 * radius; ++x) { int y; for (y = 0; y <= 2 * radius; ++y) { region *r = findregion(minx + x, miny + y); if (!r) r = new_region(minx + x, miny + y, pl, 0); freset(r, RF_ENCOUNTER); if (distance(r, center) == radius) { terraform_region(r, newterrain(T_FIREWALL)); } else if (r == center) { terraform_region(r, newterrain(T_PLAIN)); } else { terraform_region(r, newterrain(T_OCEAN)); } } } return pl; }
int resolve_region_coor(variant id, void *address) { region *r = findregion(id.sa[0], id.sa[1]); if (r) { *(region **)address = r; return 0; } *(region **)address = NULL; return -1; }
static int use_museumexitticket(unit * u, const struct item_type *itype, int amount, order * ord) { attrib *a; region *r; unit *warden = findunit(atoi36("mwar")); int unit_cookie; unused_arg(amount); /* Prüfen ob in Eingangshalle */ if (u->region->x != 9525 || u->region->y != 9525) { cmistake(u, ord, 266, MSG_MAGIC); return 0; } a = a_find(u->attribs, &at_museumexit); assert(a); r = findregion(a->data.sa[0], a->data.sa[1]); assert(r); a_remove(&u->attribs, a); /* Übergebene Gegenstände zurückgeben */ a = a_find(u->attribs, &at_museumgivebackcookie); if (a) { unit_cookie = a->data.i; a_remove(&u->attribs, a); for (a = a_find(warden->attribs, &at_museumgiveback); a && a->type == &at_museumgiveback; a = a->next) { if (((museumgiveback *)(a->data.v))->cookie == unit_cookie) break; } if (a && a->type == &at_museumgiveback) { museumgiveback *gb = (museumgiveback *)(a->data.v); item *it; for (it = gb->items; it; it = it->next) { i_change(&u->items, it->type, it->number); } ADDMSG(&u->faction->msgs, msg_message("museumgiveback", "region unit sender items", r, u, warden, gb->items)); a_remove(&warden->attribs, a); } } /* Benutzer zurück teleportieren */ move_unit(u, r, NULL); /* Exitticket abziehen */ i_change(&u->items, itype, -1); return 0; }
static void tower_init(void) { int i, first = newarena; item_type *it_demonseye = it_find("demonseye"); item_type *it_griphonwing = it_find("griphonwing"); assert(it_griphonwing && it_demonseye); for (i = 0; i != 6; ++i) { region *r = tower_region[i] = findregion(arena_center->x + delta_x[i] * 3, arena_center->y + delta_y[i] * 3); if (r) { start_region[i] = findregion(arena_center->x + delta_x[i] * 2, arena_center->y + delta_y[i] * 2); if (rterrain(r) != T_DESERT) terraform(r, T_DESERT); if (!r->buildings) { building *b = new_building(bt_find("castle"), r, NULL); b->size = 10; if (i != 0) { sprintf(buf, "Turm des %s", LOC(default_locale, mkname("school", magic_school[i]))); } else sprintf(buf, "Turm der Ahnungslosen"); set_string(&b->name, buf); } } } if (first && !arena_center->buildings) { building *b = new_building(bt_find("castle"), arena_center, NULL); attrib *a; item *items; i_add(&items, i_new(it_griphonwing, 1)); i_add(&items, i_new(it_demonseye, 1)); a = a_add(&b->attribs, make_giveitem(b, items)); b->size = 10; set_string(&b->name, "Höhle des Greifen"); } }