Ejemplo n.º 1
0
void morale_update(region *r) {
    int morale = region_get_morale(r);
    assert(r->land);

    if (r->land->ownership && r->land->ownership->owner) {
        int stability = turn - r->land->ownership->morale_turn;
        int maxmorale = MORALE_DEFAULT;
        building *b = largestbuilding(r, cmp_taxes, false);
        if (b) {
            int bsize = buildingeffsize(b, false);
            assert(b->type->taxes>0);
            maxmorale = (bsize + 1) * MORALE_TAX_FACTOR / b->type->taxes;
        }
        if (morale < maxmorale) {
            if (stability > MORALE_COOLDOWN && r->land->ownership->owner
                && morale < MORALE_MAX) {
                double ch = popularity();
                if (is_cursed(r->attribs, &ct_generous)) {
                    ch *= 1.2;            /* 20% improvement */
                }
                if (stability >= MORALE_AVERAGE * 2 || chance(ch)) {
                    region_set_morale(r, morale + 1, turn);
                }
            }
        }
        else if (morale > maxmorale) {
            region_set_morale(r, morale - 1, turn);
        }
    }
    else if (morale > MORALE_DEFAULT) {
        region_set_morale(r, morale - 1, turn);
    }
}
Ejemplo n.º 2
0
void morale_change(region *r, int value) {
    int morale = region_get_morale(r);
    if (morale > 0) {
        morale = morale - value;
        if (morale < 0) morale = 0;
        region_set_morale(r, morale, turn);
    }
}
Ejemplo n.º 3
0
Archivo: region.c Proyecto: stm2/server
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 *new_owner = building_owner(blargest);
                f = region_get_owner(r);
                if (new_owner == NULL) {
                    if (f) {
                        region_set_owner(r, NULL, turn);
                        f = NULL;
                    }
                }
                else if (new_owner->faction != f) {
                    if (!r->land->ownership) {
                        /* there has never been a prior owner */
                        region_set_morale(r, MORALE_DEFAULT, turn);
                    }
                    else if (f || new_owner->faction != region_get_last_owner(r)) {
                        alliance *al = region_get_alliance(r);
                        if (al && new_owner->faction->alliance == al) {
                            int morale = _max(0, region_get_morale(r) - MORALE_TRANSFER);
                            region_set_morale(r, morale, turn);
                        }
                        else {
                            region_set_morale(r, MORALE_TAKEOVER, turn);
                        }
                    }
                    region_set_owner(r, new_owner->faction, turn);
                    f = new_owner->faction;
                }
            }
        }
        else if (r->land->ownership && r->land->ownership->owner) {
            region_set_owner(r, NULL, turn);
            f = NULL;
        }
    }
    return f;
}
Ejemplo n.º 4
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.º 5
0
static int tolua_region_get_morale(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    lua_pushinteger(L, region_get_morale(r));
    return 1;
}