Ejemplo n.º 1
0
static unit *building_owner_ex(const building * bld, const struct faction * last_owner)
{
    unit *u, *heir = 0;
    /* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
      * nehmen. */
    for (u = bld->region->units; u; u = u->next) {
        if (u->building == bld) {
            if (u->number > 0) {
                if (heir && last_owner && heir->faction != last_owner && u->faction == last_owner) {
                    heir = u;
                    break; /* we found someone from the same faction who is not dead. let's take this guy */
                }
                else if (!heir) {
                    heir = u; /* you'll do in an emergency */
                }
            }
        }
    }
    if (!heir && config_token("rules.region_owner_pay_building", bld->type->_name)) {
        if (rule_region_owners()) {
            u = building_owner(largestbuilding(bld->region, &cmp_taxes, false));
        }
        else {
            u = building_owner(largestbuilding(bld->region, &cmp_wage, false));
        }
        if (u) {
            heir = u;
        }
    }
    return heir;
}
Ejemplo n.º 2
0
struct faction *region_get_owner(const struct region *r)
{
    assert(rule_region_owners());
    if (r->land && r->land->ownership) {
        return r->land->ownership->owner;
    }
    return NULL;
}
Ejemplo n.º 3
0
struct alliance *region_get_alliance(const struct region *r)
{
    assert(rule_region_owners());
    if (r->land && r->land->ownership) {
        region_owner *own = r->land->ownership;
        return own->owner ? own->owner->alliance : own->alliance;
    }
    return NULL;
}
Ejemplo n.º 4
0
faction *addfaction(const char *email, const char *password,
    const struct race * frace, const struct locale * loc)
{
    faction *f = calloc(1, sizeof(faction));
    char buf[128];

    if (!f) abort();
    if (check_email(email) == 0) {
        faction_setemail(f, email);
    } else {
        log_info("Invalid email address for faction %s: %s\n", itoa36(f->no), email?email:"");
        faction_setemail(f, NULL);
    }

    f->alliance_joindate = turn;
    f->lastorders = 0;
    f->_alive = true;
    f->password_id = 0;
    f->age = 0;
    f->race = frace;
    f->magiegebiet = 0;
    f->locale = loc;
    f->uid = 0;
    f->flags = FFL_ISNEW|FFL_PWMSG;

    if (password) {
        faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT));
        ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
    }

    f->options =
        WANT_OPTION(O_REPORT) | WANT_OPTION(O_ZUGVORLAGE) |
        WANT_OPTION(O_COMPUTER) | WANT_OPTION(O_COMPRESS) |
        WANT_OPTION(O_ADRESSEN) | WANT_OPTION(O_STATISTICS);

    f->no = unused_faction_id();
    if (rule_region_owners()) {
        alliance *al = makealliance(f->no, NULL);
        setalliance(f, al);
    }
    addlist(&factions, f);
    fhash(f);

    slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
    f->name = str_strdup(buf);

    if (!f->race) {
        log_warning("creating a faction that has no race", itoa36(f->no));
    }

    return f;
}
Ejemplo n.º 5
0
faction *update_owners(region * r)
{
    faction *f = NULL;
    assert(rule_region_owners());
    if (r->land) {
        building *bowner = largestbuilding(r, &cmp_current_owner, false);
        building *blargest = largestbuilding(r, &cmp_taxes, false);
        if (blargest) {
            if (!bowner || bowner->size < blargest->size) {
                /* region owners update? */
                unit *u = building_owner(blargest);
                f = region_get_owner(r);
                if (u == NULL) {
                    if (f) {
                        region_set_owner(r, NULL, turn);
                        r->land->ownership->flags |= OWNER_MOURNING;
                        f = NULL;
                    }
                }
                else if (u->faction != f) {
                    if (!r->land->ownership) {
                        /* there has never been a prior owner */
                        region_set_morale(r, MORALE_DEFAULT, turn);
                    }
                    else {
                        alliance *al = region_get_alliance(r);
                        if (al && u->faction->alliance == al) {
                            int morale = _max(0, r->land->morale - MORALE_TRANSFER);
                            region_set_morale(r, morale, turn);
                        }
                        else {
                            region_set_morale(r, MORALE_TAKEOVER, turn);
                            if (f) {
                                r->land->ownership->flags |= OWNER_MOURNING;
                            }
                        }
                    }
                    region_set_owner(r, u->faction, turn);
                    f = u->faction;
                }
            }
        }
        else if (r->land->ownership && r->land->ownership->owner) {
            r->land->ownership->flags |= OWNER_MOURNING;
            region_set_owner(r, NULL, turn);
            f = NULL;
        }
    }
    return f;
}
Ejemplo n.º 6
0
Archivo: region.c Proyecto: stm2/server
void region_set_owner(struct region *r, struct faction *owner, int turn)
{
    assert(rule_region_owners());
    if (r->land) {
        if (!r->land->ownership) {
            r->land->ownership = malloc(sizeof(region_owner));
            assert(region_get_morale(r) == MORALE_DEFAULT);
            r->land->ownership->owner = NULL;
            r->land->ownership->last_owner = NULL;
            r->land->ownership->flags = 0;
        }
        r->land->ownership->since_turn = turn;
        r->land->ownership->morale_turn = turn;
        assert(r->land->ownership->owner != owner);
        r->land->ownership->last_owner = r->land->ownership->owner;
        r->land->ownership->owner = owner;
    }
}
Ejemplo n.º 7
0
static bool is_guardian_r(const unit * guard)
{
    if (guard->number == 0)
        return false;
    if (besieged(guard))
        return false;

    /* if region_owners exist then they may be guardians: */
    if (guard->building && rule_region_owners() && guard == building_owner(guard->building)) {
        faction *owner = region_get_owner(guard->region);
        if (owner == guard->faction) {
            building *bowner = largestbuilding(guard->region, &cmp_taxes, false);
            if (bowner == guard->building) {
                return true;
            }
        }
    }

    if ((guard->flags & UFL_GUARD) == 0)
        return false;
    return fval(u_race(guard), RCF_UNARMEDGUARD) || is_monsters(guard->faction) || (armedmen(guard, true) > 0);
}