Пример #1
0
static int
enter_arena(unit * u, const item_type * itype, int amount, order * ord)
{
  skill_t sk;
  region *r = u->region;
  unit *u2;
  int fee = u->faction->score / 5;
  unused(ord);
  unused(amount);
  unused(itype);
  if (fee > 2000)
    fee = 2000;
  if (getplane(r) == arena)
    return -1;
  if (u->number != 1 && enter_fail(u))
    return -1;
  if (get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, fee) < fee
    && enter_fail(u))
    return -1;
  for (sk = 0; sk != MAXSKILLS; ++sk) {
    if (get_level(u, sk) > 1 && enter_fail(u))
      return -1;
  }
  for (u2 = r->units; u2; u2 = u2->next)
    if (u2->faction == u->faction)
      break;

  assert(!"not implemented");
/*
	for (res=0;res!=MAXRESOURCES;++res) if (res!=R_SILVER && res!=R_ARENA_GATE && (is_item(res) || is_herb(res) || is_potion(res))) {
		int x = get_resource(u, res);
		if (x) {
			if (u2) {
				change_resource(u2, res, x);
				change_resource(u, res, -x);
			}
			else if (enter_fail(u)) return -1;
		}
	}
*/
  if (get_money(u) > fee) {
    if (u2)
      change_money(u2, get_money(u) - fee);
    else if (enter_fail(u))
      return -1;
  }
  ADDMSG(&u->faction->msgs, msg_message("arena_enter_fail", "region unit",
      u->region, u));
  use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE, 1);
  use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, fee);
  set_money(u, 109);
  fset(u, UFL_ANON_FACTION);
  move_unit(u, start_region[rng_int() % 6], NULL);
  return 0;
}
Пример #2
0
void c_user::sell()
{
  std::normal_distribution<float> distribution_norm(m_market_ptr->get_current_price(), 50);
  float rand = distribution_norm(m_rand_generator);
  unsigned int price = std::floor(rand + 0.5);
  std::uniform_int_distribution<int> distribution_linear(10000,100000);
  unsigned int number_of_tokens = distribution_linear(m_rand_generator);
  number_of_tokens = get_money(number_of_tokens, e_currency::BTC);
  std::cout << "User " << m_ID << " want to sell " << number_of_tokens << " for " << price << std::endl;
  m_market_ptr->sell(e_currency::BTC, number_of_tokens, m_ID, price);  
  
}
Пример #3
0
/**
 * \brief Sets the maximum amount of money of the player.
 * \param max_money the player's maximum amount number of money
 */
void Equipment::set_max_money(int max_money) {

  Debug::check_assertion(max_money >= 0, "Invalid money amount to add");

  savegame.set_integer(Savegame::KEY_MAX_MONEY, max_money);

  // If the max money is reduced, make sure the current money does not exceed
  // the new maximum.
  if (get_money() > get_max_money()) {
    set_money(max_money);
  }
}
Пример #4
0
static int all_money(region * r, faction * f)
{
    unit *u;
    int m;

    m = rmoney(r);
    for (u = r->units; u; u = u->next) {
        if (f != u->faction) {
            m += get_money(u);
        }
    }
    return m;
}
Пример #5
0
static void help_feed(unit * donor, unit * u, int *need_p)
{
    int need = *need_p;
    int give = get_money(donor) - lifestyle(donor);
    give = _min(need, give);

    if (give > 0) {
        change_money(donor, -give);
        change_money(u, give);
        need -= give;
        add_spende(donor->faction, u->faction, give, donor->region);
    }
    *need_p = need;
}
Пример #6
0
/**
 * \brief Sets the maximum amount of money of the player.
 * \param max_money the player's maximum amount number of money
 */
void Equipment::set_max_money(int max_money) {

  if (max_money <= 0) {
    std::ostringstream oss;
    oss << "Illegal maximum amount of money: " << max_money;
    Debug::die(oss.str());
  }

  savegame.set_integer(Savegame::KEY_MAX_MONEY, max_money);

  // If the max money is reduced, make sure the current money does not exceed
  // the new maximum.
  if (get_money() > get_max_money()) {
    set_money(max_money);
  }
}
Пример #7
0
static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
{
    int n;
    bool attacks = attack_chance > 0.0;

    /* falls genug geld in der region ist, treiben wir steuern ein. */
    if (rmoney(r) >= wanted) {
        /* 5% chance, dass der drache aus einer laune raus attackiert */
        if (!attacks || chance(1.0 - u_race(udragon)->aggression)) {
            /* Drachen haben in E3 und E4 keine Einnahmen. Neuer Befehl Pluendern erstmal nur fuer Monster?*/
            return create_order(K_LOOT, default_locale, NULL);
        }
    }

    /* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an
     * und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
    n = 0;
    if (attacks && is_guard(udragon, GUARD_TAX)) {
        unit *u;
        for (u = r->units; u; u = u->next) {
            if (u->faction != udragon->faction && cansee(udragon->faction, r, u, 0) && !in_safe_building(u, udragon)) {
                int m = get_money(u);
                if (m != 0) {
                    order *ord = monster_attack(udragon, u);
                    if (ord) {
                        addlist(&udragon->orders, ord);
                        n += m;
                    }
                }
            }
        }
    }

    /* falls die einnahmen erreicht werden, bleibt das monster noch eine */
    /* runde hier. */
    if (n + rmoney(r) >= wanted) {
        return create_order(K_LOOT, default_locale, NULL);
    }

    /* wenn wir NULL zurueckliefern, macht der drache was anderes, z.b. weggehen */
    return NULL;
}
Пример #8
0
void CAI_Stalker::update_sell_info					()
{
	if (m_sell_info_actuality)
		return;

	m_sell_info_actuality	= true;

	m_temp_items.clear		();
	m_current_trader		= 0;
	m_total_money			= get_money();
	u32						money_delta = fill_items(inventory(),this,ALife::_OBJECT_ID(-1));
	m_total_money			+= money_delta;
	std::sort				(m_temp_items.begin(),m_temp_items.end());
	select_items			();

	TIItemContainer::iterator	I = inventory().m_all.begin();
	TIItemContainer::iterator	E = inventory().m_all.end();
	for ( ; I != E; ++I) {
		if (!tradable_item(*I,ID()))
			m_temp_items.push_back	(CTradeItem(*I,ID(),ID()));
	}
}
Пример #9
0
void do_split( char_data* ch, char* argument )
{
  int amount;

  if( *argument == '\0' ) {
    send( ch, "What amount do you wish to split?\r\n" );
    return;
    }

  amount = atoi( argument );

  if( amount < 2 ) {
    send( ch, "It is difficult to split anything less than 2 cp.\r\n" );
    return;
    }
 
  if( get_money( ch ) < amount ) {
    send( ch, "You don't have enough coins to split that amount.\r\n" );
    return;
    }

  split_money( ch, amount, TRUE );
}
Пример #10
0
void destroyfaction(faction ** fp)
{
    faction * f = *fp;
    unit *u = f->units;

    *fp = f->next;
    f->next = dead_factions;
    dead_factions = f;

    fset(f, FFL_QUIT);
    f->_alive = false;

    if (f->spellbook) {
        spellbook_clear(f->spellbook);
        free(f->spellbook);
        f->spellbook = 0;
    }

    if (f->seen_factions) {
        selist_free(f->seen_factions);
        f->seen_factions = 0;
    }

    while (u) {
        /* give away your stuff, to ghosts if you cannot (quest items) */
        if (u->items) {
            region *r = u->region;
            int result = gift_items(u, GIFT_FRIENDS | GIFT_PEASANTS);
            if (result != 0) {
                save_special_items(u);
            }
            if (r->land && !!playerrace(u_race(u))) {
                const race *rc = u_race(u);
                int m = rmoney(r);

                /* Personen gehen nur an die Bauern, wenn sie auch von dort
                    * stammen */
                if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) {
                    int p = rpeasants(u->region);
                    int h = rhorses(u->region);
                    item *itm;

                    p += (int)(u->number * rc->recruit_multi);
                    for (itm = u->items; itm; itm = itm->next) {
                        if (itm->type->flags & ITF_ANIMAL) {
                            h += itm->number;
                        }
                    }
                    rsetpeasants(r, p);
                    rsethorses(r, h);
                }
                m += get_money(u);
                rsetmoney(r, m);
            }
        }
        set_number(u, 0);
        u = u->nextF;
    }

    handle_event(f->attribs, "destroy", f);
    if (f->alliance) {
        setalliance(f, NULL);
    }

    funhash(f);

    /* units of other factions that were disguised as this faction
     * have their disguise replaced by ordinary faction hiding. */
    if (rule_stealth_other()) {
        region *rc;
        for (rc = regions; rc; rc = rc->next) {
            for (u = rc->units; u; u = u->next) {
                if (u->attribs && get_otherfaction(u) == f) {
                    a_removeall(&u->attribs, &at_otherfaction);
                    if (rule_stealth_anon()) {
                        fset(u, UFL_ANON_FACTION);
                    }
                }
            }
        }
    }
}
Пример #11
0
int
gagb()
{
	int             money;
	char            genbuf[200], buf[80];
	char            ans[5] = "";
	/* ±¶ÂÊ        0  1   2   3   4   5   6   7   8   9   10 */
	float           bet[11] = {0, 100, 50, 10, 3, 1.5, 1.2, 0.9, 0.8, 0.5, 0.1};
	int             a, b, c, count;

	modify_user_mode(M_XAXB);
	srandom(time(0));
	money = get_money(0,"game/gagb.welcome");
	if(!money) return 0;
	move(6, 0);
	prints("%s", MSG_SEPERATOR);
	move(17, 0);
	prints("%s", MSG_SEPERATOR);

	do {
		itoa(random() % 10000, ans);
		for (a = 0; a < 3; a++)
			for (b = a + 1; b < 4; b++)
				if (ans[a] == ans[b])
					ans[0] = 0;
	} while (!ans[0]);

	for (count = 1; count < 11; count++) {
		do {
			getdata(5, 0, "Çë²Â[q - Í˳ö] ¡ú ", genbuf, 5, DOECHO, YEA);
			if (!strcmp(genbuf, "Good")) {
				prints("[%s]", ans);
				sprintf(genbuf,"²ÂÊý×Ö×÷±×, ÏÂ×¢ %d Ôª", money);
				gamelog(genbuf);
				igetch();
			}
			if ( genbuf[0] == 'q' || genbuf[0] == 'Q' ) {
				sprintf(buf,"·ÅÆú²Â²â, ¿Û³ýѹע½ð¶î %d Ôª.", money);
				gamelog(buf);
				return;
			}
			c = atoi(genbuf);
			itoa(c, genbuf);
			for (a = 0; a < 3; a++)
				for (b = a + 1; b < 4; b++)
					if (genbuf[a] == genbuf[b])
						genbuf[0] = 0;
			if (!genbuf[0]) {
				move ( 18,3 );
				prints("ÊäÈëÊý×ÖÓÐÎÊÌâ!!");
				pressanykey();
				move ( 18,3 );
				prints("                ");
			}
		} while (!genbuf[0]);
		move(count + 6, 0);
		prints("  µÚ %2d ´Î£º %s  ->  %dA %dB ", count, genbuf, an(genbuf, ans), bn(genbuf, ans));
		if (an(genbuf, ans) == 4)
			break;
	}

	if (count > 10) {
		sprintf(buf, "ÄãÊäÁËßÏ£¡ÕýÈ·´ð°¸ÊÇ %s£¬Ï´ÎÔÙ¼ÓÓÍ°É!!", ans);
		sprintf(genbuf,"¿ÉÁ¯Ã»²Âµ½£¬ÊäÁË %d Ôª£¡", money);
		gamelog(genbuf);
	} else {
		int             oldmoney = money;
		money *= bet[count];
		inmoney(money);
		if (money - oldmoney > 0)
			sprintf(buf, "¹§Ï²£¡×ܹ²²ÂÁË %d ´Î£¬¾»×¬½±½ð %d Ôª", count, money - oldmoney);
		else if (money - oldmoney == 0)
			sprintf(buf, "°¦¡«¡«×ܹ²²ÂÁË %d ´Î£¬Ã»ÊäûӮ£¡", count);
		else
			sprintf(buf, "°¡¡«¡«×ܹ²²ÂÁË %d ´Î£¬ÅâÇ® %d Ôª£¡", count, oldmoney - money);
	}
	gamelog(buf);
	move(22, 0);
        clrtobot();
	prints(buf);
	pressanykey();
	return 0;
}
Пример #12
0
summary *make_summary(void)
{
    faction *f;
    region *r;
    unit *u;
    summary *s = calloc(1, sizeof(summary));
    const struct resource_type *rhorse = get_resourcetype(R_HORSE);

  for (f = factions; f; f = f->next) {
    const struct locale *lang = f->locale;
    struct language *plang = s->languages;
    while (plang && plang->locale != lang)
      plang = plang->next;
    if (!plang) {
      plang = calloc(sizeof(struct language), 1);
      plang->next = s->languages;
      s->languages = plang;
      plang->locale = lang;
    }
    ++plang->number;
    f->nregions = 0;
    f->num_total = 0;
    f->money = 0;
    if (f->alive && f->units) {
      s->factions++;
      /* Problem mit Monsterpartei ... */
      if (!is_monsters(f)) {
        s->factionrace[old_race(f->race)]++;
      }
    }
  }

  /* count everything */

  for (r = regions; r; r = r->next) {
    s->pferde += rhorses(r);
    s->schiffe += listlen(r->ships);
    s->gebaeude += listlen(r->buildings);
    if (!fval(r->terrain, SEA_REGION)) {
      s->landregionen++;
      if (r->units) {
        s->landregionen_mit_spielern++;
      }
      if (fval(r, RF_ORCIFIED)) {
        s->orkifizierte_regionen++;
      }
      if (r->terrain == newterrain(T_VOLCANO)) {
        s->inactive_volcanos++;
      } else if (r->terrain == newterrain(T_VOLCANO_SMOKING)) {
        s->active_volcanos++;
      }
    }
    if (r->units) {
      s->regionen_mit_spielern++;
    }
    if (rpeasants(r) || r->units) {
      s->inhabitedregions++;
      s->peasants += rpeasants(r);
      s->peasantmoney += rmoney(r);

      /* Einheiten Info. nregions darf nur einmal pro Partei
       * incrementiert werden. */

      for (u = r->units; u; u = u->next)
        freset(u->faction, FFL_SELECT);
      for (u = r->units; u; u = u->next) {
        f = u->faction;
        if (!is_monsters(u->faction)) {
          skill *sv;
          item *itm;

          s->nunits++;
          s->playerpop += u->number;
          if (u->flags & UFL_HERO) {
            s->heroes += u->number;
          }
          s->spielerpferde += i_get(u->items, rhorse->itype);
          s->playermoney += get_money(u);
          s->armed_men += armedmen(u, true);
          for (itm = u->items; itm; itm = itm->next) {
            if (itm->type->rtype->wtype) {
              s->waffen += itm->number;
            }
            if (itm->type->rtype->atype) {
              s->ruestungen += itm->number;
            }
          }

          s->spielerpferde += i_get(u->items, rhorse->itype);

          for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
            skill_t sk = sv->id;
            int aktskill = eff_skill(u, sk, r);
            if (aktskill > s->maxskill)
              s->maxskill = aktskill;
          }
          if (!fval(f, FFL_SELECT)) {
            f->nregions++;
            fset(f, FFL_SELECT);
          }
        }

        f->num_total += u->number;
        f->money += get_money(u);
        s->poprace[old_race(u_race(u))] += u->number;
      }
    }
  }

  return s;
}
Пример #13
0
void do_list( char_data* ch, char* argument )
{
  char_data*   keeper;
  char_data*      pet;
  thing_array*  array;
  obj_data*       obj;
  room_data*     room;
  int i;

  if( ( keeper = find_keeper( ch ) ) == NULL )
    return;

  if( *argument == '\0' )
    argument = "all";

  /* PET SHOP */

  if( is_set( &ch->in_room->room_flags, RFLAG_PET_SHOP ) ) {
    if( ( room = get_room_index( ch->in_room->vnum+1 ) ) == NULL ) {
      send( ch, "The pet shop is still under construction.\r\n" );
      return;
      }

    thing_array list;

    for( i = 0; i < room->contents; i++ ) 
      if( ( pet = character( room->contents[i] ) ) != NULL
        && buyable_pet( pet ) )
        list += pet;

    if( is_empty( list ) ) {
      process_tell( keeper, ch, "Sorry, I'm out of pets right now.\r\n" );
      return;
      }

    if( ( array = several_things( ch, argument, "list", &list ) ) == NULL )
      return;

    send( ch, "Copper Pieces: %d\r\n\r\n", get_money( ch ) );
    send_underlined( ch,
      "Pet                          Cost    Level\r\n" );

    for( i = 0; i < *array; i++ ) {
      pet = (char_data*) array->list[i];
      send( ch, "%-25s%8d%8d\r\n", pet->Seen_Name( ch, 1, TRUE ),
        pet->species->price, pet->shdata->level );
      }

    delete array;

    return;
    }

  /* OBJECT SHOP */

  thing_array list;

  for( i = 0; i < keeper->contents; i++ ) {
    obj = (obj_data*) keeper->contents[i];
    obj->selected = 1;
    if( ( obj->temp = get_cost( keeper, ch, obj, TRUE ) ) > 0 )
      list += obj;
    }

  if( is_empty( list ) ) {
    process_tell( keeper, ch,
      "Sorry, I have nothing to sell right now.\r\n" );
    return;
    }

  if( ( array = several_things( ch, argument, "list",  &list ) ) == NULL )
    return;

  page( ch, "Copper Pieces: %d\r\n\r\n", get_money( ch ) );
  page_underlined( ch, "Item                                     Cost\
    Level   Number   Condition\r\n" );

  char level [ 5 ];

  include_closed = FALSE;

  for( i = 0; i < *array; i++ ) {
    obj = (obj_data*) array->list[i];

    if( !can_use( ch, obj->pIndexData, obj ) )
      sprintf( level, "***" );
    else
      sprintf( level, "%d", obj->pIndexData->level );

    page( ch, "%-37s%8d%8s%8d%5s%-s\r\n",
      truncate( (char *) obj->Seen_Name( ch, 1, TRUE ), 37 ), obj->temp, level,
      obj->number, "", obj->condition_name( ch, TRUE ) );
    }

  include_closed = TRUE;

  delete array;
}
Пример #14
0
/**
 * \brief Removes some money from the player.
 *
 * If the money reaches zero, no more money is removed.
 *
 * \param money_to_remove amount of money to remove
 */
void Equipment::remove_money(int money_to_remove) {

  set_money(get_money() - money_to_remove);
}
Пример #15
0
/**
 * \brief Adds some money to the player.
 *
 * If the maximum amount of money is reached, no more money is added.
 * 
 * \param money_to_add amount of money to add
 */
void Equipment::add_money(int money_to_add) {

  set_money(get_money() + money_to_add);
}
Пример #16
0
static void get_allies(region * r, unit * u)
{
  unit *newunit = NULL;
  const char *name;
  const char *equip;
  int number;
  message *msg;

  assert(u->number);

  switch (rterrain(r)) {
    case T_PLAIN:
      if (!r_isforest(r)) {
        if (get_money(u) / u->number < 100 + rng_int() % 200)
          return;
        name = "random_plain_men";
        equip = "random_plain";
        number = rng_int() % 8 + 2;
        break;
      } else {
        if (eff_skill(u, SK_LONGBOW, r) < 3
          && eff_skill(u, SK_HERBALISM, r) < 2
          && eff_skill(u, SK_MAGIC, r) < 2) {
          return;
        }
        name = "random_forest_men";
        equip = "random_forest";
        number = rng_int() % 6 + 2;
      }
      break;

    case T_SWAMP:
      if (eff_skill(u, SK_MELEE, r) <= 1) {
        return;
      }
      name = "random_swamp_men";
      equip = "random_swamp";
      number = rng_int() % 6 + 2;
      break;

    case T_DESERT:
      if (eff_skill(u, SK_RIDING, r) <= 2) {
        return;
      }
      name = "random_desert_men";
      equip = "random_desert";
      number = rng_int() % 12 + 2;
      break;

    case T_HIGHLAND:
      if (eff_skill(u, SK_MELEE, r) <= 1) {
        return;
      }
      name = "random_highland_men";
      equip = "random_highland";
      number = rng_int() % 8 + 2;
      break;

    case T_MOUNTAIN:
      if (eff_skill(u, SK_MELEE, r) <= 1 || eff_skill(u, SK_TRADE, r) <= 2) {
        return;
      }
      name = "random_mountain_men";
      equip = "random_mountain";
      number = rng_int() % 6 + 2;
      break;

    case T_GLACIER:
      if (eff_skill(u, SK_MELEE, r) <= 1 || eff_skill(u, SK_TRADE, r) <= 1) {
        return;
      }
      name = "random_glacier_men";
      equip = "random_glacier";
      number = rng_int() % 4 + 2;
      break;

    default:
      return;
  }

  newunit =
    create_unit(r, u->faction, number, u->faction->race, 0,
    LOC(u->faction->locale, name), u);
  equip_unit(newunit, get_equipment(equip));

  u_setfaction(newunit, u->faction);
  set_racename(&newunit->attribs, get_racename(u->attribs));
  if (u_race(u)->flags & RCF_SHAPESHIFT) {
    newunit->irace = u->irace;
  }
  if (fval(u, UFL_ANON_FACTION))
    fset(newunit, UFL_ANON_FACTION);
  fset(newunit, UFL_ISNEW);

  msg = msg_message("encounter_allies", "unit name", u, name);
  r_addmessage(r, u->faction, msg);
  msg_release(msg);
}
Пример #17
0
/**
 * \brief Adds some money to the player.
 *
 * If the maximum amount of money is reached, no more money is added.
 *
 * \param money_to_add Amount of money to add.
 * Must be positive of zero.
 */
void Equipment::add_money(int money_to_add) {

  Debug::check_assertion(money_to_add >= 0, "Invalid money amount to add");

  set_money(get_money() + money_to_add);
}
Пример #18
0
static order *plan_dragon(unit * u)
{
    attrib *ta = a_find(u->attribs, &at_targetregion);
    region *r = u->region;
    region *tr = NULL;
    bool move = false;
    order *long_order = NULL;

    if (ta == NULL) {
        move |= (r->land == 0 || r->land->peasants == 0);   /* when no peasants, move */
        move |= (r->land == 0 || r->land->money == 0);      /* when no money, move */
    }
    move |= chance(0.04);         /* 4% chance to change your mind */

    if (u_race(u) == get_race(RC_WYRM) && !move) {
        unit *u2;
        for (u2 = r->units; u2; u2 = u2->next) {
            /* wyrme sind einzelgänger */
            if (u2 == u) {
                /* we do not make room for newcomers, so we don't need to look at them */
                break;
            }
            if (u2 != u && u_race(u2) == u_race(u) && chance(0.5)) {
                move = true;
                break;
            }
        }
    }

    if (move) {
        /* dragon gets bored and looks for a different place to go */
        ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
    }
    else
        ta = a_find(u->attribs, &at_targetregion);
    if (ta != NULL) {
        tr = (region *)ta->data.v;
        if (tr == NULL || !path_exists(u->region, tr, DRAGON_RANGE, allowed_dragon)) {
            ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
            if (ta)
                tr = findregion(ta->data.sa[0], ta->data.sa[1]);
        }
    }
    if (tr != NULL) {
        assert(long_order == NULL);
        switch (old_race(u_race(u))) {
        case RC_FIREDRAGON:
            long_order = make_movement_order(u, tr, 4, allowed_dragon);
            break;
        case RC_DRAGON:
            long_order = make_movement_order(u, tr, 3, allowed_dragon);
            break;
        case RC_WYRM:
            long_order = make_movement_order(u, tr, 1, allowed_dragon);
            break;
        default:
            break;
        }
        if (long_order) {
            reduce_weight(u);
        }
        if (rng_int() % 100 < 15) {
            const struct locale *lang = u->faction->locale;
            /* do a growl */
            if (rname(tr, lang)) {
                addlist(&u->orders,
                    create_order(K_MAIL, lang, "%s '%s... %s %s %s'",
                    LOC(lang, parameters[P_REGION]),
                    random_growl(),
                    u->number ==
                    1 ? "Ich rieche" : "Wir riechen",
                    "etwas in", rname(tr, u->faction->locale)));
            }
        }
    }
    else {
        /* we have no target. do we like it here, then? */
        long_order = get_money_for_dragon(u->region, u, income(u));
        if (long_order == NULL) {
            /* money is gone, need a new target */
            set_new_dragon_target(u, u->region, DRAGON_RANGE);
        }
        else if (u_race(u) != get_race(RC_FIREDRAGON)) {
            /* neue dracoiden! */
            if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) {
                int ra = 20 + rng_int() % 100;
                if (get_money(u) > ra * 50 + 100 && rng_int() % 100 < 50) {
                    recruit_dracoids(u, ra);
                }
            }
        }
    }
    if (long_order == NULL) {
        skill_t sk = SK_PERCEPTION;
        /* study perception (or a random useful skill) */
        while (!skill_enabled(sk) || u_race(u)->bonus[sk] < -5) {
            sk = (skill_t)(rng_int() % MAXSKILLS);
        }
        long_order = create_order(K_STUDY, u->faction->locale, "'%s'",
            skillname(sk, u->faction->locale));
    }
    return long_order;
}
Пример #19
0
/* ºÚ½Ü¿ËÓÎÏ· */
int 
BlackJack()
{
	int             num[52] = {11, 11, 11, 11, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6,
		7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
	10, 10, 10, 10, 10, 10, 10, 10};
	int             cardlist[52] = {0};
	int             i, j, m, tmp = 0, tmp2, ch;
	int             win = 2, win_jack = 5;	/* win ΪӮʱµÄ±¶ÂÊ, win_jack
						 * 1 µã±¶ÂÊ */
	int             six = 10, seven = 20, aj = 10, super_jack = 20;	/* 777, A+J, spade A+J µÄ±¶ÂÊ */
	int             host_count = 2, guest_count = 1, card_count = 3,
	                A_count = 0, AA_count = 0;
	int             host_point = 0, guest_point = 0, mov_y = 4;
	int             host_card[12] = {0}, guest_card[12] = {0};
	long int        money;

	int             CHEAT = 0;	/* ×ö±×²ÎÊý, 1 ¾Í×÷±×, 0 ¾Í²»×÷ */

	modify_user_mode(M_BLACKJACK);
	money = get_money(0,"game/blackjack.welcome");
	if(!money) return 0;
	move(1, 0);
	prints("¡¾ºÚ½Ü¿Ë¡¿ÓÎÏ·  [°´ y ÐøÅÆ, n ²»ÐøÅÆ, d double, q ÈÏÊäÍ˳ö]");
	move(0, 0);
	clrtoeol();
        srandom(time(0));
	for (i = 1; i <= 52; i++) {
		m = 0;
		do {
			j = random() % 52;
			if (cardlist[j] == 0) {
				cardlist[j] = i;
				m = 1;
			}
		} while (m == 0);
	};
	for (i = 0; i < 52; i++)
		cardlist[i]--;	/* Ï´ÅÆ */

	if (money >= 20000)
		CHEAT = 1;
	if (CHEAT == 1) {
		if (cardlist[1] <= 3) {
			tmp2 = cardlist[50];
			cardlist[50] = cardlist[1];
			cardlist[1] = tmp2;
		}
	}			/* ×÷±×Âë */
	host_card[0] = cardlist[0];
	if (host_card[0] < 4)
		AA_count++;
	guest_card[0] = cardlist[1];

	if (guest_card[0] < 4)
		A_count++;
	host_card[1] = cardlist[2];
	if (host_card[1] < 4)
		AA_count++;	/* ·¢Ç°ÈýÕÅÅÆ */

	move(5, 0);
	prints("¨q©¤©¤©¤¨r");
	move(6, 0);
	prints("©¦      ©¦");
	move(7, 0);
	prints("©¦      ©¦");
	move(8, 0);
	prints("©¦      ©¦");
	move(9, 0);
	prints("©¦      ©¦");
	move(10, 0);
	prints("©¦      ©¦");
	move(11, 0);
	prints("¨t©¤©¤©¤¨s");
	print_card(host_card[1], 5, 4);
	print_card(guest_card[0], 15, 0);	/* Ó¡³öÇ°ÈýÕÅÅÆ */

	host_point = num[host_card[1]];
	guest_point = num[guest_card[0]];

	do {
		m = 1;
		guest_card[guest_count] = cardlist[card_count];
		if (guest_card[guest_count] < 4)
			A_count++;
		print_card(guest_card[guest_count], 15, mov_y);
		guest_point += num[guest_card[guest_count]];

		if ((guest_card[0] >= 24 && guest_card[0] <= 27) && (guest_card[1] >= 24 && guest_card[1] <= 27) && (guest_card[2] >= 24 && guest_card[2] <= 27)) {
			move(18, 3);
			prints("     £·£·£·     ");
			move(3, 0);
			sprintf(genbuf,"£·£·£· !!! µÃ½±½ð %d ÒøÁ½", money * seven);
			prints(genbuf);
			inmoney(money * seven);
			gamelog(genbuf);
			pressanykey();
			return 0;
		}
		if ((guest_card[0] == 40 && guest_card[1] == 0) || (guest_card[0] == 0 && guest_card[1] == 40)) {
			move(18, 3);
			prints(" ³¬¼¶Õýͳ BLACK JACK  ");
			move(3, 0);
			sprintf(genbuf,"³¬¼¶Õýͳ BLACK JACK !!! µÃ½±½ð %d ÒøÁ½", money * super_jack);
			prints(genbuf);
			inmoney(money * super_jack);
			gamelog(genbuf);
			pressanykey();
			return 0;
		}
		if ((guest_card[0] <= 3 && guest_card[0] >= 0) && (guest_card[1] <= 43 && guest_card[1] >= 40))
			tmp = 1;

		if ((tmp == 1) || ((guest_card[1] <= 3 && guest_card[1] >= 0) && (guest_card[0] <= 43 && guest_card[0] >= 40))) {
			move(18, 3);
			prints(" SUPER BLACK JACK  ");
			move(3, 0);
			sprintf(genbuf,"SUPER BLACK JACK !!! µÃ½±½ð %d ÒøÁ½", money * aj);
			prints(genbuf);
			inmoney(money * aj);
			gamelog(genbuf);
			pressanykey();
			return 0;
		}
		if (guest_point == 21 && guest_count == 1) {
			move(18, 3);
			prints("  BLACK JACK  ");
			move(3, 0);
			sprintf(genbuf,"BLACK JACK !!! µÃ½±½ð %d ÒøÁ½", money * win_jack);
			prints(genbuf);
			inmoney(money * win_jack);
			gamelog(genbuf);
			pressanykey();
			return 0;
		}		/* Ç°Á½ÕÅ¾Í 21 µã */
		if (guest_point > 21) {
			if (A_count > 0) {
				guest_point -= 10;
				A_count--;
			};
		}
		move(19, 0);
		//clrtoeol();
		prints("µãÊý: %d", host_point);
		move(20, 0);
		//clrtoeol();
		prints("µãÊý: %d", guest_point);
		if (guest_point > 21) {
			move(20, 0);
			//clrtoeol();
			prints("  ±¬µôÀ²~~~  ");
			pressanykey();
			return 0;
		}
		if (guest_count == 5) {
			move(18, 3);
			prints("            ¹ýÁù¹Ø            ");
			move(3, 0);
			sprintf(genbuf,"¹ýÁù¹Ø !!! µÃ½±½ð %d ÒøÁ½", money * six);
			prints(genbuf);
			inmoney(money * six);
			gamelog(genbuf);
			pressanykey();
			return 0;
		}
		guest_count++;
		card_count++;
		mov_y += 4;

		do {
			if (ch == 'd')
				m = 0;
			if (m != 0)
				ch = egetch();
		} while (ch != 'y' && ch != 'Y' && ch != 'n' && ch != 'N' 
                      && ch != 'd' && ch != 'D' && ch != 'q' && ch != 'Q'
                      && m != 0 );	/* ×¥ key */

		if (ch == 'd' && m != 0 && guest_count == 2) {
			if (currentuser.money >= money) {
				demoney(money);
				money *= 2;
			} else
				ch = 'n';
		}		/* double */
		if (ch == 'd' && guest_count > 2)
			ch = 'n';
		if (ch == 'q' || ch == 'Q') return ;
		if (guest_point == 21)
			ch = 'n';
	} while (ch != 'n' && m != 0);

	mov_y = 8;

	print_card(host_card[0], 5, 0);
	print_card(host_card[1], 5, 4);
	host_point += num[host_card[0]];

	do {

		if (host_point < guest_point) {
			host_card[host_count] = cardlist[card_count];
			print_card(host_card[host_count], 5, mov_y);
			if (host_card[host_count] < 4)
				AA_count++;
			host_point += num[host_card[host_count]];
		}
		if (host_point > 21) {
			if (AA_count > 0) {
				host_point -= 10;
				AA_count--;
			};
		}
		move(19, 0);
		//clrtoeol();
		prints("µãÊý: %d", host_point);
		move(20, 0);
		//clrtoeol();
		prints("µãÊý: %d", guest_point);
		if (host_point > 21) {
			move(20, 0);
			//clrtoeol();
			prints("µãÊý: %d  WINNER ", guest_point);

			move(3, 0);
			sprintf(genbuf,"Ó®ÁË~~~~ µÃ½±½ð %d ÒøÁ½", money * win);
			prints(genbuf);
			gamelog(genbuf);
			inmoney(money * win);
			pressanykey();
			return 0;
		}
		host_count++;
		card_count++;
		mov_y += 4;
	} while (host_point < guest_point);

	sprintf(genbuf,"ÊäÁË~~~~ ûÊÕ %d ÒøÁ½!", money);
	prints(genbuf);
	gamelog(genbuf);
        pressanykey();
	return 0;
}
Пример #20
0
/**
 * \brief Removes some money from the player.
 *
 * If the money reaches zero, no more money is removed.
 *
 * \param money_to_remove Amount of money to remove.
 * Must be positive of zero.
 */
void Equipment::remove_money(int money_to_remove) {

  Debug::check_assertion(money_to_remove >= 0, "Invalid money amount to remove");

  set_money(get_money() - money_to_remove);
}
Пример #21
0
void get_food(region * r)
{
    plane *pl = rplane(r);
    unit *u;
    int peasantfood = rpeasants(r) * 10;
    static int food_rules = -1;
    static int gamecookie = -1;

    if (food_rules < 0 || gamecookie != global.cookie) {
        gamecookie = global.cookie;
        food_rules = get_param_int(global.parameters, "rules.economy.food", 0);
    }

    if (food_rules & FOOD_IS_FREE) {
        return;
    }
    /* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber
    * wird zunächst so auf die Einheiten aufgeteilt, dass idealerweise
    * jede Einheit genug Silber für ihren Unterhalt hat. */

    for (u = r->units; u; u = u->next) {
        int need = lifestyle(u);

        /* Erstmal zurücksetzen */
        freset(u, UFL_HUNGER);

        if (u->ship && (u->ship->flags & SF_FISHING)) {
            unit *v;
            int c = 2;
            for (v = u; c > 0 && v; v = v->next) {
                if (v->ship == u->ship) {
                    int get = 0;
                    if (v->number <= c) {
                        get = lifestyle(v);
                    }
                    else {
                        get = lifestyle(v) * c / v->number;
                    }
                    if (get) {
                        change_money(v, get);
                    }
                }
                c -= v->number;
            }
            u->ship->flags -= SF_FISHING;
        }

        if (food_rules & FOOD_FROM_PEASANTS) {
            struct faction *owner = region_get_owner(r);
            /* if the region is owned, and the owner is nice, then we'll get
            * food from the peasants - should not be used with WORK */
            if (owner != NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) {
                int rm = rmoney(r);
                int use = _min(rm, need);
                rsetmoney(r, rm - use);
                need -= use;
            }
        }

        need -= get_money(u);
        if (need > 0) {
            unit *v;

            for (v = r->units; need && v; v = v->next) {
                if (v->faction == u->faction && help_money(v)) {
                    int give = get_money(v) - lifestyle(v);
                    give = _min(need, give);
                    if (give > 0) {
                        change_money(v, -give);
                        change_money(u, give);
                        need -= give;
                    }
                }
            }
        }
    }

    /* 2. Versorgung durch Fremde. Das Silber alliierter Einheiten wird
    * entsprechend verteilt. */
    for (u = r->units; u; u = u->next) {
        int need = lifestyle(u);
        faction *f = u->faction;

        need -= _max(0, get_money(u));

        if (need > 0) {
            unit *v;

            if (food_rules & FOOD_FROM_OWNER) {
                /* the owner of the region is the first faction to help out when you're hungry */
                faction *owner = region_get_owner(r);
                if (owner && owner != u->faction) {
                    for (v = r->units; v; v = v->next) {
                        if (v->faction == owner && alliedunit(v, f, HELP_MONEY)
                            && help_money(v)) {
                            help_feed(v, u, &need);
                            break;
                        }
                    }
                }
            }
            for (v = r->units; need && v; v = v->next) {
                if (v->faction != f && alliedunit(v, f, HELP_MONEY)
                    && help_money(v)) {
                    help_feed(v, u, &need);
                }
            }

            /* Die Einheit hat nicht genug Geld zusammengekratzt und
            * nimmt Schaden: */
            if (need > 0) {
                int lspp = lifestyle(u) / u->number;
                if (lspp > 0) {
                    int number = (need + lspp - 1) / lspp;
                    if (hunger(number, u))
                        fset(u, UFL_HUNGER);
                }
            }
        }
    }

    /* 3. bestimmen, wie viele Bauern gefressen werden.
    * bei fehlenden Bauern den Dämon hungern lassen
    */
    for (u = r->units; u; u = u->next) {
        if (u_race(u) == get_race(RC_DAEMON)) {
            int hungry = u->number;

            /* use peasantblood before eating the peasants themselves */
            const struct potion_type *pt_blood = 0;
            const resource_type *rt_blood = rt_find("peasantblood");
            if (rt_blood) {
                pt_blood = rt_blood->ptype;
            }
            if (pt_blood) {
                /* always start with the unit itself, then the first known unit that may have some blood */
                unit *donor = u;
                while (donor != NULL && hungry > 0) {
                    int blut = get_effect(donor, pt_blood);
                    blut = _min(blut, hungry);
                    if (blut) {
                        change_effect(donor, pt_blood, -blut);
                        hungry -= blut;
                    }
                    if (donor == u)
                        donor = r->units;
                    while (donor != NULL) {
                        if (u_race(donor) == get_race(RC_DAEMON) && donor != u) {
                            if (get_effect(donor, pt_blood)) {
                                /* if he's in our faction, drain him: */
                                if (donor->faction == u->faction)
                                    break;
                            }
                        }
                        donor = donor->next;
                    }
                }
            }
            /* remaining demons feed on peasants */
            if (pl == NULL || !fval(pl, PFL_NOFEED)) {
                if (peasantfood >= hungry) {
                    peasantfood -= hungry;
                    hungry = 0;
                }
                else {
                    hungry -= peasantfood;
                    peasantfood = 0;
                }
                if (hungry > 0) {
                    static int demon_hunger = -1;
                    if (demon_hunger < 0) {
                        demon_hunger = get_param_int(global.parameters, "hunger.demons", 0);
                    }
                    if (demon_hunger == 0) {
                        /* demons who don't feed are hungry */
                        if (hunger(hungry, u))
                            fset(u, UFL_HUNGER);
                    }
                    else {
                        /* no damage, but set the hungry-flag */
                        fset(u, UFL_HUNGER);
                    }
                }
            }
        }
    }
    rsetpeasants(r, peasantfood / 10);

    /* 3. Von den überlebenden das Geld abziehen: */
    for (u = r->units; u; u = u->next) {
        int need = _min(get_money(u), lifestyle(u));
        change_money(u, -need);
    }
}