Пример #1
0
static void
unit_view(struct emp_qelem *list)
{
    struct sctstr sect;
    struct emp_qelem *qp;
    struct emp_qelem *next;
    struct ulist *ulp;

    for (qp = list->q_back; qp != list; qp = next) {
	next = qp->q_back;
	ulp = (struct ulist *)qp;
	if (CANT_HAPPEN(!(ef_flags(ulp->unit.gen.ef_type) & EFF_XY)))
	    continue;
	getsect(ulp->unit.gen.x, ulp->unit.gen.y, &sect);
	if (ulp->unit.gen.ef_type == EF_SHIP) {
	    if (mchr[ulp->unit.ship.shp_type].m_flags & M_FOOD)
		pr("[fert:%d] ", sect.sct_fertil);
	    if (mchr[ulp->unit.ship.shp_type].m_flags & M_OIL)
		pr("[oil:%d] ", sect.sct_oil);
	}
	pr("%s @ %s %d%% %s\n", unit_nameof(&ulp->unit.gen),
	   xyas(ulp->unit.gen.x, ulp->unit.gen.y, player->cnum),
	   sect.sct_effic, dchr[sect.sct_type].d_name);
    }
}
Пример #2
0
static int
verify_ca(int type)
{
    struct castr *ca = ef_cadef(type);
    int i;

    for (i = 0; ca[i].ca_name; i++) {
	/*
	 * Virtual selectors must be NSC_EXTRA, because xundump can't
	 * cope with them without setter methods.  Exception: if
	 * EFF_MEM is not set, xundump doesn't touch the table.
	 */
	if (CANT_HAPPEN((ef_flags(type) & EFF_MEM)
			&& ca[i].ca_get && !(ca[i].ca_flags & NSC_EXTRA)))
	    ca[i].ca_flags |= NSC_EXTRA;
    }
    return 0;
}
Пример #3
0
int
nxtitem(struct nstr_item *np, void *ptr)
{
    struct empobj *gp;
    int selected;

    if (np->sel == NS_UNDEF)
	return 0;
    gp = (struct empobj *)ptr;
    do {
	if (np->sel == NS_LIST) {
	    np->index++;
	    if (np->index >= np->size)
		return 0;
	    np->cur = np->list[np->index];
	} else if (np->sel == NS_CARGO) {
	    if (np->next < 0)
		return 0;
	    np->cur = np->next;
	    np->next = unit_cargo_next(np->type, np->next);
	} else {
	    np->cur++;
	}
	if (!ef_read(np->type, np->cur, ptr))
	    return 0;
	selected = 1;
	switch (np->sel) {
	case NS_LIST:
	case NS_CARGO:
	case NS_ALL:
	    break;
	case NS_DIST:
	    if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
		return 0;
	    if (!xyinrange(gp->x, gp->y, &np->range)) {
		selected = 0;
		break;
	    }
	    np->curdist = mapdist(gp->x, gp->y, np->cx, np->cy);
	    if (np->curdist > np->dist)
		selected = 0;
	    break;
	case NS_AREA:
	    if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
		return 0;
	    if (!xyinrange(gp->x, gp->y, &np->range))
		selected = 0;
	    break;
	case NS_XY:
	    if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY)))
		return 0;
	    if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy)
		selected = 0;
	    break;
	case NS_GROUP:
	    if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_GROUP)))
		return 0;
	    if (np->group != gp->group)
		selected = 0;
	    break;
	default:
	    CANT_REACH();
	    return 0;
	}
	if (selected && np->ncond) {
	    /* nstr_exec is expensive, so we do it last */
	    if (!nstr_exec(np->cond, np->ncond, ptr))
		selected = 0;
	}
    } while (!selected);
    return 1;
}
Пример #4
0
static int
verify_row(int type, int row)
{
    struct castr *ca = ef_cadef(type);
    struct empobj *row_ref;
    int i, j, n;
    struct valstr val;
    int ret_val = 0;
    int flags = ef_flags(type);

    if (flags & EFF_MEM)
	row_ref = ef_ptr(type, row);
    else {
	row_ref = malloc(empfile[type].size);
	ef_read(type, row, row_ref);
    }

    if ((flags & EFF_TYPED) && !EF_IS_VIEW(type)) {
	if (row_ref->ef_type != type || row_ref->uid != row) {
	    verify_fail(type, row, NULL, 0, "header corrupt");
	    ret_val = -1;
	}
    }

    if (!empobj_in_use(type, row_ref))
	goto out;

    for (i = 0; ca[i].ca_name; ++i) {
	if (ca[i].ca_get)
	    continue;		/* virtual */
	n = CA_ARRAY_LEN(&ca[i]);
	j = 0;
	do {
	    if (ca[i].ca_table == EF_BAD)
		continue;
	    nstr_mksymval(&val, &ca[i], j);
	    nstr_eval(&val, 0, row_ref, NSC_NOTYPE);
	    if (CANT_HAPPEN(val.val_type != NSC_LONG)) {
		ret_val = -1;
		continue;
	    }
	    if (ca[i].ca_table == type && i == 0) {
		/* uid */
		if (val.val_as.lng != row) {
		    verify_fail(type, row, &ca[i], j,
				"value is %ld instead of %d",
				val.val_as.lng, row);
		    ret_val = -1;
		}
	    } else {
		if (verify_tabref(type, row, &ca[i], j, val.val_as.lng) < 0)
		    ret_val = -1;
	    }
	} while (++j < n);
    }

out:
    if (!(flags & EFF_MEM))
	free(row_ref);
    return ret_val;
}