Exemple #1
0
static void
lc_write(const struct attrib *a, const void *owner, struct storage *store)
{
    building_action *data = (building_action *)a->data.v;
    const char *fname = data->fname;
    const char *fparam = data->param;

    unused_arg(owner);
    WRITE_TOK(store, fname);
    WRITE_TOK(store, fparam ? fparam : NULLSTRING);
}
Exemple #2
0
void write_triggers(struct storage *store, const trigger * t)
{
    while (t) {
        if (t->type->write) {
            WRITE_TOK(store, t->type->name);
            t->type->write(t, store);
        }
        t = t->next;
    }
    WRITE_TOK(store, "end");
}
Exemple #3
0
static void
a_writedirection(const attrib * a, const void *owner, struct storage *store)
{
    spec_direction *d = (spec_direction *)(a->data.v);

    unused_arg(owner);
    WRITE_INT(store, d->x);
    WRITE_INT(store, d->y);
    WRITE_INT(store, d->duration);
    WRITE_TOK(store, d->desc);
    WRITE_TOK(store, d->keyword);
}
Exemple #4
0
static void giveitem_write(const trigger * t, struct storage *store)
{
    giveitem_data *td = (giveitem_data *)t->data.v;
    write_unit_reference(td->u, store);
    WRITE_INT(store, td->number);
    WRITE_TOK(store, td->itype->rtype->_name);
}
Exemple #5
0
static void
write_handler(const attrib * a, const void *owner, struct storage *store)
{
    handler_info *hi = (handler_info *)a->data.v;
    WRITE_TOK(store, hi->event);
    write_triggers(store, hi->triggers);
}
Exemple #6
0
static void
a_writeeffect(const attrib * a, const void *owner, struct storage *store)
{
  effect_data *edata = (effect_data *) a->data.v;
  WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0));
  WRITE_INT(store, edata->value);
}
Exemple #7
0
static void
write_gmcreate(const attrib * a, const void *owner, struct storage *store)
{
  const item_type *itype = (const item_type *)a->data.v;
  assert(itype);
  WRITE_TOK(store, resourcename(itype->rtype, 0));
}
Exemple #8
0
void curse_write(const attrib * a, const void *owner, struct storage *store)
{
  unsigned int flags;
  curse *c = (curse *) a->data.v;
  const curse_type *ct = c->type;
  unit *mage = (c->magician && c->magician->number) ? c->magician : NULL;

  /* copied from c_clearflag */
  flags = (c->flags & ~CURSE_ISNEW) | (c->type->flags & CURSE_ISNEW);

  WRITE_INT(store, c->no);
  WRITE_TOK(store, ct->cname);
  WRITE_INT(store, flags);
  WRITE_INT(store, c->duration);
  WRITE_FLT(store, (float)c->vigour);
  write_unit_reference(mage, store);
  WRITE_FLT(store, (float)c->effect);

  if (c->type->write)
    c->type->write(store, c, owner);
  else if (c->type->typ == CURSETYP_UNIT) {
    WRITE_INT(store, c->data.i);
  }
  if (c->type->typ == CURSETYP_REGION) {
    write_region_reference((region *) c->data.v, store);
  }
}
Exemple #9
0
static void unitmessage_write(const trigger * t, struct storage *store)
{
  unitmessage_data *td = (unitmessage_data *) t->data.v;
  write_unit_reference(td->target, store);
  WRITE_TOK(store, td->string);
  WRITE_INT(store, td->type);
  WRITE_INT(store, td->level);
}
Exemple #10
0
void a_write(struct storage *store, const attrib * attribs, const void *owner)
{
    const attrib *na = attribs;

    while (na) {
        if (na->type->write) {
            assert(na->type->hashkey || !"attribute not registered");
            WRITE_TOK(store, na->type->name);
            na->type->write(na, owner, store);
            na = na->next;
        }
        else {
            na = na->nexttype;
        }
    }
    WRITE_TOK(store, "end");
}
static void createcurse_write(const trigger * t, struct storage *store)
{
    createcurse_data *td = (createcurse_data *)t->data.v;
    write_unit_reference(td->mage, store);
    write_unit_reference(td->target, store);
    WRITE_TOK(store, td->type->cname);
    WRITE_FLT(store, (float)td->vigour);
    WRITE_INT(store, td->duration);
    WRITE_FLT(store, (float)td->effect);
    WRITE_INT(store, td->men);
}
void write_borders(struct storage *store)
{
    int i;
    for (i = 0; i != BORDER_MAXHASH; ++i) {
        connection *bhash;
        for (bhash = borders[i]; bhash; bhash = bhash->nexthash) {
            connection *b;
            for (b = bhash; b != NULL; b = b->next) {
                if (b->type->valid && !b->type->valid(b))
                    continue;
                WRITE_TOK(store, b->type->__name);
                WRITE_INT(store, b->id);
                WRITE_INT(store, b->from->uid);
                WRITE_INT(store, b->to->uid);

                if (b->type->write)
                    b->type->write(b, store);
                WRITE_SECTION(store);
            }
        }
    }
    WRITE_TOK(store, "end");
}
Exemple #13
0
static void
object_write(const attrib * a, const void *owner, struct storage *store)
{
  const object_data *data = (object_data *) a->data.v;
  int type = (int)data->type;
  WRITE_TOK(store, data->name);
  WRITE_INT(store, type);
  switch (data->type) {
    case TINTEGER:
      WRITE_INT(store, data->data.i);
      break;
    case TREAL:
      WRITE_FLT(store, (float)data->data.real);
      break;
    case TSTRING:
      WRITE_STR(store, data->data.str);
      break;
    case TUNIT:
      write_unit_reference(data->data.u, store);
      break;
    case TFACTION:
      write_faction_reference(data->data.f, store);
      break;
    case TBUILDING:
      write_building_reference(data->data.b, store);
      break;
    case TSHIP:
      /* write_ship_reference(data->data.sh, store); */
      assert(!"not implemented");
      break;
    case TREGION:
      write_region_reference(data->data.r, store);
      break;
    case TNONE:
      break;
    default:
      assert(!"illegal type in object-attribute");
  }
}
Exemple #14
0
static void test_memstream(CuTest *tc) {
    storage store;
    stream out = { 0 };
    char buf[1024];
    int val=0;

    mstream_init(&out);
    binstore_init(&store, &out);
    store.handle.data = &out;

    WRITE_INT(&store, 999999);
    WRITE_TOK(&store, "fortytwo");
    WRITE_INT(&store, 42);

    out.api->rewind(out.handle);
    READ_INT(&store, &val);
    READ_TOK(&store, buf, 1024);
    CuAssertIntEquals(tc, 999999, val);
    CuAssertStrEquals(tc, "fortytwo", buf);
    READ_INT(&store, &val);
    CuAssertIntEquals(tc, 42, val);
    mstream_done(&out);
}
Exemple #15
0
static void xmasgate_write(const trigger * t, struct storage *store)
{
    building *b = (building *)t->data.v;
    WRITE_TOK(store, itoa36(b->no));
}
Exemple #16
0
void write_race_reference(const race * rc, struct storage *store)
{
  WRITE_TOK(store, rc ? rc->_name[0] : "none");
}
Exemple #17
0
static void removecurse_write(const trigger * t, struct storage *store)
{
  removecurse_data *td = (removecurse_data *) t->data.v;
  WRITE_TOK(store, td->target ? itoa36(td->target->no) : 0);
  WRITE_INT(store, td->curse ? td->curse->no : 0);
}