void update(float percent, float offset)
{
	int n = (int) (position_counter * percent / 100);
	for (int j = 0; j < n; j++) {
		int i = (int) random_range(0, position_counter - 1);
		float x = position_matrix[i].x + random_range(- offset, offset);
		float y = position_matrix[i].y + random_range(- offset, offset);
		position_matrix[i].x = (x <= 0) ? 0 : (x <= 1) ? x : 1;
		position_matrix[i].y = (y <= 0) ? 0 : (y <= 1) ? y : 1;
	}
}
Beispiel #2
0
void straggle_corridor(int fx, int fy, int tx, int ty, Symbol loc, char rsi)
{
  int dx,dy;
  while ((fx != tx) || (fy != ty)) {
    dx = tx - fx;
    dy = ty - fy;
    if (random_range(abs(dx)+abs(dy)) < abs(dx))
      corridor_crawl(&fx,&fy,sign(dx),0,random_range(abs(dx))+1,loc,rsi);
    else corridor_crawl(&fx,&fy,0,sign(dy),random_range(abs(dy))+1,loc,rsi);
  }
}
Beispiel #3
0
int32_t WeaponMelee::getElementDamage(const Player* player, const Item* item) const
{
	int32_t attackSkill = player->getWeaponSkill(item);
	int32_t attackValue = std::max<int32_t>(0, elementDamage);
	float attackFactor = player->getAttackFactor();

	int32_t maxValue = Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, attackFactor);
	if(random_range(1, 100) <= g_config.getNumber(ConfigManager::CRITICAL_HIT_CHANCE))
		maxValue <<= 1;

	maxValue = int32_t(maxValue * player->getVocation()->meleeDamageMultipler);
	return -random_range(0, maxValue, DISTRO_NORMAL);
}
Beispiel #4
0
void i_chaos(pob o)
{
  if (Player.alignment < 0) {
    Player.alignment -= random_range(20);
    mprint("You feel deliciously chaotic!");
    gain_experience(abs(Player.alignment)*10);
  }
  else {
    mprint("You feel a sense of inner turmoil!");
  }
  /* Potion of Chaos always makes player more chaotic. PGM */
  Player.alignment -= random_range(20);
}
Beispiel #5
0
int itemblessing(void)
{
    switch(random_range(10)) {
    case 0:
    case 1:
        return(-1-random_range(10));
    case 8:
    case 9:
        return(1+random_range(10));
    default:
        return(0);
    }
}
Beispiel #6
0
void i_law(pob o)
{
  if (Player.alignment > 0) {
    Player.alignment += random_range(20);
    mprint("You feel wonderfully lawful!");
    gain_experience(Player.alignment*10);
  }
  else {
    mprint("You feel a sense of inner constraint!");
  }
  /* Potion of Law always makes player more lawful. PGM */
  Player.alignment += random_range(20);
}
Beispiel #7
0
bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/)
{
	int32_t nHealth = mType->health,nMaxHealth = mType->healthMax, nExp = mType->experience, nDef = mType->defense, nArm = mType->armor;
		int32_t monsterLevel = random_range(mType->minLevel, mType->maxLevel);
	if (monsterLevel != 0)
	{
    monsterLevel = monsterLevel;
} else {
    monsterLevel = random_range(5,15);
}
	mType->health = (uint64_t)std::ceil(mType->health * monsterLevel / 8);
	mType->healthMax = (uint64_t)std::ceil(mType->healthMax * monsterLevel / 8);
	mType->experience = (uint64_t)std::ceil(mType->experience * monsterLevel / 8);
	mType->defense = (uint64_t)std::ceil(mType->defense * monsterLevel / 8);
	mType->armor = (uint64_t)std::ceil(mType->armor * monsterLevel / 8);
    Monster* monster = Monster::createMonster(mType);
    monster->doMonsterSetCombatValues(monsterLevel);
    monster->doMonsterSetLevel(monsterLevel);
 
mType->health = nHealth;
mType->healthMax = nMaxHealth;
mType->experience = nExp;
mType->defense = nDef;
mType->armor = nArm;
	if(!monster)
		return false;

	if(startup)
	{
		//No need to send out events to the surrounding since there is no one out there to listen!
		if(!g_game.internalPlaceCreature(monster, pos, false, true))
		{
			delete monster;
			return false;
		}
	}
	else if(!g_game.placeCreature(monster, pos, false, true))
	{
		delete monster;
		return false;
	}

	monster->setSpawn(this);
	monster->setMasterPosition(pos, radius);
	monster->setDirection(dir);

	monster->addRef();
	spawnedMap.insert(SpawnedPair(spawnId, monster));
	spawnMap[spawnId].lastSpawn = OTSYS_TIME();
	return true;
}
Beispiel #8
0
Vector vector_random_direction(void)
{
    float x, y, z;

    do
    {
        x = random_range(-1, 1);
        y = random_range(-1, 1);
        z = random_range(-1, 1);
    }
    while (x*x + y*y + z*z > 1);

    return vector_normalize(vector(x, y, z));
}
Beispiel #9
0
void make_weapon(Object* newObject, int id)
{
    if (id == -1) id = random_range(NUMWEAPONS);
    *newObject = Objects[WEAPONID+id];
    if ((id == 28) || (id == 29)) /* bolt or arrow */
        newObject->number = random_range(20)+1;
    if (newObject->blessing == 0) newObject->blessing = itemblessing();
    if (newObject->plus == 0) {
        newObject->plus = itemplus();
        if (newObject->blessing < 0)
            newObject->plus = -1 - abs(newObject->plus);
        else if (newObject->blessing > 0)
            newObject->plus = 1 + abs(newObject->plus);
    }
}
Beispiel #10
0
bool ConditionDamage::init()
{
	if(periodDamage != 0){
		return true;
	}

	if(damageList.empty()){
		setTicks(0);

		int32_t amount = random_range(minDamage, maxDamage);

		if(amount != 0){
			if(startDamage > maxDamage){
				startDamage = maxDamage;
			}
			else if(startDamage == 0){
				startDamage = std::max((int32_t)1, (int32_t)std::ceil(((float)amount / 20.0)));
			}

			std::list<int32_t> list;
			ConditionDamage::generateDamageList(amount, startDamage, list);

			for(std::list<int32_t>::iterator it = list.begin(); it != list.end(); ++it){
				addDamage(1, tickInterval, -*it);
			}
		}
	}

	return (!damageList.empty());
}
Beispiel #11
0
void ConditionSpeed::addCondition(Creature* creature, const Condition* addCondition)
{
	if(updateCondition(addCondition)){
		setTicks( addCondition->getTicks() );

		const ConditionSpeed& conditionSpeed = static_cast<const ConditionSpeed&>(*addCondition);
		int32_t oldSpeedDelta = speedDelta;
		speedDelta = conditionSpeed.speedDelta;
		mina = conditionSpeed.mina;
		maxa = conditionSpeed.maxa;
		minb = conditionSpeed.minb;
		maxb = conditionSpeed.maxb;

		if(speedDelta == 0){
			int32_t min;
			int32_t max;
			getFormulaValues(creature->getBaseSpeed(), min, max);
			speedDelta = random_range(min, max);
		}

		int32_t newSpeedChange = (speedDelta - oldSpeedDelta);
		if(newSpeedChange != 0){
			g_game.changeSpeed(creature, newSpeedChange);
		}
	}
}
Beispiel #12
0
/* search once particular spot */
void searchat(int x, int y)
{
    int i;
    if (inbounds(x,y) && (random_range(3) || Player.status[ALERT])) {
        if (loc_statusp(x,y,SECRET)) {
            lreset(x,y,SECRET);
            lset(x, y, CHANGED);
            if ((Level->site[x][y].locchar==OPEN_DOOR) ||
                    (Level->site[x][y].locchar==CLOSED_DOOR)) {
                mprint("You find a secret door!");
                for(i=0; i<=8; i++) { /* FIXED! 12/25/98 */
                    lset(x+Dirs[0][i],y+Dirs[1][i],STOPS);
                    lset(x+Dirs[0][i], y+Dirs[1][i], CHANGED);
                }
            }
            else mprint("You find a secret passage!");
            drawvision(Player.x,Player.y);
        }
        if ((Level->site[x][y].p_locf >= TRAP_BASE) &&
                (Level->site[x][y].locchar != TRAP) &&
                (Level->site[x][y].p_locf <= TRAP_BASE+NUMTRAPS)) {
            Level->site[x][y].locchar = TRAP;
            lset(x, y, CHANGED);
            mprint("You find a trap!");
            drawvision(Player.x,Player.y);
            State.setFastMove(false);
        }
    }
}
Beispiel #13
0
/* Increase in level at appropriate experience gain */
void gain_level(void)
{
  int gained=FALSE;
  int hp_gain; /* FIXED! 12/30/98 */
  
  if (gamestatusp(SUPPRESS_PRINTING))
    return;
  while (expval(Player.level+1) <= Player.xp) {
    if (!gained)
      morewait();
    gained = TRUE;
    Player.level++;
    print1("You have attained a new experience level!");
    print2("You are now ");
    nprint2(getarticle(levelname(Player.level)));
    nprint2(levelname(Player.level));
    hp_gain = random_range(Player.con)+1; /* start fix 12/30/98 */
    if (Player.hp < Player.maxhp )
      Player.hp += hp_gain*Player.hp/Player.maxhp;
    else if (Player.hp < Player.maxhp + hp_gain)
      Player.hp = Player.maxhp + hp_gain;
    /* else leave current hp alone */
    Player.maxhp += hp_gain;
    Player.maxmana = calcmana();
    /* If the character was given a bonus, let him keep it.  Otherwise
     * recharge him. */
    Player.mana = max(Player.mana, Player.maxmana); /* end fix 12/30/98 */
    morewait();
  }
  if (gained) clearmsg();
  calc_melee();
}
Beispiel #14
0
bool ConditionDamage::init()
{
	if(periodDamage)
		return true;

	if(!damageList.empty())
		return true;

	setTicks(0);
	int32_t amount = random_range(minDamage, maxDamage);
	if(!amount)
		return false;

	if(startDamage > maxDamage)
		startDamage = maxDamage;
	else if(!startDamage)
		startDamage = std::max((int32_t)1, (int32_t)std::ceil(((float)amount / 20.0)));

	std::list<int32_t> list;
	ConditionDamage::generateDamageList(amount, startDamage, list);
	for(std::list<int32_t>::iterator it = list.begin(); it != list.end(); ++it)
		addDamage(1, tickInterval, -(*it));

	return !damageList.empty();
}
Beispiel #15
0
const char* object_generator::get_value(unsigned long long key_index, unsigned int *len) {
    // compute size
    unsigned int new_size = 0;
    if (m_data_size_type == data_size_fixed) {
        new_size = m_data_size.size_fixed;
    } else if (m_data_size_type == data_size_range) {
        if (m_data_size_pattern && *m_data_size_pattern=='S') {
            double a = (key_index-m_key_min)/static_cast<double>(m_key_max-m_key_min);
            new_size = (m_data_size.size_range.size_max-m_data_size.size_range.size_min)*a + m_data_size.size_range.size_min;
        } else {
            new_size = random_range(m_data_size.size_range.size_min > 0 ? m_data_size.size_range.size_min : 1,
                                    m_data_size.size_range.size_max);
        }
    } else if (m_data_size_type == data_size_weighted) {
        new_size = m_data_size.size_list->get_next_size();
    } else {
        assert(0);
    }

    // modify object content in case of random data
    if (m_random_data) {
        m_value_buffer[m_value_buffer_mutation_pos++]++;
        if (m_value_buffer_mutation_pos >= m_value_buffer_size)
            m_value_buffer_mutation_pos = 0;
    }

    *len = new_size;
    return m_value_buffer;
}
Beispiel #16
0
void Actor::onThinkTarget(uint32_t interval)
{
  if(!isSummon()){
    if(cType.changeTargetSpeed() > 0){
      bool canChangeTarget = true;
      if(targetChangeCooldown > 0){
        targetChangeCooldown -= interval;
        if(targetChangeCooldown <= 0){
          targetChangeCooldown = 0;
          targetChangeTicks = (uint32_t)cType.changeTargetSpeed();
        }
        else{
          canChangeTarget = false;
        }
      }

      if(canChangeTarget){
        targetChangeTicks += interval;

        if(targetChangeTicks >= (uint32_t)cType.changeTargetSpeed()){
          targetChangeTicks = 0;
          targetChangeCooldown = (uint32_t)cType.changeTargetSpeed();

          if(cType.changeTargetChance() >= random_range(1, 100)){
            searchTarget(TARGETSEARCH_RANDOM);
          }
        }
      }
    }
  }
}
Beispiel #17
0
void objdet(int blessing)
{
    int i,j;
    for (i=0; i<Level->level_width; i++)
        for (j=0; j<Level->level_length; j++)
            if (Level->site[i][j].things != NULL) {
                if (blessing < 0)
                    putspot(random_range(Level->level_width),
                            random_range(Level->level_length),
                            Level->site[i][j].things->thing->objchar);
                else putspot(i,j,Level->site[i][j].things->thing->objchar);
            }
    levelrefresh();
    morewait();
    show_screen();
}
Beispiel #18
0
int32_t WeaponWand::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const
{
	if(maxDamage)
		return -maxChange;

	return random_range(-minChange, -maxChange, DISTRO_NORMAL);
}
Beispiel #19
0
void i_azoth(pob o)
{
    if (o->plus < 0) {
        mprint("The mercury was poisonous!");
        p_poison(25);
    }
    else if (o->plus == 0) {
        mprint("The partially enchanted azoth makes you sick!");
        Player.con = ((int) (Player.con / 2));
        calc_melee();
    }
    else if (o->blessing < 1) {
        mprint("The unblessed azoth warps your soul!");
        Player.pow = Player.maxpow = ((int) (Player.maxpow / 2));
        level_drain(random_range(10),"cursed azoth");
    }
    else {
        mprint("The azoth fills you with cosmic power!");
        if (Player.str > Player.maxstr*2) {
            mprint("The power rages out of control!");
            p_death("overdose of azoth");
        }
        else {
            heal(10);
            cleanse(1);
            Player.mana = calcmana()*3;
            toggle_item_use(TRUE);
            Player.str = (Player.maxstr++)*3;
            toggle_item_use(FALSE);
        }
    }
}
Beispiel #20
0
void Monster::onThinkTarget(uint32_t interval)
{
	if(isSummon() || mType->changeTargetSpeed <= 0)
		return;

	bool canChangeTarget = true;
	if(targetChangeCooldown > 0)
	{
		targetChangeCooldown -= interval;
		if(targetChangeCooldown <= 0)
		{
			targetChangeCooldown = 0;
			targetChangeTicks = (uint32_t)mType->changeTargetSpeed;
		}
		else
			canChangeTarget = false;
	}

	if(!canChangeTarget)
		return;

	targetChangeTicks += interval;
	if(targetChangeTicks < (uint32_t)mType->changeTargetSpeed)
		return;

	targetChangeTicks = 0;
	targetChangeCooldown = (uint32_t)mType->changeTargetSpeed;
	if(mType->changeTargetChance < random_range(1, 100))
		return;

	if(mType->targetDistance <= 1)
		searchTarget(TARGETSEARCH_RANDOM);
	else
		searchTarget(TARGETSEARCH_NEAREST);
}
Beispiel #21
0
void Raids::checkRaids()
{
	if(!getRunning()){
		uint64_t now = OTSYS_TIME();
		for(RaidList::iterator it = raidList.begin(); it != raidList.end(); ++it){
			if(now >= (getLastRaidEnd() + (*it)->getMargin())){
				if(MAX_RAND_RANGE*CHECK_RAIDS_INTERVAL/(*it)->getInterval() >= (uint32_t)random_range(0, MAX_RAND_RANGE)){
#ifdef __DEBUG_RAID__
					char buffer[32];
					time_t tmp = time(NULL);
					formatDate(tmp, buffer);
					std::cout << buffer << " [Notice] Raids: Starting raid " << (*it)->getName() << std::endl;
#endif
					setRunning(*it);
					(*it)->startRaid();
					break;
				}
			}

		}
	}

	 checkRaidsEvent = Scheduler::getScheduler().addEvent(createSchedulerTask(CHECK_RAIDS_INTERVAL*1000, 
	     boost::bind(&Raids::checkRaids, this)));
}
Beispiel #22
0
int SpawnStations(int num_stations) {
    /* spawns random stations */
    int status, attempts;
    int sensor;

    status = 0;
    attempts = 0;
    seed(Time());
    while (num_stations > 0 && attempts < 5) {
        sensor = random_range(0, SENSOR_COUNT - 1);
        status = AddTrainStation(sensor, -1);
        switch (status) {
            case TRANSACTION_INCOMPLETE:
            case TASK_DOES_NOT_EXIST:
            case TOO_MANY_STATIONS:
                attempts++;
                return status;
            case TRAIN_STATION_INVALID:
                attempts++;
                break;
            default:
                attempts = 0;
                num_stations--;
                printf("Created station at sensor %s with %d passengers\r\n",
                       (DispatchGetTrackNode(sensor))->name, status);
        }
    }
    return 1;
}
void Creature::onWalk(Direction& dir)
{
	if (hasCondition(CONDITION_DRUNK)) {
		uint32_t r = random_range(0, 20);

		if (r <= 4) {
			switch (r) {
				case 0:
					dir = NORTH;
					break;
				case 1:
					dir = WEST;
					break;
				case 3:
					dir = SOUTH;
					break;
				case 4:
					dir = EAST;
					break;

				default:
					break;
			}

			g_game.internalCreatureSay(this, SPEAK_MONSTER_SAY, "Hicks!", false);
		}
	}
}
Beispiel #24
0
/* Drop a packet from the longest queue in 'rl'. */
static void
drop_packet(struct rate_limiter *rl)
{
    struct ofp_queue *longest;  /* Queue currently selected as longest. */
    int n_longest;              /* # of queues of same length as 'longest'. */
    struct ofp_queue *q;

    longest = &rl->queues[0];
    n_longest = 1;
    for (q = &rl->queues[0]; q < &rl->queues[OFPP_MAX]; q++) {
        if (longest->n < q->n) {
            longest = q;
            n_longest = 1;
        } else if (longest->n == q->n) {
            n_longest++;

            /* Randomly select one of the longest queues, with a uniform
             * distribution (Knuth algorithm 3.4.2R). */
            if (!random_range(n_longest)) {
                longest = q;
            }
        }
    }

    /* FIXME: do we want to pop the tail instead? */
    ofpbuf_delete(queue_pop_head(longest));
    rl->n_queued--;
}
Beispiel #25
0
void mondet(int blessing)
{
    MonsterList* ml;
    for (ml=Level->mlist; ml!=NULL; ml=ml->next)
        if (ml->monster->hp > 0) /* FIXED 12/30/98 DG */
        {
            if (blessing > -1)
                plotmon(ml->monster);
            else
                putspot(random_range(Level->level_width), random_range(Level->level_length),
                        Monsters[random_range(NUMMONSTERS)].symbol);
        }
    levelrefresh();
    morewait();
    show_screen();
}
Beispiel #26
0
int16_t Vocation::getReflect(CombatType_t combat) const
{
	if(reflect[REFLECT_CHANCE][combat] < random_range(0, 100))
		return reflect[REFLECT_PERCENT][combat];

	return 0;
}
Beispiel #27
0
/* returns index of an item to steal, ABORT if player carrying none */
int stolen_item(void)
{
    int idx;
    int nextitem;

    int cards[MAXITEMS];

    nextitem = 0;

    /* look for bank cards */
    for (idx = 0; idx < MAXITEMS; ++idx)
    {
        if (0 == Player.possessions[idx]) continue;
        if (Player.possessions[idx]->id < OB_DEBIT_CARD) continue;
        if (Player.possessions[idx]->id > OB_SMART_CARD) continue;

        cards[nextitem++] = idx;
    }

    if (0 == nextitem) return random_item();

    if (nextitem > 1)
        shuffle(cards, nextitem);

    if (random_range(100) < 75)
    {
        /* oh that sucks... */
        return cards[0];
    }

    return random_item();
}
Beispiel #28
0
void draw_squares(IplImage *img, CvScalar color, int min_cnt, int max_cnt)
{
	int i, cnt, side;
	CvPoint topLeft, bottomRight;
	
	cnt = random_range(min_cnt, max_cnt);

	for (i = 0; i < cnt; i++) {
		topLeft.x = random_range(50, IMAGE_WIDTH - 50);
		topLeft.y = random_range(50, IMAGE_HEIGHT - 50);
		side = random_range(5, 50);
		bottomRight.x = side + topLeft.x;
		bottomRight.y = side + topLeft.y;
		cvRectangle(img, topLeft, bottomRight, color, CV_FILLED, 8, 0);
	}					
}
Beispiel #29
0
void ConditionSpeed::addCondition(Creature* creature, const Condition* addCondition)
{
	if(conditionType != addCondition->getType() || (ticks == -1 && addCondition->getTicks() > 0))
		return;

	setTicks(addCondition->getTicks());
	const ConditionSpeed& conditionSpeed = static_cast<const ConditionSpeed&>(*addCondition);
	int32_t oldSpeedDelta = speedDelta;

	mina = conditionSpeed.mina;
	maxa = conditionSpeed.maxa;
	minb = conditionSpeed.minb;
	maxb = conditionSpeed.maxb;

	speedDelta = conditionSpeed.speedDelta;
	outfits = conditionSpeed.outfits;

	changeOutfit(creature);
	if(!speedDelta)
	{
		int32_t min, max;
		getFormulaValues(creature->getBaseSpeed(), min, max);
		speedDelta = random_range(min, max);
	}

	int32_t newSpeedChange = speedDelta - oldSpeedDelta;
	if(newSpeedChange)
		g_game.changeSpeed(creature, newSpeedChange);
}
Beispiel #30
0
static void
test_one(const struct test_vector *vec)
{
    uint8_t md[SHA1_DIGEST_SIZE];
    int i;

    /* All at once. */
    sha1_bytes(vec->data, vec->size, md);
    assert(!memcmp(md, vec->output, SHA1_DIGEST_SIZE));

    /* In two pieces. */
    for (i = 0; i < 20; i++) {
        int n0 = vec->size ? random_range(vec->size) : 0;
        int n1 = vec->size - n0;
        struct sha1_ctx sha1;

        sha1_init(&sha1);
        sha1_update(&sha1, vec->data, n0);
        sha1_update(&sha1, vec->data + n0, n1);
        sha1_final(&sha1, md);
        assert(!memcmp(md, vec->output, SHA1_DIGEST_SIZE));
    }

    putchar('.');
    fflush(stdout);
}