Exemplo n.º 1
0
NUMBER generate_prime(int len, int prob) 
{
	NUMBER a_three,a_four;
	NUMBER prim ;
	int i ;
	
	a_add( &a_one, &a_two, &a_three );
	a_add( &a_two, &a_two, &a_four );

	init_rnd();
	
	do {
		gen_number( len, &prim );
	} while ( !prim.n_len );
	
	a_mult( &prim, &a_two, &prim );
	a_mult( &prim, &a_three, &prim );
	a_add( &prim, &a_one, &prim );
	
	for (i=1 ;; i++) {
		if (p_prim( &prim, prob ))
			break;
		if (i % 2)
			a_add( &prim, &a_four, &prim );
		else
			a_add( &prim, &a_two, &prim );
	}
	
	//num_fput( &prim, stdout );
	return prim ;
}
Exemplo n.º 2
0
static void test_attrib_nexttype(CuTest * tc)
{
    attrib_type at_foo = { "foo" };
    attrib_type at_bar = { "bar" };
    attrib *a, *alist = 0;
    CuAssertPtrNotNull(tc, (a = a_new(&at_foo)));
    CuAssertPtrEquals(tc, 0, a->nexttype);
    CuAssertPtrEquals(tc, a, a_add(&alist, a));
    CuAssertPtrEquals(tc, 0, alist->nexttype);

    CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo)));
    CuAssertPtrEquals(tc, 0, alist->nexttype);

    CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
    CuAssertPtrEquals(tc, a, alist->nexttype);
    CuAssertPtrEquals(tc, 0, a->nexttype);

    a_remove(&alist, alist);
    CuAssertPtrEquals(tc, a, alist->nexttype);

    CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
    a_remove(&alist, alist->nexttype);
    CuAssertPtrEquals(tc, a, alist->nexttype);

    a_removeall(&alist, &at_foo);
    a_removeall(&alist, &at_bar);
}
Exemplo n.º 3
0
faction *gm_addfaction(const char *email, plane * p, region * r)
{
  attrib *a;
  unit *u;
  faction *f = calloc(1, sizeof(faction));

  assert(p != NULL);

  /* GM faction */
  a_add(&f->attribs, make_key(atoi36("quest")));
  f->banner = _strdup("quest faction");
  f->name = _strdup("quest faction");
  f->passw = _strdup(itoa36(rng_int()));
  if (set_email(&f->email, email) != 0) {
    log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
  }
  f->race = new_race[RC_TEMPLATE];
  f->age = 0;
  f->lastorders = turn;
  f->alive = true;
  f->locale = default_locale;
  f->options =
    want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN);
  {
    faction *xist;
    int id = atoi36("gm00") - 1;
    do {
      xist = findfaction(++id);
    } while (xist);

    f->no = id;
    addlist(&factions, f);
    fhash(f);
  }

  /* generic permissions */
  a = a_add(&f->attribs, a_new(&at_permissions));
  if (a) {
    attrib *ap = (attrib *) a->data.v;
    const char *keys[] =
      { "gmterf", "gmtele", "gmgive", "gmskil", "gmtake", "gmmsgr", "gmmsgu",
        "gmgate", 0 };
    const char **key_p = keys;
    while (*key_p) {
      add_key(&ap, atoi36(*key_p));
      ++key_p;
    }
    a_add(&ap, make_atgmcreate(resource2item(r_silver)));

    a->data.v = ap;
  }

  /* one initial unit */
  u = create_unit(r, f, 1, new_race[RC_TEMPLATE], 1, "quest master", NULL);
  u->irace = new_race[RC_GNOME];

  return f;
}
Exemplo n.º 4
0
static int do_potion(unit * u, region *r, const potion_type * ptype, int amount)
{
  if (ptype == oldpotiontype[P_LIFE]) {
    int holz = 0;
    static int tree_type = -1;
    static int tree_count = -1;
    if (tree_type < 0) {
      tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1);
      tree_count =
        get_param_int(global.parameters, "rules.magic.wol_effect", 10);
    }
    /* mallorn is required to make mallorn forests, wood for regular ones */
    if (fval(r, RF_MALLORN)) {
      holz = use_pooled(u, rt_find("mallorn"),
        GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
    } else {
      holz = use_pooled(u, rt_find("log"),
        GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
    }
    if (r->land == 0)
      holz = 0;
    if (holz < tree_count * amount) {
      int x = holz / tree_count;
      if (holz % tree_count)
        ++x;
      if (x < amount)
        amount = x;
    }
    rsettrees(r, tree_type, rtrees(r, tree_type) + holz);
    ADDMSG(&u->faction->msgs, msg_message("growtree_effect",
        "mage amount", u, holz));
  } else if (ptype == oldpotiontype[P_HEILWASSER]) {
    u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount);
  } else if (ptype == oldpotiontype[P_PEOPLE]) {
    attrib *a = (attrib *) a_find(r->attribs, &at_peasantluck);
    if (!a)
      a = a_add(&r->attribs, a_new(&at_peasantluck));
    a->data.i += amount;
  } else if (ptype == oldpotiontype[P_HORSE]) {
    attrib *a = (attrib *) a_find(r->attribs, &at_horseluck);
    if (!a)
      a = a_add(&r->attribs, a_new(&at_horseluck));
    a->data.i += amount;
  } else if (ptype == oldpotiontype[P_WAHRHEIT]) {
    fset(u, UFL_DISBELIEVES);
    amount = 1;
  } else if (ptype == oldpotiontype[P_MACHT]) {
    /* Verfünffacht die HP von max. 10 Personen in der Einheit */
    u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4;
  } else {
    change_effect(u, ptype, 10 * amount);
  }
  return amount;
}
Exemplo n.º 5
0
void warden_add_give(unit * src, unit * u, const item_type * itype, int n)
{
    attrib *aw = a_find(u->attribs, &at_warden);
    museumgiveback *gb = NULL;
    museumgivebackcookie *gbc;
    attrib *a;

    /* has the giver a cookie corresponding to the warden */
    for (a = a_find(src->attribs, &at_museumgivebackcookie);
        a && a->type == &at_museumgivebackcookie; a = a->next) {
        if (((museumgivebackcookie *)(a->data.v))->warden_no == u->no)
            break;
    }

    /* if not give it one */
    if (a == NULL || a->type != &at_museumgivebackcookie) {
        a = a_add(&src->attribs, a_new(&at_museumgivebackcookie));
        gbc = (museumgivebackcookie *)a->data.v;
        gbc->warden_no = u->no;
        gbc->cookie = aw->data.i;
        assert(aw->data.i < INT_MAX);
        aw->data.i++;
    }
    else {
        gbc = (museumgivebackcookie *)(a->data.v);
    }

    /* now we search for the warden's corresponding item list */
    for (a = a_find(u->attribs, &at_museumgiveback);
        a && a->type == &at_museumgiveback; a = a->next) {
        gb = (museumgiveback *)a->data.v;
        if (gb->cookie == gbc->cookie) {
            break;
        }
    }

    /* if there's none, give it one */
    if (!gb) {
        a = a_add(&u->attribs, a_new(&at_museumgiveback));
        gb = (museumgiveback *)a->data.v;
        gb->cookie = gbc->cookie;
    }

    /* now register the items */
    i_change(&gb->items, itype, n);

    /* done */

    /* this has a caveat: If the src-unit is destroyed while inside
     * the museum, the corresponding itemlist of the warden will never
     * be removed. to circumvent that in a generic way will be extremly
     * difficult. */
}
Exemplo n.º 6
0
static void test_attrib_remove(CuTest * tc)
{
    attrib_type at_foo = { "foo" };
    attrib *a, *alist = 0;

    CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo)));
    CuAssertPtrNotNull(tc, a = a_add(&alist, a_new(&at_foo)));
    CuAssertIntEquals(tc, 1, a_remove(&alist, a));
    CuAssertPtrNotNull(tc, alist);
    CuAssertIntEquals(tc, 1, a_remove(&alist, alist));
    CuAssertPtrEquals(tc, 0, alist);
}
Exemplo n.º 7
0
static void test_attrib_removeall(CuTest * tc) {
    const attrib_type at_foo = { "foo" };
    const attrib_type at_bar = { "bar" };
    attrib *alist = 0, *a;
    a_add(&alist, a_new(&at_foo));
    a = a_add(&alist, a_new(&at_bar));
    a_add(&alist, a_new(&at_foo));
    a_removeall(&alist, &at_foo);
    CuAssertPtrEquals(tc, a, alist);
    CuAssertPtrEquals(tc, 0, alist->next);
    a_add(&alist, a_new(&at_bar));
    a_add(&alist, a_new(&at_foo));
    a_removeall(&alist, NULL);
    CuAssertPtrEquals(tc, 0, alist);
}
Exemplo n.º 8
0
int change_effect(unit * u, const potion_type * effect, int delta)
{
  if (delta != 0) {
    attrib *a = a_find(u->attribs, &at_effect);
    effect_data *data = NULL;

    while (a && a->type == &at_effect) {
      data = (effect_data *) a->data.v;
      if (data->type == effect) {
        if (data->value + delta == 0) {
          a_remove(&u->attribs, a);
          return 0;
        } else {
          data->value += delta;
          return data->value;
        }
      }
      a = a->next;
    }

    a = a_add(&u->attribs, a_new(&at_effect));
    data = (effect_data *) a->data.v;
    data->type = effect;
    data->value = delta;
    return data->value;
  }
  log_error("change effect with delta==0 for unit %s\n", itoa36(u->no));
  return 0;
}
Exemplo n.º 9
0
static int
use_speedsail(struct unit *u, const struct item_type *itype, int amount,
struct order *ord)
{
    struct plane *p = rplane(u->region);
    unused_arg(amount);
    unused_arg(itype);
    if (p != NULL) {
        ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
    }
    else {
        if (u->ship) {
            attrib *a = a_find(u->ship->attribs, &at_speedup);
            if (a == NULL) {
                a = a_add(&u->ship->attribs, a_new(&at_speedup));
                a->data.sa[0] = 50;     /* speed */
                a->data.sa[1] = 50;     /* decay */
                ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit", u));
                /* Ticket abziehen */
                i_change(&u->items, itype, -1);
                return 0;
            }
            else {
                cmistake(u, ord, 211, MSG_EVENT);
            }
        }
        else {
            cmistake(u, ord, 144, MSG_EVENT);
        }
    }
    return EUNUSABLE;
}
Exemplo n.º 10
0
void set_group(struct unit *u, struct group *g)
{
    attrib *a = NULL;

    if (fval(u, UFL_GROUP)) {
        a = a_find(u->attribs, &at_group);
    }

    if (a) {
        group *og = (group *)a->data.v;
        if (og == g)
            return;
        --og->members;
    }

    if (g) {
        if (!a) {
            a = a_add(&u->attribs, a_new(&at_group));
            fset(u, UFL_GROUP);
        }
        a->data.v = g;
        g->members++;
    }
    else if (a) {
        a_remove(&u->attribs, a);
        freset(u, UFL_GROUP);
    }
}
Exemplo n.º 11
0
static fighter *summon_allies(const fighter *fi, const race *rc, int number) {
    attrib *a;
    unit *mage = fi->unit;
    side *si = fi->side;
    battle *b = si->battle;
    region *r = b->region;
    message *msg;
    unit *u =
        create_unit(r, mage->faction, number, rc, 0, NULL, mage);
    leave(u, true);
    unit_setstatus(u, ST_FIGHT);
    
    u->hp = u->number * unit_max_hp(u);
    
    if (mage->flags & UFL_ANON_FACTION) {
        u->flags |= UFL_ANON_FACTION;
    }
    
    a = a_new(&at_unitdissolve);
    a->data.ca[0] = 0;
    a->data.ca[1] = 100;
    a_add(&u->attribs, a);
    
    msg = msg_message("sp_wolfhowl_effect", "mage amount race", mage, u->number, rc);
    message_all(b, msg);
    msg_release(msg);

    return make_fighter(b, u, si, is_attacker(fi));
}
Exemplo n.º 12
0
void set_movement(attrib ** alist, int type)
{
    attrib *a = a_find(*alist, &at_movement);
    if (a == NULL)
        a = a_add(alist, a_new(&at_movement));
    a->data.i |= type;
}
Exemplo n.º 13
0
static void set_factionstealth(unit *u, faction *f) {
    attrib *a = a_find(u->attribs, &at_otherfaction);
    if (!a)
        a = a_add(&u->attribs, make_otherfaction(f));
    else
        a->data.v = f;
}
Exemplo n.º 14
0
Arquivo: gnuc.c Projeto: 274914765/C
int main(void)
{
    a_add(&i);
    printf("%d\n",i);

    return 0;
}
Exemplo n.º 15
0
int sp_shadowcall(struct castorder * co)
{
    fighter * fi = co->magician.fig;
    int level = co->level;
    double power = co->force;
    battle *b = fi->side->battle;
    region *r = b->region;
    unit *mage = fi->unit;
    attrib *a;
    int force = (int)(get_force(power, 3) / 2);
    unit *u;
    const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" };
    const race *rc = rc_find(races[rng_int() % 3]);
    message *msg;

    u = create_unit(r, mage->faction, force, rc, 0, NULL, mage);
    setstatus(u, ST_FIGHT);

    set_level(u, SK_WEAPONLESS, (int)(power / 2));
    set_level(u, SK_STAMINA, (int)(power / 2));
    u->hp = u->number * unit_max_hp(u);

    a = a_new(&at_unitdissolve);
    a->data.ca[0] = 0;
    a->data.ca[1] = 100;
    a_add(&u->attribs, a);

    make_fighter(b, u, fi->side, is_attacker(fi));
    msg =
        msg_message("sp_shadowcall_effect", "mage amount race", mage, u->number,
        u_race(u));
    message_all(b, msg);
    msg_release(msg);
    return level;
}
Exemplo n.º 16
0
void usetpotionuse(unit * u, const potion_type * ptype)
{
  attrib *a = a_find(u->attribs, &at_potionuser);
  if (!a)
    a = a_add(&u->attribs, a_new(&at_potionuser));
  a->data.v = (void *)ptype;
}
Exemplo n.º 17
0
/* Legt eine neue Verzauberung an. Sollte es schon einen Zauber
 * dieses Typs geben, gibt es den bestehenden zurück.
 */
static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct,
  float vigour, int duration, float effect, int men)
{
  curse *c;
  attrib *a;

  a = a_new(&at_curse);
  a_add(ap, a);
  c = (curse *) a->data.v;

  c->type = ct;
  c->flags = 0;
  c->vigour = vigour;
  c->duration = duration;
  c->effect = effect;
  c->magician = mage;

  c->no = newunitid();
  chash(c);

  switch (c->type->typ) {
    case CURSETYP_NORM:
      break;

    case CURSETYP_UNIT:
    {
      c->data.i = men;
      break;
    }

  }
  return c;
}
Exemplo n.º 18
0
static attrib *set_new_dragon_target(unit * u, region * r, int range)
{
    int max_affinity = 0;
    region *max_region = NULL;
    quicklist *ql, *rlist = regions_in_range(r, range, allowed_dragon);
    int qi;

    for (qi = 0, ql = rlist; ql; ql_advance(&ql, &qi, 1)) {
        region *r2 = (region *)ql_get(ql, qi);
        int affinity = dragon_affinity_value(r2, u);
        if (affinity > max_affinity) {
            max_affinity = affinity;
            max_region = r2;
        }
    }

    ql_free(rlist);

    if (max_region && max_region != r) {
        attrib *a = a_find(u->attribs, &at_targetregion);
        if (!a) {
            a = a_add(&u->attribs, make_targetregion(max_region));
        }
        else {
            a->data.v = max_region;
        }
        return a;
    }
    return NULL;
}
Exemplo n.º 19
0
void building_addaction(building * b, const char *fname, const char *param)
{
    attrib *a = a_add(&b->attribs, a_new(&at_building_action));
    building_action *data = (building_action *)a->data.v;
    data->fname = _strdup(fname);
    if (param) {
        data->param = _strdup(param);
    }
}
Exemplo n.º 20
0
static void
make_wormhole(const building_type * bt_wormhole, region * r1, region * r2)
{
    building *b1 = new_building(bt_wormhole, r1, default_locale);
    building *b2 = new_building(bt_wormhole, r2, default_locale);
    attrib *a1 = a_add(&b1->attribs, a_new(&at_wormhole));
    attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
    wormhole_data *d1 = (wormhole_data *)a1->data.v;
    wormhole_data *d2 = (wormhole_data *)a2->data.v;
    d1->entry = b1;
    d2->entry = b2;
    d1->exit = b2->region;
    d2->exit = b1->region;
    b1->size = bt_wormhole->maxsize;
    b2->size = bt_wormhole->maxsize;
    ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
    ADDMSG(&r2->msgs, msg_message("wormhole_appear", "region", r2));
}
Exemplo n.º 21
0
void usetcontact(unit * u, const unit * u2)
{
  attrib *a = a_find(u->attribs, &at_contact);
  while (a && a->type == &at_contact && a->data.v != u2)
    a = a->next;
  if (a && a->type == &at_contact)
    return;
  a_add(&u->attribs, a_new(&at_contact))->data.v = (void *)u2;
}
Exemplo n.º 22
0
void set_prefix(attrib ** ap, const char *str)
{
  attrib *a = a_find(*ap, &at_raceprefix);
  if (a == NULL) {
    a = a_add(ap, a_new(&at_raceprefix));
  } else {
    free(a->data.v);
  }
  assert(a->type == &at_raceprefix);
  a->data.v = _strdup(str);
}
Exemplo n.º 23
0
/*------Argument Hash-------*/
void ahash(cons_t * cell, char *fname)
{
    int argsize = 0;
    cell = cell->cdr;
    while (cell != NULL) {
	a_add(hash(fname), sgmt_eval(cell).ivalue);
	argsize++;
	cell = cell->cdr;

    }
}
Exemplo n.º 24
0
static void test_attrib_add(CuTest * tc)
{
    attrib_type at_foo = { "foo" };
    attrib_type at_bar = { "bar" };
    attrib *a, *alist = 0;

    CuAssertPtrNotNull(tc, (a = a_new(&at_foo)));
    CuAssertPtrEquals(tc, a, a_add(&alist, a));
    CuAssertPtrEquals(tc, a, alist);

    CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo))));
    CuAssertPtrEquals_Msg(tc, "new attribute not added after existing", alist->next, a);

    CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
    CuAssertPtrEquals_Msg(tc, "new atribute not added at end of list", alist->next->next, a);

    CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo))));
    CuAssertPtrEquals_Msg(tc, "messages not sorted by type", alist->next->next, a);
    a_removeall(&alist, &at_foo);
    a_removeall(&alist, &at_bar);
}
Exemplo n.º 25
0
static void test_otherfaction(CuTest *tc) {
    unit *u;
    faction *f;

    test_setup();
    u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
    f = test_create_faction(NULL);
    config_set("stealth.faction.other", "1");
    CuAssertIntEquals(tc, true, rule_stealth_other());
    CuAssertPtrEquals(tc, u->faction, visible_faction(f, u));
    a_add(&u->attribs, make_otherfaction(f));
    CuAssertPtrEquals(tc, f, visible_faction(f, u));
    test_teardown();
}
Exemplo n.º 26
0
int
use_potion_delayed(unit * u, const item_type * itype, int amount,
  struct order *ord)
{
  const potion_type *ptype = resource2potion(itype->rtype);
  int result = begin_potion(u, ptype, ord);
  if (result)
    return result;

  a_add(&u->attribs, make_potiondelay(u, ptype, amount));

  end_potion(u, ptype, amount);
  return 0;
}
Exemplo n.º 27
0
static void
volcano_destruction(region * volcano, region * r, const char *damage)
{
    attrib *a;
    unit **up;
    int percent = 25, time = 6 + rng_int() % 12;

    rsettrees(r, 2, 0);
    rsettrees(r, 1, 0);
    rsettrees(r, 0, 0);

    a = a_find(r->attribs, &at_reduceproduction);
    if (!a) {
        a = a_add(&r->attribs, make_reduceproduction(percent, time));
    }
    else {
        /* Produktion vierteln ... */
        a->data.sa[0] = (short)percent;
        /* Für 6-17 Runden */
        a->data.sa[1] = (short)(a->data.sa[1] + time);
    }

    /* Personen bekommen 4W10 Punkte Schaden. */

    for (up = &r->units; *up;) {
        unit *u = *up;
        if (u->number) {
            int dead = damage_unit(u, damage, true, false);
            if (dead) {
                ADDMSG(&u->faction->msgs, msg_message("volcano_dead",
                    "unit region dead", u, volcano, dead));
            }
            if (!fval(u->faction, FFL_SELECT)) {
                fset(u->faction, FFL_SELECT);
                ADDMSG(&u->faction->msgs, msg_message("volcanooutbreaknn",
                    "region", r));
            }
        }
        if (u == *up) {
            up = &u->next;
        }
    }

    if (r != volcano) {
        ADDMSG(&r->msgs, msg_message("volcanooutbreak",
            "regionv regionn", volcano, r));
    }
    remove_empty_units_in_region(r);
}
Exemplo n.º 28
0
void usetsiege(unit * u, const struct building *t)
{
  attrib *a = a_find(u->attribs, &at_siege);
  if (!a && t)
    a = a_add(&u->attribs, a_new(&at_siege));
  if (a) {
    if (!t) {
      a_remove(&u->attribs, a);
      freset(u, UFL_SIEGE);
    } else {
      a->data.v = (void *)t;
      fset(u, UFL_SIEGE);
    }
  }
}
Exemplo n.º 29
0
void usettarget(unit * u, const unit * t)
{
  attrib *a = a_find(u->attribs, &at_target);
  if (!a && t)
    a = a_add(&u->attribs, a_new(&at_target));
  if (a) {
    if (!t) {
      a_remove(&u->attribs, a);
      freset(u, UFL_TARGET);
    } else {
      a->data.v = (void *)t;
      fset(u, UFL_TARGET);
    }
  }
}
Exemplo n.º 30
0
void usetprivate(unit * u, const char *str)
{
  attrib *a = a_find(u->attribs, &at_private);

  if (str == NULL) {
    if (a)
      a_remove(&u->attribs, a);
    return;
  }
  if (!a)
    a = a_add(&u->attribs, a_new(&at_private));
  if (a->data.v)
    free(a->data.v);
  a->data.v = _strdup((const char *)str);
}