Exemple #1
0
struct building *inside_building(const struct unit *u)
{
  if (u->building == NULL)
    return NULL;

  if (!fval(u->building, BLD_WORKING)) {
    /* Unterhalt nicht bezahlt */
    return NULL;
  } else if (u->building->size < u->building->type->maxsize) {
    /* Gebäude noch nicht fertig */
    return NULL;
  } else {
    int p = 0, cap = buildingcapacity(u->building);
    const unit *u2;
    for (u2 = u->region->units; u2; u2 = u2->next) {
      if (u2->building == u->building) {
        p += u2->number;
        if (u2 == u) {
          if (p <= cap)
            return u->building;
          return NULL;
        }
        if (p > cap)
          return NULL;
      }
    }
  }
  return NULL;
}
Exemple #2
0
static void test_buildingcapacity(CuTest *tc) {
    building *b;
    building_type *btype;
    test_setup();
    btype = test_create_buildingtype("lighthouse");
    btype->capacity = 1;
    btype->maxcapacity = 4;
    b = test_create_building(test_create_region(0, 0, NULL), btype);

    b->size = 1;
    CuAssertIntEquals(tc, b->size*btype->capacity, buildingcapacity(b));
    b->size = 5;
    CuAssertIntEquals(tc, btype->maxcapacity, buildingcapacity(b));

    btype->capacity = -1;
    CuAssertTrue(tc, building_finished(b));
    CuAssertIntEquals(tc, btype->maxcapacity, buildingcapacity(b));
    test_teardown();
}
Exemple #3
0
bool check_leuchtturm(region * r, faction * f)
{
    attrib *a;

    if (!fval(r->terrain, SEA_REGION)) {
        return false;
    }
    for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
        a = a->next) {
        building *b = (building *)a->data.v;

        assert(is_building_type(b->type, "lighthouse"));
        if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
            int maxd = (int)log10(b->size) + 1;

            if (skill_enabled(SK_PERCEPTION) && f) {
                region *r2 = b->region;
                unit *u;
                int c = 0;
                int d = 0;

                for (u = r2->units; u; u = u->next) {
                    if (u->building == b) {
                        c += u->number;
                        if (c > buildingcapacity(b))
                            break;
                        if (u->faction == f) {
                            if (!d)
                                d = distance(r, r2);
                            if (maxd < d)
                                break;
                            if (effskill(u, SK_PERCEPTION, 0) >= d * 3)
                                return true;
                        }
                    }
                    else if (c)
                        break;              /* first unit that's no longer in the house ends the search */
                }
            }
            else {
                /* E3A rule: no perception req'd */
                return true;
            }
        }
    }

    return false;
}
Exemple #4
0
int lighthouse_range(const building * b, const faction * f)
{
    int d = 0;
    if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
        int maxd = (int)log10(b->size) + 1;

        if (skill_enabled(SK_PERCEPTION)) {
            region *r = b->region;
            int c = 0;
            int cap = buildingcapacity(b);
            unit *u, *uown = building_owner(b);

            for (u = r->units; u; u = u->next) {
                if (u->building == b || u == uown) {
                    c += u->number;
                    if (c > cap) {
                        break;
                    }
                    else if (f == NULL || u->faction == f) {
                        int sk = effskill(u, SK_PERCEPTION, 0) / 3;
                        d = _max(d, sk);
                        d = _min(maxd, d);
                        if (d == maxd)
                            break;
                    }
                }
                else if (c)
                    break;                /* first unit that's no longer in the house ends the search */
            }
        }
        else {
            /* E3A rule: no perception req'd */
            return maxd;
        }
    }
    return d;
}