Esempio n. 1
0
char *mkalphanum(int len) {
 //returns an alphanumeric string of len length
  int size = len + 1;
  char *s = malloc(sizeof(char) * size);
  char c;
  s[size] = 0;
  for (int i = 0; i < size;i++) {
    int typeflag = randint(1);
    if (typeflag == 0)
       s[i] = randalpha();
    else
       s[i] = randint(9) + '0';
  }
  s[size] = '\0';
  return s;
}
Esempio n. 2
0
bool MineParticleSmoke::idle(const Uint64 delta_t)
{
    if (state == 0) {
        const Uint64 age = get_time() - born;
        const float age_f = (float)(age)/1000000.0f;
        alpha = age_f * 0.125;
        if (age_f > 0.25) {
            state = 1;
            alpha = randalpha(0.375);
        }
        return true;
    }
    const interval_t float_time = delta_t / 1000000.0;
    const alpha_t scalar = std::pow(randfloat(), float_time);
    alpha *= std::sqrt(scalar);
    if (alpha < 0.01)
        return false;
    return true;
}
Esempio n. 3
0
	bool SwordEffect::idle(const Uint64 usec)
	{
		if ((recall) && (particles.size() == 0))
			return false;

		if (recall)
			return true;

		const Vec3 pos_change = old_end - *end;
		float speed= square(pos_change.magnitude() * 1000000.0 / usec) * 0.666667;
		float bias = 0.5f;
		switch (type)
		{
			case SERPENT:
			case CUTLASS:
			case EMERALD_CLAYMORE:
			case SUNBREAKER:
			case ORC_SLAYER:
			case EAGLE_WING:
			case JAGGED_SABER:
			{
				bias = randfloat(0.33);
				if (speed > 2.0)
					speed = 2.0f;
				else if (speed < 0.05)
					speed = 0.05;
			}
			case SWORD_OF_FIRE:
			case SWORD_OF_ICE:
			case SWORD_OF_MAGIC:
			{
				if (speed > 3.0f)
					speed = 3.0f;
				else if (speed < 0.25f)
					speed = 0.25f;
			}
		}

		while (pow_randfloat((float)usec * 0.000083f * speed) < bias)
		{
			const percent_t percent= square(randpercent());
			Vec3 randcoords;
			randcoords.randomize(0.0025);
			const Vec3 coords = (*start * percent) + (*end * (1.0 - percent))
				+ randcoords;
			Vec3 velocity;
			velocity.randomize(0.005);
			Vec3 direction = *end - *start;
			direction.normalize(0.05 + randfloat(0.25) * randfloat(0.25));
			velocity += direction;
			Particle* p = new SwordParticle(this, mover, coords, velocity, size - 0.25 + randfloat(0.25), 0.25 + randalpha(percent), color[0], color[1], color[2], texture, LOD);
			if (!base->push_back_particle(p))
				break;
			if (randfloat(2.0f) < 0.1f) {
				p = new SwordParticle(this, mover, coords, velocity, 1.5, 1.0, 2.0, 2.0, 2.0, EC_TWINFLARE, LOD);
				base->push_back_particle(p);
			}
		}

		old_end = *end;

		return true;
	}
Esempio n. 4
0
	HarvestingEffect::HarvestingEffect(EyeCandy* _base, bool* _dead,
		Vec3* _pos, const HarvestingType _type, const Uint16 _LOD)
	{
		if (EC_DEBUG)
			std::cout << "HarvestingEffect (" << this << ") created (" << type
				<< ")." << std::endl;
		base = _base;
		dead = _dead;
		pos = _pos;
		effect_center = *pos;
		type = _type;
		LOD = base->last_forced_LOD;
		desired_LOD = _LOD;
		spawner = NULL;
		bounds = NULL;
		mover = NULL;
		spawner2 = NULL;
		mover2 = NULL;
		direction = Vec3(0.0, 0.0, 0.0);

		switch (type)
		{
			case TOOL_BREAK:
			{
				// handled in other constructor
				break;
			}
			case RADON_POUCH:
			{
				effect_center.y += 0.5;
				spawner = new FilledSphereSpawner(0.9);
				mover = new GravityMover(this, &effect_center, 8e9);
				while ((int)particles.size() < LOD * 50)
				{
					const Vec3 coords = spawner->get_new_coords()
						+ effect_center;
					Vec3 velocity;
					velocity.randomize();
					velocity.normalize(0.8);
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 5.25, 0.5, 0.6, 0.7, 0.2, EC_FLARE, LOD, type);
					p->state = 0;
					if (!base->push_back_particle(p))
						break;
				}
				while ((int)particles.size() < LOD * 100)
				{
					const Vec3 coords = spawner->get_new_coords()
						+ effect_center;
					Vec3 velocity;
					velocity.randomize();
					velocity.normalize(1.5);
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 4.5, 0.5 + randalpha(0.4), 0.7, 0.6, 0.5, EC_WATER, LOD, type);
					p->state = 1;
					if (!base->push_back_particle(p))
						break;
				}
				break;
			}
			case CAVERN_WALL:
			{
				effect_center.y += 15.0;
				spawner = new FilledSphereSpawner(1.0);
				mover = new ParticleMover(this);
				while ((int)particles.size() < LOD * 50)
				{
					Vec3 coords = spawner->get_new_coords();
					coords.y *= 8.0;
					Vec3 velocity;
					velocity.randomize();
					velocity.normalize(0.2);
					velocity.y *= 3.0;
					velocity.y -= 9.0;
					coords += effect_center;
					const color_t scalar= randcolor(0.4);
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 8.0 + randcoord(12.0), 1.0, scalar + randcolor(0.1), scalar + randcolor(0.1), scalar + randcolor(0.1), EC_SIMPLE, LOD, type);
					if (!base->push_back_particle(p))
						break;
				}
				while ((int)particles.size() < LOD * 100)
				{
					Vec3 coords = spawner->get_new_coords();
					coords.y *= 8.0;
					Vec3 velocity;
					velocity.randomize();
					velocity.normalize(0.2);
					velocity.y *= 3.0;
					velocity.y -= 9.0;
					coords += effect_center;
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 3.0 + randcoord(6.0), 0.4 + randalpha(0.4), 0.2 + randcolor(0.2), 0.2 + randcolor(0.2), 0.2 + randcolor(0.2), EC_WATER, LOD, type);
					if (!base->push_back_particle(p))
						break;
				}
				break;
			}
			case MOTHER_NATURE:
			{
				effect_center.y += 0.2;
				spawner = new HollowDiscSpawner(0.1);
				mover = new SpiralMover(this, &effect_center, 18.0, 11.0);
				while ((int)particles.size() < LOD * 100)
				{
					const Vec3 coords = spawner->get_new_coords()
						+ effect_center;
					Vec3 velocity;
					velocity.randomize(0.3);
					velocity.y *= 3;
					velocity.y += 1.4;
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 3.0, 0.2, 1.0, 0.5 + randcolor(0.5), 0.5, EC_TWINFLARE, LOD, type);
					if (!base->push_back_particle(p))
						break;
				}
				break;
			}
			case QUEEN_OF_NATURE:
			{
				effect_center.y += 0.2;
				spawner = new FilledDiscSpawner(0.5);
				mover = new ParticleMover(this);
				while ((int)particles.size() < LOD * 100)
				{
					Vec3 coords = spawner->get_new_coords() + effect_center;
					coords.y += (coord_t)(randfloat(2.0) * randfloat(2.0) * randfloat(2.0));
					const Vec3 velocity(0.0, 0.0, 0.0);
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 2.0 + randcoord(1.0), 1.0, randcolor(1.0), randcolor(1.0), randcolor(1.0), EC_SHIMMER, LOD, type);
					if (!base->push_back_particle(p))
						break;
				}
				break;
			}
			case BEES:
			{
				spawner = new FilledSphereSpawner(0.75);
				mover = new GravityMover(this, &effect_center, 8e9);
				direction.randomize();
				direction.y = 0;
				while ((int)particles.size() < LOD * 4)
				{
					const Vec3 coords = spawner->get_new_coords()
						+ effect_center - direction;
					Vec3 velocity;
					velocity.randomize();
					velocity.normalize(0.75);
					velocity.x += randfloat(direction.x);
					velocity.z += randfloat(direction.z);
					Particle * p = new HarvestingParticle(this, mover, coords, velocity, 0.5 + randfloat(0.25), 1.0, 0.9, 0.7, 0.3, EC_TWINFLARE, LOD, type);
					if (!base->push_back_particle(p))
						break;
				}
				break;
			}
			case BAG_OF_GOLD:
			{
				mover = new GravityMover(this, &effect_center, 2e10);
				spawner = new HollowSphereSpawner(0.3);

				for (int i = 0; i < LOD * 60; i++)
				{
					Vec3 coords = spawner->get_new_coords();
					const Vec3 velocity = coords / 10.0;
					coords += effect_center;
					Particle* p = new HarvestingParticle(this, mover, coords, velocity, 1.05, 0.75, randcolor(0.3) + 0.7, randcolor(0.3) + 0.5, randcolor(0.3) + 0.3, EC_FLARE, LOD, type);
					p->state = 1;
					if (!base->push_back_particle(p))
						break;
				}

				Particle* p = new HarvestingParticle(this, mover, effect_center, Vec3(0.0, 0.0, 0.0), 8.0, 1.0, 0.8, 0.7, 0.3, EC_SHIMMER, LOD, type);
				base->push_back_particle(p);
				break;
			}
			case RARE_STONE:
			{
				mover = new ParticleMover(this);
				spawner = new HollowSphereSpawner(0.3);

				for (int i = 0; i < LOD * 60; i++)
				{
					Vec3 coords = spawner->get_new_coords();
					const Vec3 velocity = coords / 10.0;
					coords += effect_center;
					Particle* p = new HarvestingParticle(this, mover, coords, velocity, 0.75, 0.05, randcolor(0.3) + 0.7, randcolor(0.3) + 0.5, randcolor(0.3) + 0.3, EC_FLARE, LOD, type);
					p->state = 1;
					if (!base->push_back_particle(p))
						break;
				}

				Particle* p = new HarvestingParticle(this, mover, effect_center, Vec3(0.0, 0.0, 0.0), 7.5, 1.0, 1.0, 1.0, 1.0, EC_VOID, LOD, type);
				if (!base->push_back_particle(p))
					break;
				p = new HarvestingParticle(this, mover, effect_center, Vec3(0.0, 0.01, 0.0), 7.5, 1.0, 1.0, 1.0, 1.0, EC_VOID, LOD, type);
				base->push_back_particle(p);
				break;
			}
		}
	}