示例#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;
}
示例#2
0
文件: disk.c 项目: balr0g/cw
/****************************************************************************
 * config_disk_directive
 ****************************************************************************/
static cw_bool_t
config_disk_directive(
	struct config			*cfg,
	struct disk			*dsk,
	struct disk_track		*dsk_trk,
	struct disk_params		*dsk_prm,
	cw_flag_t			scope)

	{
	cw_char_t			token[GLOBAL_MAX_NAME_SIZE];
	cw_count_t			len;

	len = config_token(cfg, token, sizeof (token));
	if (len == 0)
		{
		if (scope & SCOPE_ENTER) config_error(cfg, "directive expected");
		config_error(cfg, "} expected");
		}
	if ((scope & SCOPE_ENTER) && (string_equal(token, "{"))) return (config_disk_enter(cfg, dsk, dsk_trk, dsk_prm, scope));
	if ((scope & SCOPE_LEAVE) && (string_equal(token, "}"))) return (CW_BOOL_FAIL);
	if (scope & SCOPE_TRACK)
		{
		if (string_equal(token, "info"))        return (config_disk_info(cfg, dsk));
		if (string_equal(token, "copy"))        return (config_disk_copy(cfg, dsk));
		if (string_equal(token, "image"))       return (config_disk_image(cfg, dsk));
		if (string_equal(token, "trackmap"))    return (config_disk_trackmap(cfg, dsk));
		if (string_equal(token, "track"))       return (config_disk_track(cfg, dsk, dsk_trk));
		if (string_equal(token, "track_range")) return (config_disk_track_range(cfg, dsk, dsk_trk));
		}
	if (scope & SCOPE_RW)
		{
		if (string_equal(token, "format"))       return (config_disk_format(cfg, dsk_trk));
		if (string_equal(token, "clock"))        return (config_disk_clock(cfg, dsk_trk));
		if (string_equal(token, "timeout"))      return (config_disk_timeout(cfg, dsk_trk));
		if (string_equal(token, "indexed"))      return (config_disk_indexed(cfg, dsk_trk));
		if (string_equal(token, "optional"))     return (config_disk_optional(cfg, dsk_trk));
		if (string_equal(token, "flip_side"))    return (config_disk_flip_side(cfg, dsk_trk));
		if (string_equal(token, "side_offset"))  return (config_disk_side_offset(cfg, dsk_trk));
		if (string_equal(token, "read"))         return (config_disk_directive(cfg, NULL, dsk_trk, NULL, SCOPE_ENTER | SCOPE_READ));
		if (string_equal(token, "write"))        return (config_disk_directive(cfg, NULL, dsk_trk, NULL, SCOPE_ENTER | SCOPE_WRITE));
		if (disk_get_format(dsk_trk) == NULL)    config_disk_error_format(cfg);
		if (string_equal(token, "skew"))         return (config_disk_skew(cfg, dsk_trk));
		if (string_equal(token, "interleave"))   return (config_disk_interleave(cfg, dsk_trk));
		if (config_disk_rw(cfg, dsk_trk, token)) return (CW_BOOL_OK);
		}
	if (scope & SCOPE_READ)
		{
		if (string_equal(token, "timeout"))        return (config_disk_timeout_read(cfg, dsk_trk));
		if (string_equal(token, "indexed"))        return (config_disk_indexed_read(cfg, dsk_trk));
		if (disk_get_format(dsk_trk) == NULL)      config_disk_error_format(cfg);
		if (config_disk_read(cfg, dsk_trk, token)) return (CW_BOOL_OK);
		}
	if (scope & SCOPE_WRITE)
		{
		if (string_equal(token, "timeout"))         return (config_disk_timeout_write(cfg, dsk_trk));
		if (string_equal(token, "indexed"))         return (config_disk_indexed_write(cfg, dsk_trk));
		if (disk_get_format(dsk_trk) == NULL)       config_disk_error_format(cfg);
		if (config_disk_write(cfg, dsk_trk, token)) return (CW_BOOL_OK);
		}
	if ((scope & SCOPE_PARAMS) && (config_disk_params(cfg, dsk_trk, dsk_prm, token, len))) return (CW_BOOL_OK);
	config_error_invalid(cfg, token);

	/* never reached, only to make gcc happy */

	return (CW_BOOL_FAIL);
	}