static void monster_attacks(unit * monster) { region *r = monster->region; unit *u; for (u = r->units; u; u = u->next) { if (u->faction != monster->faction && cansee(monster->faction, r, u, 0) && !in_safe_building(u, monster)) { order *ord = monster_attack(monster, u); if (ord) { addlist(&monster->orders, ord); } } } }
static void test_safe_building(CuTest *tc) { building_type *btype; unit *u1, *u2; test_setup(); btype = test_create_buildingtype("castle"); u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); u2 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); CuAssertIntEquals(tc, false, in_safe_building(u1, u2)); u1->building = test_create_building(u1->region, btype); CuAssertIntEquals(tc, false, in_safe_building(u1, u2)); btype->flags |= BTF_FORTIFICATION; CuAssertIntEquals(tc, true, in_safe_building(u1, u2)); u2->building = u1->building; CuAssertIntEquals(tc, true, in_safe_building(u1, u2)); u1->number = 2; CuAssertIntEquals(tc, false, in_safe_building(u1, u2)); u1->building->size = 3; CuAssertIntEquals(tc, false, in_safe_building(u1, u2)); test_teardown(); }
static order *get_money_for_dragon(region * r, unit * udragon, int wanted) { int n; bool attacks = attack_chance > 0.0; /* falls genug geld in der region ist, treiben wir steuern ein. */ if (rmoney(r) >= wanted) { /* 5% chance, dass der drache aus einer laune raus attackiert */ if (!attacks || chance(1.0 - u_race(udragon)->aggression)) { /* Drachen haben in E3 und E4 keine Einnahmen. Neuer Befehl Pluendern erstmal nur fuer Monster?*/ return create_order(K_LOOT, default_locale, NULL); } } /* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an * und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */ n = 0; if (attacks && is_guard(udragon, GUARD_TAX)) { unit *u; for (u = r->units; u; u = u->next) { if (u->faction != udragon->faction && cansee(udragon->faction, r, u, 0) && !in_safe_building(u, udragon)) { int m = get_money(u); if (m != 0) { order *ord = monster_attack(udragon, u); if (ord) { addlist(&udragon->orders, ord); n += m; } } } } } /* falls die einnahmen erreicht werden, bleibt das monster noch eine */ /* runde hier. */ if (n + rmoney(r) >= wanted) { return create_order(K_LOOT, default_locale, NULL); } /* wenn wir NULL zurueckliefern, macht der drache was anderes, z.b. weggehen */ return NULL; }