Пример #1
0
static struct starfish *
make_starfish (struct state *st, int maxx, int maxy, int size)
{
  struct starfish *s = (struct starfish *) calloc(1, sizeof(*s));
  int i;

  s->blob_p = st->blob_p;
  s->elasticity = SCALE * get_float_resource (st->dpy, "thickness", "Thickness");

  if (s->elasticity == 0)
    /* bell curve from 0-15, avg 7.5 */
    s->elasticity = RAND(5*SCALE) + RAND(5*SCALE) + RAND(5*SCALE);

  s->rotv = get_float_resource (st->dpy, "rotation", "Rotation");
  if (s->rotv == -1)
    /* bell curve from 0-12 degrees, avg 6 */
    s->rotv = frand(4) + frand(4) + frand(4);

  s->rotv /= 360;  /* convert degrees to ratio */

  if (s->blob_p)
    {
      s->elasticity *= 3;
      s->rotv *= 3;
    }

  s->rot_max = s->rotv * 2;
  s->rota = 0.0004 + frand(0.0002);


  if (! (random() % 20))
    size *= frand(0.35) + frand(0.35) + 0.3;

  {
    static const char skips[] = { 2, 2, 2, 2,
                                  3, 3, 3,
                                  6, 6,
                                  12 };
    s->skip = skips[random() % sizeof(skips)];
  }

  if (! (random() % (s->skip == 2 ? 3 : 12)))
    s->mode = zoom;
  else
    s->mode = pulse;

  maxx *= SCALE;
  maxy *= SCALE;
  size *= SCALE;

  s->max_r = size;
  s->min_r = 0;

  if (s->min_r < (5*SCALE)) s->min_r = (5*SCALE);

  s->x = maxx/2;
  s->y = maxy/2;

  s->th = frand(M_PI+M_PI) * RANDSIGN();

  {
    static const char sizes[] = { 3, 3, 3, 3, 3,
                                  4, 4, 4, 4,
                                  5, 5, 5, 5, 5, 5,
                                  8, 8, 8,
                                  10,
                                  35 };
    int nsizes = sizeof(sizes);
    if (s->skip > 3)
      nsizes -= 4;
    s->npoints = s->skip * sizes[random() % nsizes];
  }

  s->spline = make_spline (s->npoints);
  s->r = (long *) malloc (sizeof(*s->r) * s->npoints);

  for (i = 0; i < s->npoints; i++)
    s->r[i] = ((i % s->skip) == 0) ? 0 : size;

  return s;
}
Пример #2
0
int pickPositions() {

	int gals;

	VectorNew(galPos[100]);
	VectorNew(galVel[100]);
	VectorNew(shit);

	float galSize[100];
	float galMassMin[100];
	float galMassMax[100];
	float spawnRange;
	int i;
	int g;
	particle_t *p;
	particleDetail_t *pd;
	float totalMass = 0;

	float angle;
	float angle2;
	float radius;

	gals = (rand() % (1 + spawnVars.maxGalCount-spawnVars.minGalCount)) + spawnVars.minGalCount;

	if (gals <= 0) {

		conAdd(LERR, "For some reason galaxies to spawn is 0 or less. Not possible!");
		return 0;

	}

	if (gals >= 100) {

		conAdd(LERR, "Maximum galaxies to spawn is 100");
		return 0;

	}

	spawnRange = frand(spawnVars.minSpawnRange, spawnVars.maxSpawnRange);

	conAdd(LNORM, "Spawning new simulation...");
	conAdd(LLOW, "- %i particles...", state.particleCount);
	conAdd(LLOW, "- %i galaxies...", gals);

	for (g = 0; g < gals; g++) {

		galMassMin[g] = frand(spawnVars.minGalMass, spawnVars.maxGalMass);
		galMassMax[g] = frand(spawnVars.minGalMass, spawnVars.maxGalMass);
		galSize[g] = frand(spawnVars.minGalSize, spawnVars.maxGalSize);

		setRangePosition(galPos[g], spawnRange);
		setRangePosition(galVel[g], frand(0,1) * frand(0,1) * frand(spawnVars.minGalVel, spawnVars.maxGalVel));

	}

	for (i = 0; i < state.particleCount; i++) {

		if (!(i % 100)) {
			view.recordParticlesDone = i;
			doVideoUpdateInSpawn();
		}

		if (state.restartSpawning) {
			return 0;
		}
		
		p = getParticleFirstFrame(i);
		pd = getParticleDetail(i);

		g = rand() % gals;

		pd->mass = frand(galMassMin[g], galMassMax[g]);

//		if (g % 2 == 0)
//			pd->mass = -pd->mass;

		totalMass += pd->mass;

		// position
		VectorCopy(galPos[g], p->pos);
		setRangePosition((float *)&shit, galSize[g]);
		VectorAdd(p->pos, shit, p->pos);


		// galaxy structured position
		angle = frand(0, PI*2);
		radius = frand(0, galSize[g]);

		VectorZero(p->pos);

		p->pos[0] = cos(angle) * radius;
		p->pos[1] = sin(angle) * radius;
		p->pos[2] = frand(-radius/10, radius/10);

		VectorAdd(galPos[g], p->pos, p->pos);

		angle2 = angle + PI / 2;

		p->vel[0] = cos(angle2) * radius * 0.05f;
		p->vel[1] = sin(angle2) * radius * 0.05f;
		p->vel[2] = 0;

		VectorAdd(galVel[g], p->vel, p->vel);

		if (g & 2) {
			p->vel[0] = -p->vel[0];
			p->vel[1] = -p->vel[1];
			p->vel[2] = -p->vel[2];
		}

	}

	conAdd(LLOW, "- %f total mass...", totalMass);
	conAdd(LLOW, "- %f galaxy mass...", totalMass / gals);
	conAdd(LLOW, "- %f particle mass...", totalMass / state.particleCount);

	return 0;

}
Пример #3
0
static void *
halftone_init (Display *dpy, Window window)
{
  int x, y, i;
  int count;
  int spacing;
  double factor;
  double min_mass;
  double max_mass;
  double min_speed;
  double max_speed;
  XGCValues gc_values;
  XWindowAttributes attrs;
  halftone_screen *halftone;

  halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen));

  halftone->dpy = dpy;
  halftone->window = window;

  //halftone->delay = get_integer_resource (dpy, "delay", "Integer");
  //halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);
  halftone->delay = delay;
  halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);

  halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values);

  halftone->buffer_width = -1;
  halftone->buffer_height = -1;
  halftone->dots = NULL;

  /* Read command line arguments and set all settings. */ 
  //count = get_integer_resource (dpy, "count", "Count");
  count = count_;
  halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count; 

  //spacing = get_integer_resource (dpy, "spacing", "Integer");
  spacing = spacing_;
  halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing; 

  //factor = get_float_resource (dpy, "sizeFactor", "Double");
  factor = sizeFactor;
  halftone->max_dot_size = 
    (factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing; 

  //min_mass = get_float_resource (dpy, "minMass", "Double");
  min_mass = minMass;
  min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass;

  //max_mass = get_float_resource (dpy, "maxMass", "Double");
  max_mass = maxMass;
  max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass;
  max_mass = max_mass < min_mass ? min_mass : max_mass;

  //min_speed = get_float_resource (dpy, "minSpeed", "Double");
  min_speed = minSpeed;
  min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed;

  //max_speed = get_float_resource (dpy, "maxSpeed", "Double");
  max_speed = maxSpeed;
  max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed;
  max_speed = max_speed < min_speed ? min_speed : max_speed;


  /* Set up the moving gravity points. */
  halftone->gravity_point_x = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_y = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_mass = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_x_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_y_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double));

  for (i = 0; i < halftone->gravity_point_count; i++)
  {
    halftone->gravity_point_x[i] = frand(1);
    halftone->gravity_point_y[i] = frand(1);
    halftone->gravity_point_mass[i] = min_mass + (max_mass - min_mass) * frand(1);
    halftone->gravity_point_x_inc[i] = min_speed + (max_speed - min_speed) * frand(1);
    halftone->gravity_point_y_inc[i] = min_speed + (max_speed - min_speed) * frand(1);
  }


  /* Set up the dots. */
  XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);  

  //halftone->ncolors = get_integer_resource (dpy, "colors", "Colors");
  halftone->ncolors = colors;
  if (halftone->ncolors < 4) halftone->ncolors = 4;
  halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor));
  make_smooth_colormap (attrs.screen, attrs.visual, attrs.colormap,
                        halftone->colors, &halftone->ncolors,
                        True, 0, False);
  halftone->color0 = 0;
  halftone->color1 = halftone->ncolors / 2;
  //halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed");
  halftone->cycle_speed = cycleSpeed;
  halftone->color_tick = 0;

  update_buffer(halftone, &attrs);
  update_dot_attributes(halftone, &attrs);

  for (x = 0; x < halftone->dots_width; x++)
    for (y = 0; y < halftone->dots_height; y++)
    {
	halftone->dots[x + y * halftone->dots_width] = 0;
    }

  return halftone;
}
Пример #4
0
bool ParticleEmitter::Update(const clock_t diff)
{
    //Nejdrive pricist k celkovemu casu ten ubehly (milisekundy)
    totaltime += diff;

    //Pak porovnat celkovy cas, zdali uz ubehnul maximalni cas
    if(totaltime >= time)
        return false; //--> odstranit emitter z listu pro update
    //TODO: dodelat "dojizdeni" emitteru - cas po ktery uz nebudou vydavany castice, ale
    //stare castice se budou stale pohybovat, az zmizi. Po tu dobu vracet stale true!

    uint32 newparticlescount = 10;

    //Zde update vsech castic a emit novych
    while(newparticlescount > 0)
    {
        if (Particles.size() < velocity-1)
        {
            if (nextParticleCountdown < diff)
            {
                //vytvorit novou castici
                Particle* pNew = new Particle;
                //a priradit ji veskere hodnoty

                //velice neuniverzalni a ne prilis profesionalni postup zde
                pNew->sx = x;
                pNew->sz = z;
                if (dirangleh < PI/4 || dirangleh > 7*PI/4 || (dirangleh > 3*PI/4 && dirangleh < 5*PI/4) )
                    pNew->sz = z+frand(square1,square3);
                else
                    pNew->sx = x+frand(square1,square3);
                pNew->sy = y+frand(square2,square4);
                //az sem

                pNew->modelId = modelId;
                pNew->actTime = 0;
                pNew->destrange = frand(minrange,maxrange);
                pNew->hangle = frand(dirangleh-angleh/2,dirangleh+angleh/2);
                pNew->vangle = frand(diranglev-anglev/2,diranglev+anglev/2);
                pNew->modelSize = modelSize+frand(min(0,sizevar),max(0,sizevar));
                float rotate = 0.0f;
                if (flags & EMIT_FLAG_RANDOM_ROTATE)
                    rotate = frand(0,PI);

                //pridat ji do display listu a ulozit pointer
                pNew->pRec = gDisplay.DrawModel(x,y,z,modelId, ANIM_IDLE,false,pNew->modelSize,rotate);

                Particles.push_back(pNew);
                nextParticleCountdown = density;
            } else nextParticleCountdown -= diff;
        }
        --newparticlescount;
    }

    Particle* temp;
    // Projit particles a rozpohybovat je
    for (std::list<Particle*>::iterator itr = Particles.begin(); itr != Particles.end(); ++itr)
    {
        temp = *itr;

        //pricist cas ktery ubehl [ms]
        temp->actTime += diff;

        if (!temp->pRec)
            continue;

        //speed [pocet tisicin rozmeru za 1 sekundu]
        temp->pRec->x = temp->sx+(float(temp->actTime)/1000)*(float(speed)/1000)*cos(temp->hangle);
        temp->pRec->y = temp->sy+(float(temp->actTime)/1000)*(float(speed)/1000)*sin(temp->vangle);
        temp->pRec->z = temp->sz+(float(temp->actTime)/1000)*(float(speed)/1000)*sin(temp->hangle);

        //pokud castice urazila drahu jakou ma urazit, vymazeme ji
        if (pythagoras_c(pythagoras_c(temp->pRec->x-temp->sx,temp->pRec->z-temp->sz),temp->pRec->y-temp->sy) > temp->destrange)
        {
            temp->pRec->remove = true;
            itr = Particles.erase(itr);
            if (itr == Particles.end())
                break;
            if (itr != Particles.begin())
                --itr;
            continue;
        }
    }

    return true; //false pokud emitter dosahne maximalniho casu pusobeni nebo je jinak odstranen
}
Пример #5
0
static double
bellrand (double extent)    /* like frand(), but a bell curve. */
{
  return (((frand(extent) + frand(extent) + frand(extent)) / 3)
          - (extent/2));
}
Пример #6
0
ParticleList& BeamEmitter::obliqueEmit(Scalar t, Scalar dt)
{
  Vector2 xMKS;
  for (int j=0; j < 4*(j2 - j1) + 2; j += 2){
		int index = j/2;
		int jl = points[j];
		int kl = points[j+1];
		int jh = points[j+2];
		int kh = points[j+3];

		if (jh == jl && kh == kl) continue; // if this is a duplicate point, get next

		Vector2 p1 = fields->getMKS(jl, kl); // note these are local to this segment
		Vector2 p2 = fields->getMKS(jh, kh);
		Scalar localRate = emissionRate*dt*get_time_value(t)*area[index]/totalArea;
		oblExtra[index] += localRate;

		if (oblExtra[index] < 1) continue; // not enough to emit in this cell
		Scalar del_t = dt/localRate;
		while (oblExtra[index] >= 1) {
			oblExtra[index] -= 1;
			if (kl == kh || !rweight)
				xMKS = p1 + frand()*(p2 - p1);
			else {
				Scalar r_min = p1.e2();
				Scalar r_max = p2.e2();
				xMKS = Vector2(0.5*(p1.e1() + p2.e1()),
									sqrt(r_min*r_min + (r_max*r_max - r_min*r_min)*frand()));
			}
			Vector2 x = fields->getGridCoords(xMKS);
			if (kl == kh) { // horizontal
//				x += deltaHorizontal; // perturb particles off boundary
				normal = Vector3(0, 1, 0)*get_normal();
			}
			else if (k2 > k1) { // up and right
//				x -= deltaVertical;
				normal = Vector3(-1, 0, 0)*get_normal();
			}
			else { // down and right
//				x += deltaVertical;
				normal = Vector3(1, 0, 0)*get_normal();
			}
			Vector3 u;
			if (thetaDot.e3()){
				// only correct if r*thetaDot << vz
				//  thetaDot is yDot for ZXgeometry
				Vector3 v = maxwellian->get_V(normal);
				if (rweight) v+=xMKS.e2()*thetaDot;
				u = v/sqrt(1-v*v*iSPEED_OF_LIGHT_SQ);
			}
			else 
				u = maxwellian->get_U(normal);

			x += delta;

			Particle* p = new Particle(x, u, species, np2c);
			Boundary* bPtr = initialPush(del_t*oblExtra[index], dt, *p);
			if (!bPtr) particleList.add(p);
		}
  }
  return particleList;
}
Пример #7
0
void CLQ2_RailTrail( vec3_t start, vec3_t end ) {
	byte clr = 0x74;

	vec3_t move;
	VectorCopy( start, move );
	vec3_t vec;
	VectorSubtract( end, start, vec );
	float len = VectorNormalize( vec );

	vec3_t right, up;
	MakeNormalVectors( vec, right, up );

	for ( int i = 0; i < len; i++ ) {
		cparticle_t* p = CL_AllocParticle();
		if ( !p ) {
			return;
		}

		p->type = pt_q2static;

		VectorClear( p->accel );

		float d = i * 0.1;
		float c = cos( d );
		float s = sin( d );

		vec3_t dir;
		VectorScale( right, c, dir );
		VectorMA( dir, s, up, dir );

		p->alpha = 1.0;
		p->alphavel = -1.0 / ( 1 + frand() * 0.2 );
		p->color = clr + ( rand() & 7 );
		for ( int j = 0; j < 3; j++ ) {
			p->org[ j ] = move[ j ] + dir[ j ] * 3;
			p->vel[ j ] = dir[ j ] * 6;
		}

		VectorAdd( move, vec, move );
	}

	float dec = 0.75;
	VectorScale( vec, dec, vec );
	VectorCopy( start, move );

	while ( len > 0 ) {
		len -= dec;

		cparticle_t* p = CL_AllocParticle();
		if ( !p ) {
			return;
		}
		p->type = pt_q2static;

		VectorClear( p->accel );

		p->alpha = 1.0;
		p->alphavel = -1.0 / ( 0.6 + frand() * 0.2 );
		p->color = rand() & 15;

		for ( int j = 0; j < 3; j++ ) {
			p->org[ j ] = move[ j ] + crand() * 3;
			p->vel[ j ] = crand() * 3;
			p->accel[ j ] = 0;
		}

		VectorAdd( move, vec, move );
	}
}
Пример #8
0
/**
 * @brief Choose if a new ground mission should be started.
 * @note Recon mission -- Stage 1
 * @note Already one ground mission has been made
 * @sa CP_ReconMissionSelect
 */
static bool CP_ReconMissionNewGroundMission (mission_t *mission)
{
	return (frand() > 0.7f);
}
Пример #9
0
bool FleeingMovementGenerator<T>::_getPoint(T& owner, float& x, float& y, float& z)
{
    if (!&owner)
        { return false; }

    float dist_from_caster, angle_to_caster;
    if (Unit* fright = ObjectAccessor::GetUnit(owner, i_frightGuid))
    {
        dist_from_caster = fright->GetDistance(&owner);
        if (dist_from_caster > 0.2f)
            { angle_to_caster = fright->GetAngle(&owner); }
        else
            { angle_to_caster = frand(0, 2 * M_PI_F); }
    }
    else
    {
        dist_from_caster = 0.0f;
        angle_to_caster = frand(0, 2 * M_PI_F);
    }

    float dist, angle;
    if (dist_from_caster < MIN_QUIET_DISTANCE)
    {
        dist = frand(0.4f, 1.3f) * (MIN_QUIET_DISTANCE - dist_from_caster);
        angle = angle_to_caster + frand(-M_PI_F / 8, M_PI_F / 8);
    }
    else if (dist_from_caster > MAX_QUIET_DISTANCE)
    {
        dist = frand(0.4f, 1.0f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
        angle = -angle_to_caster + frand(-M_PI_F / 4, M_PI_F / 4);
    }
    else    // we are inside quiet range
    {
        dist = frand(0.6f, 1.2f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
        angle = frand(0, 2 * M_PI_F);
    }

    float curr_x, curr_y, curr_z;
    owner.GetPosition(curr_x, curr_y, curr_z);

    x = curr_x + dist * cos(angle);
    y = curr_y + dist * sin(angle);
    z = curr_z + 0.5f;

    // try to fix z
    if (!owner.GetMap()->GetHeightInRange(owner.GetPhaseMask(), x, y, z))
        return false;
    
    if (owner.GetTypeId() == TYPEID_PLAYER)
    {
        // check any collision
        float testZ = z + 0.5f; // needed to avoid some false positive hit detection of terrain or passable little object
        if (owner.GetMap()->GetHitPosition(curr_x, curr_y, curr_z + 0.5f, x, y, testZ, owner.GetPhaseMask(), -0.1f))
        {
            z = testZ;
            if (!owner.GetMap()->GetHeightInRange(owner.GetPhaseMask(), x, y, z))
                return false;
        }
    }

    return true;
}
Пример #10
0
void CL_Heatbeam (vec3_t start, vec3_t end)
{
	vec3_t		move;
	vec3_t		vec;
	float		len;
	int			j;
	cparticle_t	*p;
	vec3_t		forward, right, up;
	int			i;
	float		d, c, s;
	vec3_t		dir;
	float		ltime;
	float		step = 32.0, rstep;
	float		start_pt;
	float		rot;

	VectorCopy (start, move);
	VectorSubtract (end, start, vec);
	len = VectorNormalize (vec);

//	MakeNormalVectors (vec, right, up);
	VectorCopy (cl.v_forward, forward);
	VectorCopy (cl.v_right, right);
	VectorCopy (cl.v_up, up);
	VectorMA (move, -0.5, right, move);
	VectorMA (move, -0.5, up, move);

	for (i=0; i<8; i++)
	{
		if (!free_particles)
			return;

		p = free_particles;
		free_particles = p->next;
		p->next = active_particles;
		active_particles = p;
		
		p->time = cl.time;
		VectorClear (p->accel);
		
		d = crand()*M_PI;
		c = cos(d)*30;
		s = sin(d)*30;

		p->alpha = 1.0;
		p->alphavel = -5.0 / (1+frand());
		p->color = 223 - (rand()&7);

		for (j=0 ; j<3 ; j++)
		{
			p->org[j] = move[j];
		}
		VectorScale (vec, 450, p->vel);
		VectorMA (p->vel, c, right, p->vel);
		VectorMA (p->vel, s, up, p->vel);
	}
/*

	ltime = (float) cl.time/1000.0;
	start_pt = fmod(ltime*16.0,step);
	VectorMA (move, start_pt, vec, move);

	VectorScale (vec, step, vec);

//	Com_Printf ("%f\n", ltime);
	rstep = M_PI/12.0;
	for (i=start_pt ; i<len ; i+=step)
	{
		if (i>step*5) // don't bother after the 5th ring
			break;

		for (rot = 0; rot < M_PI*2; rot += rstep)
		{
			if (!free_particles)
				return;

			p = free_particles;
			free_particles = p->next;
			p->next = active_particles;
			active_particles = p;
			
			p->time = cl.time;
			VectorClear (p->accel);
//			rot+= fmod(ltime, 12.0)*M_PI;
//			c = cos(rot)/2.0;
//			s = sin(rot)/2.0;
			c = cos(rot)/1.5;
			s = sin(rot)/1.5;
			
			// trim it so it looks like it's starting at the origin
			if (i < 10)
			{
				VectorScale (right, c*(i/10.0), dir);
				VectorMA (dir, s*(i/10.0), up, dir);
			}
			else
			{
				VectorScale (right, c, dir);
				VectorMA (dir, s, up, dir);
			}
		
			p->alpha = 0.5;
	//		p->alphavel = -1.0 / (1+frand()*0.2);
			p->alphavel = -1000.0;
	//		p->color = 0x74 + (rand()&7);
			p->color = 223 - (rand()&7);
			for (j=0 ; j<3 ; j++)
			{
				p->org[j] = move[j] + dir[j]*3;
	//			p->vel[j] = dir[j]*6;
				p->vel[j] = 0;
			}
		}
		VectorAdd (move, vec, move);
	}
*/
}
Пример #11
0
ENTRYPOINT void
init_planet (ModeInfo * mi)
{
  planetstruct *gp;
  int screen = MI_SCREEN(mi);
  Bool wire = MI_IS_WIREFRAME(mi);

  if (planets == NULL) {
	if ((planets = (planetstruct *) calloc(MI_NUM_SCREENS(mi),
										  sizeof (planetstruct))) == NULL)
	  return;
  }
  gp = &planets[screen];

  if ((gp->glx_context = init_GL(mi)) != NULL) {
	reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  }

  {
	//char *f = get_string_resource(mi->dpy, "imageForeground", "Foreground");
	//char *b = get_string_resource(mi->dpy, "imageBackground", "Background");
	char *f = _strdup(imageForeground);
	char *b = _strdup(imageBackground);
	char *s;
	if (!f) f = _strdup("white");
	if (!b) b = _strdup("black");
	
	for (s = f + strlen(f)-1; s > f; s--)
	  if (*s == ' ' || *s == '\t')
		*s = 0;
	for (s = b + strlen(b)-1; s > b; s--)
	  if (*s == ' ' || *s == '\t')
		*s = 0;

    if (!XParseColor(mi->dpy, mi->xgwa.colormap, f, &gp->fg))
      {
		fprintf(stderr, "%s: unparsable color: \"%s\"\n", progname, f);
		exit(1);
      }
    if (!XParseColor(mi->dpy, mi->xgwa.colormap, b, &gp->bg))
      {
		fprintf(stderr, "%s: unparsable color: \"%s\"\n", progname, f);
		exit(1);
      }

	free (f);
	free (b);
  }

  {
    double spin_speed   = 0.5;
    double wander_speed = 0.02;
    gp->rot = make_rotator (do_roll ? spin_speed : 0,
                            do_roll ? spin_speed : 0,
                            0, 1,
                            do_wander ? wander_speed : 0,
                            True);
    gp->z = frand (1.0);
    gp->trackball = gltrackball_init ();
  }

  if (wire)
    {
      do_texture = False;
      do_light = False;
    }

  if (do_texture)
    setup_texture (mi);

  if (do_light)
	init_sun (mi);

  if (do_stars)
    init_stars (mi);

  if (random() & 1)
    star_spin = -star_spin;

  /* construct the polygons of the planet
   */
  gp->platelist = glGenLists(1);
  glNewList (gp->platelist, GL_COMPILE);
  glColor3f (1,1,1);
  glPushMatrix ();
  glScalef (RADIUS, RADIUS, RADIUS);
  glRotatef (90, 1, 0, 0);
  glFrontFace(GL_CCW);
  unit_sphere (resolution, resolution, wire);
  glPopMatrix ();
  glEndList();

  /* construct the polygons of the latitude/longitude/axis lines.
   */
  gp->latlonglist = glGenLists(1);
  glNewList (gp->latlonglist, GL_COMPILE);
  glPushMatrix ();
  glDisable (GL_TEXTURE_2D);
  glDisable (GL_LIGHTING);
  glDisable (GL_LINE_SMOOTH);
  glColor3f (0.1, 0.3, 0.1);
  glScalef (RADIUS, RADIUS, RADIUS);
  glScalef (1.01, 1.01, 1.01);
  glRotatef (90, 1, 0, 0);
  unit_sphere (12, 24, 1);
  glBegin(GL_LINES);
  glVertex3f(0, -2, 0);
  glVertex3f(0,  2, 0);
  glEnd();
  glPopMatrix ();
  glEndList();
}
Пример #12
0
// commented out to remove unused parameter warnings in Linux
void key(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key) 
    {
    case ' ':
        bPause = !bPause;
        break;
    case 13:
        psystem->update(timestep); 
        renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
        break;
    case '\033':
    case 'q':
        exit(0);
        break;
    case 'v':
        mode = M_VIEW;
        break;
    case 'm':
        mode = M_MOVE;
        break;
    case 'p':
        displayMode = (ParticleRenderer::DisplayMode)
                      ((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
        break;
    case 'd':
        psystem->dumpGrid();
        break;
    case 'u':
        psystem->dumpParticles(0, 1);
        break;

    case 'r':
        displayEnabled = !displayEnabled;
        break;

    case '1':
        psystem->reset(ParticleSystem::CONFIG_GRID);
        break;
    case '2':
        psystem->reset(ParticleSystem::CONFIG_RANDOM);
        break;
    case '3':
        {
            // inject a sphere of particles
            float pr = psystem->getParticleRadius();
            float tr = pr+(pr*2.0f)*ballr;
            float pos[4], vel[4];
            pos[0] = -1.0 + tr + frand()*(2.0f - tr*2.0f);
            pos[1] = 1.0f - tr;
            pos[2] = -1.0 + tr + frand()*(2.0f - tr*2.0f);
            pos[3] = 0.0f;
            vel[0] = vel[1] = vel[2] = vel[3] = 0.0f;
            psystem->addSphere(0, pos, vel, ballr, pr*2.0f);
        }
        break;
    case '4':
        {
            // shoot ball from camera
            float pr = psystem->getParticleRadius();
            float vel[4], velw[4], pos[4], posw[4];
            vel[0] = 0.0f;
            vel[1] = 0.0f;
            vel[2] = -0.05f;
            vel[3] = 0.0f;
            ixform(vel, velw, modelView);

            pos[0] = 0.0f;
            pos[1] = 0.0f;
            pos[2] = -2.5f;
            pos[3] = 1.0;
            ixformPoint(pos, posw, modelView);
            posw[3] = 0.0f;

            psystem->addSphere(0, posw, velw, ballr, pr*2.0f);
        }
        break;

    case 'w':
        wireframe = !wireframe;
        break;

    case 'h':
        displaySliders = !displaySliders;
        break;
    }

    glutPostRedisplay();
}
Пример #13
0
void intro_init( void )
{
    // create openGL functions
    for (int i=0; i<NUM_GL_NAMES; i++) glFP[i] = (GenFP)wglGetProcAddress(glnames[i]);

    // create noise Texture
#ifdef FLOAT_TEXTURE
    for (int i = 0; i < NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * 4; i++)
    {
        noiseData[i] = frand() - 0.5f;
    }
#else
    for (int i = 0; i < NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * 4; i++)
    {
        noiseData[i] = (unsigned char)rand();
    }
#endif

    // Create and link shader and stuff:
    // I will have to separate these to be able to use more than one shader...
    // TODO: I should make some sort of compiling and linking loop...

    // init objects:
    GLuint vMainObject = glCreateShader(GL_VERTEX_SHADER);
    GLuint fMainBackground = glCreateShader(GL_FRAGMENT_SHADER);
    GLuint fOffscreenCopy = glCreateShader(GL_FRAGMENT_SHADER);
    shaderPrograms[0] = glCreateProgram();
    shaderPrograms[1] = glCreateProgram();
    // compile sources:
    glShaderSource(vMainObject, 1, &vertexMainObject, NULL);
    glCompileShader(vMainObject);
    glShaderSource(fMainBackground, 1, &fragmentMainBackground, NULL);
    glCompileShader(fMainBackground);
    glShaderSource(fOffscreenCopy, 1, &fragmentOffscreenCopy, NULL);
    glCompileShader(fOffscreenCopy);

#ifdef SHADER_DEBUG
    // Check programs
    int tmp, tmp2;
    glGetShaderiv(vMainObject, GL_COMPILE_STATUS, &tmp);
    if (!tmp)
    {
        glGetShaderInfoLog(vMainObject, 4096, &tmp2, err);
        err[tmp2]=0;
        MessageBox(hWnd, err, "vMainObject shader error", MB_OK);
        return;
    }
    glGetShaderiv(fMainBackground, GL_COMPILE_STATUS, &tmp);
    if (!tmp)
    {
        glGetShaderInfoLog(fMainBackground, 4096, &tmp2, err);
        err[tmp2]=0;
        MessageBox(hWnd, err, "fMainBackground shader error", MB_OK);
        return;
    }
    glGetShaderiv(fOffscreenCopy, GL_COMPILE_STATUS, &tmp);
    if (!tmp)
    {
        glGetShaderInfoLog(fOffscreenCopy, 4096, &tmp2, err);
        err[tmp2]=0;
        MessageBox(hWnd, err, "fOffscreeCopy shader error", MB_OK);
        return;
    }
#endif

    // link shaders:
    glAttachShader(shaderPrograms[0], vMainObject);
    glAttachShader(shaderPrograms[0], fMainBackground);
    glLinkProgram(shaderPrograms[0]);
    glAttachShader(shaderPrograms[1], vMainObject);
    glAttachShader(shaderPrograms[1], fOffscreenCopy);
    glLinkProgram(shaderPrograms[1]);

    // Set texture.
    glEnable(GL_TEXTURE_3D); // automatic?
    glGenTextures(1, &noiseTexture);
    glBindTexture(GL_TEXTURE_3D, noiseTexture);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
#ifdef FLOAT_TEXTURE
    glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F,
                 NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE,
                 0, GL_RGBA, GL_FLOAT, noiseData);
#else
    glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8,
                 NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE,
                 0, GL_RGBA, GL_UNSIGNED_BYTE, noiseData);
#endif

    // Create a rendertarget texture
    glGenTextures(1, &offscreenTexture);
    glBindTexture(GL_TEXTURE_2D, offscreenTexture);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, OFFSCREEN_WIDTH, OFFSCREEN_HEIGHT, 0,
                 GL_RGBA, GL_UNSIGNED_BYTE, 0);
    //glBindTexture(GL_TEXTURE_2D, 0);
}
Пример #14
0
VOID	RayTrace(INT pid)
	{
	INT	j;
	INT	x, y;			/* Pixel address.		     */
	REAL	xx, yy;
	VEC3	N;			/* Normal at intersection.	     */
	VEC3	Ipoint; 		/* Intersection point.		     */
	COLOR	c;			/* Color for storing background.     */
	RAY	*ray;			/* Ray pointer. 		     */
	RAY	rmsg;			/* Ray message. 		     */
	RAYJOB	job;			/* Ray job from work pool.	     */
	OBJECT	*po;			/* Ptr to object.		     */
	BOOL	hit;			/* An object hit?		     */
	IRECORD hitrecord;		/* Intersection record. 	     */

	ray = &rmsg;

	while (GetJobs(&job, pid) != WPS_EMPTY)
		{
		while (GetRayJobFromBundle(&job, &x, &y))
			{
			/* Convert the ray job to the ray message format. */

			xx = (REAL)x;
			yy = (REAL)y;

			if (AntiAlias)
				for (j = 0; j < NumSubRays; j++)
					{
					ConvertPrimRayJobToRayMsg(ray, xx + frand(), yy + frand());
					PushRayTreeStack(ray, pid);
					}
			else
				{
				ConvertPrimRayJobToRayMsg(ray, xx, yy);
				PushRayTreeStack(ray, pid);
				}

			while (PopRayTreeStack(ray, pid) != RTS_EMPTY)
				{
				/* Find which object is closest along the ray. */

				switch (TraversalType)
					{
					case TT_LIST:
						hit = Intersect(ray, &hitrecord);
						break;

					case TT_HUG:
						hit = TraverseHierarchyUniform(ray, &hitrecord, pid);
						break;
					}

				/* Process the object ray hit. */

				if (hit)
					{
					/*
					 *  Get parent object to be able to access
					 *  object operations.
					 */

					po = hitrecord.pelem->parent;

					/* Calculate intersection point. */
					RayPoint(Ipoint, ray, hitrecord.t);

					/* Calculate normal at this point. */
					((void (*)(IRECORD *, VEC3, VEC3))(*po->procs->normal))(&hitrecord, Ipoint, N);

					/* Make sure normal is pointing toward ray origin. */
					if ((VecDot(ray->D, N)) >  0.0)
						VecNegate(N, N);

					/*
					 *  Compute shade at this point - will process
					 *  shadow rays and add secondary reflection
					 *  and refraction rays to ray tree stack
					 */

					Shade(Ipoint, N, ray, &hitrecord, pid);
					}
				else
					{
					/* Add background as pixel contribution. */

					VecCopy(c, View.bkg);
					VecScale(c, ray->weight, c);
					AddPixelColor(c, ray->x, ray->y);
					}
				}
			}
		}
	}
Пример #15
0
void PetAI::MoveToVictim(Unit* u)
{
    if (!u)
        return;

    switch (m_AIType)
    {
        case PET_AI_PASSIVE:
        case PET_AI_SLACKER:
        case PET_AI_HEALER:
            if (Unit* owner = m_creature->GetCharmerOrOwner())
                m_creature->GetMotionMaster()->MoveChase(owner, PET_FOLLOW_DIST, m_creature->IsPet() ? ((Pet*)m_creature)->GetPetFollowAngle() : PET_FOLLOW_ANGLE);
            break;
        case PET_AI_RANGED:
            if (sWorld.getConfig(CONFIG_BOOL_PET_ADVANCED_AI))
                m_creature->GetMotionMaster()->MoveChase(u, attackDistance, m_creature->GetAngle(u) + frand(-M_PI_F/4.0f, M_PI_F/4.0f));
            else
                m_creature->GetMotionMaster()->MoveChase(u);
            break;
        case PET_AI_MELEE:
        case PET_AI_RANGED_NOAMMO:
        default:
            m_creature->GetMotionMaster()->MoveChase(u);
            break;
    }
    DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS,"PetAI::MoveToVictim pet %s move to %s, distance %f,  AI type %u",
        m_creature->GetObjectGuid().GetString().c_str(),u ? u->GetObjectGuid().GetString().c_str() : "<none>",attackDistance, m_AIType);
}
Пример #16
0
/* task that renders a single screen tile */
Vec3fa renderPixelPathTrace(float x, float y, const Vec3fa& vx, const Vec3fa& vy, const Vec3fa& vz, const Vec3fa& p)
{
  int seed = 21344*x+121233*y+234532*g_accu_count;
  float time = frand(seed);

  /* initialize ray */
  RTCRay2 ray;
  ray.org = p;
  ray.dir = normalize(x*vx + y*vy + vz);
  ray.tnear = 0.0f;
  ray.tfar = inf;
  ray.geomID = RTC_INVALID_GEOMETRY_ID;
  ray.primID = RTC_INVALID_GEOMETRY_ID;
  ray.mask = -1;
  ray.time = time;
  ray.filter = NULL; 
  
  Vec3fa color = Vec3fa(0.0f);
  Vec3fa weight = Vec3fa(1.0f);
  size_t depth = 0;

  while (true)
  {
    /* terminate ray path */
    if (reduce_max(weight) < 0.01 || depth > 20) 
      return color;

    /* intersect ray with scene and gather all hits */
    rtcIntersect(g_scene,*((RTCRay*)&ray)); // FIXME: use (RTCRay&) cast
    
    /* exit if we hit environment */
    if (ray.geomID == RTC_INVALID_GEOMETRY_ID) 
      return color + weight*Vec3fa(g_ambient_intensity);

    /* calculate transmissivity of hair */
    AnisotropicBlinn brdf;
    float tnear_eps = 0.0001f;

    if (ray.geomID < g_ispc_scene->numHairSets) 
    {
      /* calculate tangent space */
      const Vec3fa dx = normalize(ray.Ng);
      const Vec3fa dy = normalize(cross(ray.dir,dx));
      const Vec3fa dz = normalize(cross(dy,dx));

      /* generate anisotropic BRDF */
      AnisotropicBlinn__Constructor(&brdf,hair_Kr,hair_Kt,dx,20.0f,dy,2.0f,dz);
      brdf.Kr = hair_Kr;
      Vec3fa p = evalBezier(ray.geomID,ray.primID,ray.u);
      tnear_eps = 1.1f*p.w;
    }
    else 
    {
      int meshID = ray.geomID-g_ispc_scene->numHairSets;
      ISPCMesh* mesh = g_ispc_scene->meshes[meshID];
      ISPCTriangle* triangle = &mesh->triangles[ray.primID];
      ISPCMaterial* material = &g_ispc_scene->materials[triangle->materialID];
      if (material->illum == 1)
      {
        /* calculate tangent space */
        const Vec3fa dx = normalize(Vec3fa(mesh->normals[triangle->v0]));
        const Vec3fa dy = normalize(cross(ray.dir,dx));
        const Vec3fa dz = normalize(cross(dy,dx));
        
        /* generate anisotropic BRDF */
        AnisotropicBlinn__Constructor(&brdf,hair_Kr,hair_Kt,dx,20.0f,dy,2.0f,dz);
        brdf.Kr = hair_Kr;
        tnear_eps = 1.1f*mesh->texcoords[triangle->v0].x;
      }
      else
      {
        if (dot(ray.dir,ray.Ng) > 0) ray.Ng = neg(ray.Ng);
        
        /* calculate tangent space */
        const Vec3fa dz = normalize(ray.Ng);
        const Vec3fa dx = normalize(cross(dz,ray.dir));
        const Vec3fa dy = normalize(cross(dz,dx));
        
        /* generate isotropic BRDF */
        AnisotropicBlinn__Constructor(&brdf,Vec3fa(1.0f),Vec3fa(0.0f),dx,1.0f,dy,1.0f,dz);
      }
    }
    
    /* sample directional light */
    RTCRay2 shadow;
    shadow.org = ray.org + ray.tfar*ray.dir;
    shadow.dir = neg(Vec3fa(g_dirlight_direction));
    shadow.tnear = tnear_eps;
    shadow.tfar = inf;
    shadow.time = time;
    Vec3fa T = occluded(g_scene,shadow);
    Vec3fa c = AnisotropicBlinn__eval(&brdf,neg(ray.dir),neg(Vec3fa(g_dirlight_direction)));
    color = color + weight*c*T*Vec3fa(g_dirlight_intensity); // FIXME: use += operator

#if 1
    /* sample BRDF */
    Vec3fa wi;
    c = AnisotropicBlinn__sample(&brdf,neg(ray.dir),wi,frand(seed),frand(seed),frand(seed));
    if (wi.w <= 0.0f) return color;

    /* calculate secondary ray and offset it out of the hair */
    float sign = dot(Vec3fa(wi),brdf.dz) < 0.0f ? -1.0f : 1.0f;
    ray.org = ray.org + ray.tfar*ray.dir + sign*tnear_eps*brdf.dz;
    ray.dir = Vec3fa(wi);
    ray.tnear = 0.001f;
    ray.tfar = inf;
    ray.geomID = RTC_INVALID_GEOMETRY_ID;
    ray.primID = RTC_INVALID_GEOMETRY_ID;
    ray.mask = -1;
    ray.time = time;
    ray.filter = NULL;
    weight = weight * c/wi.w; // FIXME: use *= operator

#else    

    /* continue with transparency ray */
    ray.geomID = RTC_INVALID_GEOMETRY_ID;
    ray.tnear = 1.001f*ray.tfar;
    ray.tfar = inf;
    weight *= brdf.Kt;
    
#endif

    depth++;
  }
  return color;
}
Пример #17
0
            void UpdateAI(const uint32 diff)
            {
                if (!UpdateVictim())
                    return;

                if (me->HasUnitState(UNIT_STATE_CASTING))
                    return;

                events.Update(diff);

                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_SECONDARY_ATTACK:
                        {
                            if (Unit* target = SelectTarget(SELECT_TARGET_TOPAGGRO))
                            {
                                uint32 spellId = RAND(SPELL_RIGHT_CROSS, SPELL_LEFT_HOOK, SPELL_HAMMER_FIST, SPELL_SWEEPING_KICK);
                                me->CastSpell(target, spellId, true);
                            }
                            events.ScheduleEvent(EVENT_SECONDARY_ATTACK, urand(5000, 10000));
                            break;
                        }
                        case EVENT_SUMMON_TOTEM:
                        {
                            me->MonsterTextEmote("Gara'jal summons a Spirit Totem. Use it to Cross Over to the Spirit World !", 0, true);
                            float x = 0.0f, y = 0.0f;
                            GetRandPosFromCenterInDist(4277.08f, 1341.35f, frand(0.0f, 30.0f), x, y);
                            me->SummonCreature(NPC_SPIRIT_TOTEM, x, y, 454.55f, 0.0f, TEMPSUMMON_CORPSE_DESPAWN);
                            events.ScheduleEvent(EVENT_SUMMON_TOTEM,     urand(47500, 52500));
                            break;
                        }
                        case EVENT_SUMMON_SHADOWY_MINION:
                        {
                            float x = 0.0f, y = 0.0f;
                            GetRandPosFromCenterInDist(4277.08f, 1341.35f, frand(0.0f, 30.0f), x, y);
                            me->SummonCreature(NPC_SHADOWY_MINION_REAL, x, y, 454.55f, 0.0f, TEMPSUMMON_CORPSE_DESPAWN);
                            events.ScheduleEvent(EVENT_SUMMON_SHADOWY_MINION,     urand(10000, 15000));
                            break;
                        }
                        case EVENT_VOODOO_DOLL:
                        {
                            pInstance->DoRemoveAurasDueToSpellOnPlayers(SPELL_VOODOO_DOLL_VISUAL);
                            pInstance->DoRemoveAurasDueToSpellOnPlayers(SPELL_VOODOO_DOLL_SHARE);
                            me->MonsterTextEmote("Gara'jal selects random players to become Voodoo Dolls !", 0, true);

                            int32 mobCount = Is25ManRaid() ? 4 : 3;

                            for (int32 i = 0; i < mobCount; ++i)
                            {
                                if (Unit* target = SelectTarget(i == 0 ? SELECT_TARGET_TOPAGGRO : SELECT_TARGET_RANDOM, 0, 0, true, -SPELL_VOODOO_DOLL_VISUAL))
                                {
                                    voodooTargets[i] = target->GetGUID();
                                    me->MonsterTextEmote("You are a Voodoo Doll ! Damage you take is copied to the other Voodoo Dolls in your raid !", target->GetGUID(), true);
                                    target->AddAura(SPELL_VOODOO_DOLL_VISUAL, target);
                                }
                            }

                            if (Player* target = sObjectAccessor->GetPlayer(*me, voodooTargets[0]))
                                me->CastSpell(target, SPELL_VOODOO_DOLL_SHARE, true);

                            break;
                        }
                        case EVENT_BANISHMENT:
                        {
                            if (Unit* target = SelectTarget(SELECT_TARGET_TOPAGGRO))
                            {
                                me->AddAura(SPELL_BANISHMENT,       target);
                                me->AddAura(SPELL_SOUL_CUT_SUICIDE, target);
                                me->AddAura(SPELL_SOUL_CUT_DAMAGE,  target);

                                Difficulty difficulty = me->GetMap()->GetDifficulty();
                                uint64 viewerGuid = target->GetGUID();
                                uint8  mobCount   = IsHeroic() ? 3: 1;

                                for (uint8 i = 0; i < mobCount; ++i)
                                    if (Creature* soulCutter = me->SummonCreature(NPC_SOUL_CUTTER, target->GetPositionX() + 2.0f, target->GetPositionY() + 2.0f, target->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_DESPAWN, 30000, i == 0 ? viewerGuid: 0))
                                    {
                                        soulCutter->SetPhaseMask(2, true);
                                        soulCutter->AI()->AttackStart(target);
                                        soulCutter->SetInCombatWith(target);
                                        soulCutter->getThreatManager().addThreat(target, 10000.0f);
                                    }

                                me->getThreatManager().resetAllAggro();
                            }

                            pInstance->DoRemoveAurasDueToSpellOnPlayers(SPELL_VOODOO_DOLL_VISUAL);
                            pInstance->DoRemoveAurasDueToSpellOnPlayers(SPELL_VOODOO_DOLL_SHARE);

                            events.ScheduleEvent(EVENT_VOODOO_DOLL, 5000);
                            events.ScheduleEvent(EVENT_BANISHMENT, 90000);
                            break;
                        }
                        case EVENT_FINAL_DESTINATION:
                        {
                            me->CastSpell(me, SPELL_FINAL_DESTINATION, false);
                            Talk(TALK_FRENZY);
                            break;
                        }
                        default:
                            break;
                    }
                }

                DoMeleeAttackIfReady();
            }
Пример #18
0
//generate one html file in file name fname
void gen_file(char *fname, int i) {
  char progress[200];

  int len = doc_len();
    if ( 0 && i >= 20800 )
      {
	sprintf(progress, "echo 'doc len %d' >> /scratch/report.txt",(len));
        system(progress);
      }
    int linesofar = 0, total_so_far = 0;
  FILE *f = fopen(fname, "w");
  int link = 0;

  if (f != NULL) {
    fprintf(f, "<html><head></head><body>\n");
    while (1) {
      char *nextw;

    if ( 0 && i >= 20800 )
      {
	sprintf(progress, "echo 'lines so far len %d TOTAL %d' >> /scratch/report.txt",(linesofar), total_so_far);
        system(progress);
      }
      
      if (frand() < link_freq) {
	if ( 0 && i >= 20800 )
	  {
	    sprintf(progress, "echo '----------get URL ' >> /scratch/report.txt");
	    system(progress);
	  }


	nextw = get_url();
	link = 1;
      } else {
	if ( 0 && i >= 20800 )
          {
            sprintf(progress, "echo '----------get WORD ' >> /scratch/report.txt");
            system(progress);
          }

	nextw = get_word();
	link =0;
      }
      if (link) {
	fprintf(f,"<a href=\"%s\">link</a> ",nextw);
      } else {
	fprintf(f,"%s ",nextw);
      }
      linesofar = linesofar + strlen(nextw);
      if (linesofar > 80 ) {
	fprintf(f, "\n");
	total_so_far += linesofar + 1;
	if (total_so_far > len)
	  break;
	linesofar = 0;
      }
    }
    fprintf(f, "\n</body></html>");

  } else {
    printf ("Couldn't open %s\n", fname);
    exit(1);
  }
  fclose(f);
}
Пример #19
0
void CLQ2_DiminishingTrail( vec3_t start, vec3_t end, q2centity_t* old, int flags ) {
	vec3_t move;
	VectorCopy( start, move );
	vec3_t vec;
	VectorSubtract( end, start, vec );
	float len = VectorNormalize( vec );

	float dec = 0.5;
	VectorScale( vec, dec, vec );

	float orgscale;
	float velscale;
	if ( old->trailcount > 900 ) {
		orgscale = 4;
		velscale = 15;
	} else if ( old->trailcount > 800 ) {
		orgscale = 2;
		velscale = 10;
	} else {
		orgscale = 1;
		velscale = 5;
	}

	while ( len > 0 ) {
		len -= dec;

		// drop less particles as it flies
		if ( ( rand() & 1023 ) < old->trailcount ) {
			cparticle_t* p = CL_AllocParticle();
			if ( !p ) {
				return;
			}
			p->type = pt_q2static;
			VectorClear( p->accel );

			if ( flags & Q2EF_GIB ) {
				p->alpha = 1.0;
				p->alphavel = -1.0 / ( 1 + frand() * 0.4 );
				p->color = 0xe8 + ( rand() & 7 );
				for ( int j = 0; j < 3; j++ ) {
					p->org[ j ] = move[ j ] + crand() * orgscale;
					p->vel[ j ] = crand() * velscale;
					p->accel[ j ] = 0;
				}
				p->vel[ 2 ] -= PARTICLE_GRAVITY;
			} else if ( flags & Q2EF_GREENGIB ) {
				p->alpha = 1.0;
				p->alphavel = -1.0 / ( 1 + frand() * 0.4 );
				p->color = 0xdb + ( rand() & 7 );
				for ( int j = 0; j < 3; j++ ) {
					p->org[ j ] = move[ j ] + crand() * orgscale;
					p->vel[ j ] = crand() * velscale;
					p->accel[ j ] = 0;
				}
				p->vel[ 2 ] -= PARTICLE_GRAVITY;
			} else {
				p->alpha = 1.0;
				p->alphavel = -1.0 / ( 1 + frand() * 0.2 );
				p->color = 4 + ( rand() & 7 );
				for ( int j = 0; j < 3; j++ ) {
					p->org[ j ] = move[ j ] + crand() * orgscale;
					p->vel[ j ] = crand() * velscale;
				}
				p->accel[ 2 ] = 20;
			}
		}

		old->trailcount -= 5;
		if ( old->trailcount < 100 ) {
			old->trailcount = 100;
		}
		VectorAdd( move, vec, move );
	}
}
Пример #20
0
// ---------- main ----------
int
main ( int argc, char *argv[] )
{
  UserInput_t XLAL_INIT_DECL(uvar_s);
  UserInput_t *uvar = &uvar_s;

  uvar->randSeed = 1;
  uvar->Nruns = 1;
  uvar->inAlign = uvar->outAlign = sizeof(void*);
  // ---------- register user-variable ----------
  XLALRegisterUvarMember(  randSeed,            INT4, 's', OPTIONAL, "Random-number seed");
  XLALRegisterUvarMember(  Nruns,               INT4, 'r', OPTIONAL, "Number of repeated timing 'runs' to average over (=improves variance)" );
  XLALRegisterUvarMember(  inAlign,             INT4, 'a', OPTIONAL, "Alignment of input vectors; default is sizeof(void*), i.e. no particular alignment" );
  XLALRegisterUvarMember(  outAlign,            INT4, 'b', OPTIONAL, "Alignment of output vectors; default is sizeof(void*), i.e. no particular alignment" );

  BOOLEAN should_exit = 0;
  XLAL_CHECK( XLALUserVarReadAllInput( &should_exit, argc, argv, lalVCSInfoList ) == XLAL_SUCCESS, XLAL_EFUNC );
  if ( should_exit ) {
    exit (1);
  }

  srand ( uvar->randSeed );
  XLAL_CHECK ( uvar->Nruns >= 1, XLAL_EDOM );
  UINT4 Nruns = (UINT4)uvar->Nruns;

  UINT4 Ntrials = 1000000 + 7;
  REAL4VectorAligned *xIn_a, *xIn2_a, *xOut_a, *xOut2_a;
  XLAL_CHECK ( ( xIn_a   = XLALCreateREAL4VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( ( xIn2_a  = XLALCreateREAL4VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( ( xOut_a  = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( ( xOut2_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
  REAL4VectorAligned *xOutRef_a, *xOutRef2_a;
  XLAL_CHECK ( (xOutRef_a  = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( (xOutRef2_a = XLALCreateREAL4VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );

  // extract aligned REAL4 vectors from these
  REAL4 *xIn      = xIn_a->data;
  REAL4 *xIn2     = xIn2_a->data;
  REAL4 *xOut     = xOut_a->data;
  REAL4 *xOut2    = xOut2_a->data;
  REAL4 *xOutRef  = xOutRef_a->data;
  REAL4 *xOutRef2 = xOutRef2_a->data;

  UINT4Vector *xOutU4;
  UINT4Vector *xOutRefU4;
  XLAL_CHECK ( ( xOutU4 = XLALCreateUINT4Vector ( Ntrials )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( ( xOutRefU4 = XLALCreateUINT4Vector ( Ntrials )) != NULL, XLAL_EFUNC );

  REAL8VectorAligned *xInD_a, *xIn2D_a, *xOutD_a, *xOutRefD_a;
  XLAL_CHECK ( ( xInD_a   = XLALCreateREAL8VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( ( xIn2D_a  = XLALCreateREAL8VectorAligned ( Ntrials, uvar->inAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( ( xOutD_a  = XLALCreateREAL8VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );
  XLAL_CHECK ( (xOutRefD_a= XLALCreateREAL8VectorAligned ( Ntrials, uvar->outAlign )) != NULL, XLAL_EFUNC );

  // extract aligned REAL8 vectors from these
  REAL8 *xInD      = xInD_a->data;
  REAL8 *xIn2D     = xIn2D_a->data;
  REAL8 *xOutD     = xOutD_a->data;
  REAL8 *xOutRefD  = xOutRefD_a->data;


  REAL8 tic, toc;
  REAL4 maxErr = 0, maxRelerr = 0;
  REAL4 abstol, reltol;

  XLALPrintInfo ("Testing sin(x), cos(x) for x in [-1000, 1000]\n");
  for ( UINT4 i = 0; i < Ntrials; i ++ ) {
    xIn[i] = 2000 * ( frand() - 0.5 );
  }
  abstol = 2e-7, reltol = 1e-5;
  // ==================== SIN() ====================
  TESTBENCH_VECTORMATH_S2S(Sin,xIn);

  // ==================== COS() ====================
  TESTBENCH_VECTORMATH_S2S(Cos,xIn);

  // ==================== SINCOS() ====================
  TESTBENCH_VECTORMATH_S2SS(SinCos,xIn);

  // ==================== SINCOS(2PI*x) ====================
  TESTBENCH_VECTORMATH_S2SS(SinCos2Pi,xIn);

  // ==================== EXP() ====================
  XLALPrintInfo ("\nTesting exp(x) for x in [-10, 10]\n");
  for ( UINT4 i = 0; i < Ntrials; i ++ ) {
    xIn[i] = 20 * ( frand() - 0.5 );
  }

  abstol = 4e-3, reltol = 3e-7;
  TESTBENCH_VECTORMATH_S2S(Exp,xIn);

  // ==================== LOG() ====================
  XLALPrintInfo ("\nTesting log(x) for x in (0, 10000]\n");
  for ( UINT4 i = 0; i < Ntrials; i ++ ) {
    xIn[i] = 10000.0f * frand() + 1e-6;
  } // for i < Ntrials
  abstol = 2e-6, reltol = 2e-7;

  TESTBENCH_VECTORMATH_S2S(Log,xIn);

  // ==================== ADD,MUL ====================
  for ( UINT4 i = 0; i < Ntrials; i ++ ) {
    xIn[i]  = -10000.0f + 20000.0f * frand() + 1e-6;
    xIn2[i] = -10000.0f + 20000.0f * frand() + 1e-6;
    xInD[i] = -100000.0 + 200000.0 * frand() + 1e-6;
    xIn2D[i]= -100000.0 + 200000.0 * frand() + 1e-6;
  } // for i < Ntrials
  abstol = 2e-7, reltol = 2e-7;

  XLALPrintInfo ("\nTesting add,multiply,shift,scale(x,y) for x,y in (-10000, 10000]\n");
  TESTBENCH_VECTORMATH_SS2S(Add,xIn,xIn2);
  TESTBENCH_VECTORMATH_SS2S(Multiply,xIn,xIn2);
  TESTBENCH_VECTORMATH_SS2S(Max,xIn,xIn2);

  TESTBENCH_VECTORMATH_SS2S(Shift,xIn[0],xIn2);
  TESTBENCH_VECTORMATH_SS2S(Scale,xIn[0],xIn2);

  TESTBENCH_VECTORMATH_DD2D(Scale,xInD[0],xIn2D);

  // ==================== FIND ====================
  for ( UINT4 i = 0; i < Ntrials; i ++ ) {
    xIn[i]  = -10000.0f + 20000.0f * frand() + 1e-6;
    xIn2[i] = -10000.0f + 20000.0f * frand() + 1e-6;
  } // for i < Ntrials

  XLALPrintInfo ("\nTesting find for x,y in (-10000, 10000]\n");
  TESTBENCH_VECTORMATH_SS2uU(FindVectorLessEqual,xIn,xIn2);

  TESTBENCH_VECTORMATH_SS2uU(FindScalarLessEqual,xIn[0],xIn2);

  XLALPrintInfo ("\n");

  // ---------- clean up memory ----------
  XLALDestroyREAL4VectorAligned ( xIn_a );
  XLALDestroyREAL4VectorAligned ( xIn2_a );
  XLALDestroyREAL4VectorAligned ( xOut_a );
  XLALDestroyREAL4VectorAligned ( xOut2_a );

  XLALDestroyREAL4VectorAligned ( xOutRef_a );
  XLALDestroyREAL4VectorAligned ( xOutRef2_a );

  XLALDestroyUINT4Vector ( xOutU4 );
  XLALDestroyUINT4Vector ( xOutRefU4 );

  XLALDestroyREAL8VectorAligned ( xInD_a );
  XLALDestroyREAL8VectorAligned ( xIn2D_a );
  XLALDestroyREAL8VectorAligned ( xOutD_a );
  XLALDestroyREAL8VectorAligned ( xOutRefD_a );

  XLALDestroyUserVars();

  LALCheckMemoryLeaks();

  return XLAL_SUCCESS;

} // main()
Пример #21
0
void CLQ2_TrapParticles( vec3_t origin ) {
	origin[ 2 ] -= 14;
	vec3_t start;
	VectorCopy( origin, start );
	vec3_t end;
	VectorCopy( origin, end );
	origin[ 2 ] += 14;
	end[ 2 ] += 64;

	vec3_t move;
	VectorCopy( start, move );
	vec3_t vec;
	VectorSubtract( end, start, vec );
	float len = VectorNormalize( vec );

	int dec = 5;
	VectorScale( vec, 5, vec );

	// FIXME: this is a really silly way to have a loop
	while ( len > 0 ) {
		len -= dec;

		cparticle_t* p = CL_AllocParticle();
		if ( !p ) {
			return;
		}
		p->type = pt_q2static;
		VectorClear( p->accel );

		p->alpha = 1.0;
		p->alphavel = -1.0 / ( 0.3 + frand() * 0.2 );
		p->color = 0xe0;
		for ( int j = 0; j < 3; j++ ) {
			p->org[ j ] = move[ j ] + crand();
			p->vel[ j ] = crand() * 15;
			p->accel[ j ] = 0;
		}
		p->accel[ 2 ] = PARTICLE_GRAVITY;

		VectorAdd( move, vec, move );
	}

	vec3_t org;
	VectorCopy( origin, org );

	for ( int i = -2; i <= 2; i += 4 ) {
		for ( int j = -2; j <= 2; j += 4 ) {
			for ( int k = -2; k <= 2; k += 4 ) {
				cparticle_t* p = CL_AllocParticle();
				if ( !p ) {
					return;
				}
				p->type = pt_q2static;

				p->color = 0xe0 + ( rand() & 3 );

				p->alpha = 1.0;
				p->alphavel = -1.0 / ( 0.3 + ( rand() & 7 ) * 0.02 );

				p->org[ 0 ] = org[ 0 ] + i + ( ( rand() & 23 ) * crand() );
				p->org[ 1 ] = org[ 1 ] + j + ( ( rand() & 23 ) * crand() );
				p->org[ 2 ] = org[ 2 ] + k + ( ( rand() & 23 ) * crand() );

				vec3_t dir;
				dir[ 0 ] = j * 8;
				dir[ 1 ] = i * 8;
				dir[ 2 ] = k * 8;

				VectorNormalize( dir );
				float vel = 50 + ( rand() & 63 );
				VectorScale( dir, vel, p->vel );

				p->accel[ 0 ] = p->accel[ 1 ] = 0;
				p->accel[ 2 ] = -PARTICLE_GRAVITY;
			}
		}
	}
}
Пример #22
0
/* Start a new cluster of lines going.
   Pick their anim type, and in, mid, and out positions.
 */
static void
reset_lines (ModeInfo *mi)
{
  fliptext_configuration *sc = &scs[MI_SCREEN(mi)];
  int i;
  line *prev = 0;
  GLfloat minx, maxx, miny, maxy, minz, maxz, maxw, maxh;

  sc->rotation.x = 5 - BELLRAND(10);
  sc->rotation.y = 5 - BELLRAND(10);
  sc->rotation.z = 5 - BELLRAND(10);

  switch (random() % 8)
    {
    case 0:  sc->anim_type = SCROLL_TOP;    break;
    case 1:  sc->anim_type = SCROLL_BOTTOM; break;
    default: sc->anim_type = SPIN;          break;
    }

  minx = sc->left_margin  * 0.9;
  maxx = sc->right_margin * 0.9;

  miny = sc->bottom_margin * 0.9;
  maxy = sc->top_margin    * 0.9;

  minz = sc->left_margin  * 5;
  maxz = sc->right_margin * 2;

  maxw = sc->font_wrap_pixels * sc->font_scale;
  maxh = max_lines * sc->line_height * sc->font_scale;
 
  if (maxw > maxx - minx)
    maxw = maxx - minx;
  if (maxh > maxy - miny)
    maxh = maxy - miny;
      
  if (alignment_random_p)
    sc->alignment = (random() % 3) - 1;

  if      (sc->alignment == -1) maxx -= maxw;
  else if (sc->alignment ==  1) minx += maxw;
  else                          minx += maxw/2, maxx -= maxw/2;

  miny += maxh/2;
  maxy -= maxh/2;

  sc->mid.x = minx + frand (maxx - minx);
  if (sc->anim_type == SPIN)
    sc->mid.y = miny + BELLRAND (maxy - miny);
  else
    sc->mid.y = miny + frand (maxy - miny);

  sc->in.x  = BELLRAND(sc->right_margin * 2) - sc->right_margin;
  sc->out.x = BELLRAND(sc->right_margin * 2) - sc->right_margin;

  sc->in.y  = miny + frand(maxy - miny);
  sc->out.y = miny + frand(maxy - miny);

  sc->in.z  = minz + frand(maxz - minz);
  sc->out.z = minz + frand(maxz - minz);

  sc->mid.z = 0;

  if (sc->anim_type == SPIN && sc->in.z  > 0) sc->in.z  /= 4;
  if (sc->anim_type == SPIN && sc->out.z > 0) sc->out.z /= 4;

  for (i = 0; i < max_lines; i++)
    {
      line *line = make_line (sc, (i == 0));
      if (!line) break;			/* no text available */
      if (i >= min_lines &&
          (!line->text || !*line->text))	/* blank after min */
        break;
    }

  for (i = 0; i < sc->nlines; i++)
    {
      line *line = sc->lines[i];
      if (!prev)
        {
          line->from.y = sc->bottom_margin;
          line->to.y   = 0;
        }
      else
        {
          line->from.y = prev->from.y - prev->height;
          line->to.y   = prev->to.y   - prev->height;
        }
      line->cluster_pos = i;
      line->cluster_size = sc->nlines;
      prev = line;
    }
}
Пример #23
0
static void
animate_lava (ModeInfo *mi)
{
  lavalite_configuration *bp = &bps[MI_SCREEN(mi)];
  int wire = MI_IS_WIREFRAME(mi);
  Bool just_started_p = bp->just_started_p;

  double isolevel = 0.3;

  /* Maybe bubble a new blobby to the surface.
   */
  if (just_started_p ||
      frand(1.0) < bp->launch_chance)
    {
      bp->just_started_p = False;
      launch_balls (mi);

      if (do_impatient && just_started_p)
        while (1)
          {
            int i;
            move_balls (mi);
            for (i = 0; i < bp->nballs; i++)
              {
                metaball *b = &bp->balls[i];
                if (b->alive_p && !b->static_p && !b->leader &&
                    b->z > 0.5)
                  goto DONE;
              }
          }
      DONE: ;
    }

  move_balls (mi);

  glNewList (bp->ball_list, GL_COMPILE);
  glPushMatrix();

  glMaterialfv (GL_FRONT, GL_SPECULAR,            lava_spec);
  glMateriali  (GL_FRONT, GL_SHININESS,           lava_shininess);
  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, lava_color);

  /* For the blobbies, the origin is on the axis at the bottom of the
     glass bottle; and the top of the bottle is +1 on Z.
   */
  glTranslatef (0, 0, -0.5);

  mi->polygon_count = 0;
  {
    double s;
    if (bp->grid_size == 0) bp->grid_size = 1;  /* first time through */
    s = 1.0/bp->grid_size;

    glPushMatrix();
    glTranslatef (-0.5, -0.5, 0);
    glScalef (s, s, s);
    marching_cubes (resolution, isolevel, wire, do_smooth,
                    obj_init, obj_compute, obj_free, bp,
                    &mi->polygon_count);
    glPopMatrix();
  }

  mi->polygon_count += bp->bottle_poly_count;

  glPopMatrix();
  glEndList ();
}
Пример #24
0
void PetAI::MoveToVictim(Unit* pTarget)
{
    if (!pTarget)
        return;

    switch (m_AIType)
    {
        case PET_AI_PASSIVE:
        case PET_AI_SLACKER:
        case PET_AI_HEALER:
            m_creature->GetMotionMaster()->MoveTargetedHome();
            break;
        case PET_AI_RANGED:
            if (sWorld.getConfig(CONFIG_BOOL_PET_ADVANCED_AI))
                m_creature->GetMotionMaster()->MoveChase(pTarget, m_attackDistance, m_creature->GetAngle(pTarget) + frand(-M_PI_F/4.0f, M_PI_F/4.0f));
            else
                m_creature->GetMotionMaster()->MoveChase(pTarget);
            break;
        case PET_AI_MELEE:
        case PET_AI_RANGED_NOAMMO:
        default:
            m_creature->GetMotionMaster()->MoveChase(pTarget);
            break;
    }
    DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS,"PetAI::MoveToVictim pet %s move to %s, distance %f,  AI type %u",
        m_creature->GetObjectGuid().GetString().c_str(),pTarget ? pTarget->GetObjectGuid().GetString().c_str() : "<none>",m_attackDistance, m_AIType);
}
Пример #25
0
            void UpdateAI(uint32 diff) override
            {
                if (!UpdateVictim())
                    return;

                events.Update(diff);

                if (me->HasUnitState(UNIT_STATE_CASTING))
                    return;

                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_SHADOW_WORD_PAIN:
                            DoCastVictim(SPELL_SHADOW_WORD_PAIN, true);
                            events.ScheduleEvent(EVENT_SHADOW_WORD_PAIN, urand(5000, 7000), 0, PHASE_ONE);
                            break;
                        case EVENT_GOUGE:
                            DoCastVictim(SPELL_GOUGE, true);
                            break;
                        case EVENT_SUMMON_PROWLERS:
                            if (_summonCountA < MAX_PROWLERS_PER_SIDE)
                            {
                                if (Unit* trigger = ObjectAccessor::GetUnit(*me, _triggersSideAGUID[urand(0, 4)]))
                                {
                                    trigger->CastSpell(trigger, SPELL_SUMMON_PROWLER);
                                    ++_summonCountA;
                                }
                            }
                            if (_summonCountB < MAX_PROWLERS_PER_SIDE)
                            {
                                if (Unit* trigger = ObjectAccessor::GetUnit(*me, _triggersSideBGUID[urand(0, 4)]))
                                {
                                    trigger->CastSpell(trigger, SPELL_SUMMON_PROWLER);
                                    ++_summonCountB;
                                }
                            }
                            events.ScheduleEvent(EVENT_SUMMON_PROWLERS, 6000, 0, PHASE_ALL);
                            break;
                        case EVENT_MARK_OF_ARLOKK:
                        {
                            Unit* target = SelectTarget(SELECT_TARGET_TOPAGGRO, urand(1, 3), 0.0f, false, -SPELL_MARK_OF_ARLOKK);
                            if (!target)
                                target = me->GetVictim();
                            if (target)
                            {
                                DoCast(target, SPELL_MARK_OF_ARLOKK, true);
                                Talk(SAY_FEAST_PROWLER, target);
                            }
                            events.ScheduleEvent(EVENT_MARK_OF_ARLOKK, urand(120000, 130000));
                            break;
                        }
                        case EVENT_TRANSFORM:
                        {
                            DoCast(me, SPELL_PANTHER_TRANSFORM); // SPELL_AURA_TRANSFORM
                            me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, uint32(EQUIP_UNEQUIP));
                            me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, uint32(EQUIP_UNEQUIP));
                            /*
                            const CreatureTemplate* cinfo = me->GetCreatureTemplate();
                            me->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg +((cinfo->mindmg/100) * 35)));
                            me->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg +((cinfo->maxdmg/100) * 35)));
                            me->UpdateDamagePhysical(BASE_ATTACK);
                            */
                            me->AttackStop();
                            DoResetThreat();
                            me->SetReactState(REACT_PASSIVE);
                            me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE|UNIT_FLAG_NOT_SELECTABLE);
                            DoCast(me, SPELL_VANISH_VISUAL);
                            DoCast(me, SPELL_VANISH);
                            events.ScheduleEvent(EVENT_VANISH, 1000, 0, PHASE_ONE);
                            break;
                        }
                        case EVENT_VANISH:
                            DoCast(me, SPELL_SUPER_INVIS);
                            me->SetWalk(false);
                            me->GetMotionMaster()->MovePoint(0, frand(-11551.0f, -11508.0f), frand(-1638.0f, -1617.0f), me->GetPositionZ());
                            events.ScheduleEvent(EVENT_VANISH_2, 9000, 0, PHASE_ONE);
                            break;
                        case EVENT_VANISH_2:
                            DoCast(me, SPELL_VANISH);
                            DoCast(me, SPELL_SUPER_INVIS);
                            events.ScheduleEvent(EVENT_VISIBLE, urand(7000, 10000), 0, PHASE_ONE);
                            break;
                        case EVENT_VISIBLE:
                            me->SetReactState(REACT_AGGRESSIVE);
                            me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE|UNIT_FLAG_NOT_SELECTABLE);
                            if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
                                AttackStart(target);
                            me->RemoveAura(SPELL_SUPER_INVIS);
                            me->RemoveAura(SPELL_VANISH);
                            events.ScheduleEvent(EVENT_RAVAGE, urand(10000, 14000), 0, PHASE_TWO);
                            events.ScheduleEvent(EVENT_TRANSFORM_BACK, urand(15000, 18000), 0, PHASE_TWO);
                            events.SetPhase(PHASE_TWO);
                            me->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, 35.0f, true); // hack
                            break;
                        case EVENT_RAVAGE:
                            DoCastVictim(SPELL_RAVAGE, true);
                            events.ScheduleEvent(EVENT_RAVAGE, urand(10000, 14000), 0, PHASE_TWO);
                            break;
                        case EVENT_TRANSFORM_BACK:
                        {
                            me->RemoveAura(SPELL_PANTHER_TRANSFORM); // SPELL_AURA_TRANSFORM
                            DoCast(me, SPELL_VANISH_VISUAL);
                            me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, uint32(WEAPON_DAGGER));
                            me->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 1, uint32(WEAPON_DAGGER));
                            /*
                            const CreatureTemplate* cinfo = me->GetCreatureTemplate();
                            me->SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, (cinfo->mindmg));
                            me->SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, (cinfo->maxdmg));
                            me->UpdateDamagePhysical(BASE_ATTACK);
                            */
                            me->HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND, TOTAL_PCT, 35.0f, false); // hack
                            events.ScheduleEvent(EVENT_SHADOW_WORD_PAIN, urand(4000, 7000), 0, PHASE_ONE);
                            events.ScheduleEvent(EVENT_GOUGE, urand(12000, 15000), 0, PHASE_ONE);
                            events.ScheduleEvent(EVENT_TRANSFORM, urand(16000, 20000), 0, PHASE_ONE);
                            events.SetPhase(PHASE_ONE);
                            break;
                        }
                        default:
                            break;
                    }
                }

                DoMeleeAttackIfReady();
            }
Пример #26
0
ENTRYPOINT void init_jigglypuff(ModeInfo *mi)
{
    jigglystruct *js;
    int subdivs;

    if(!jss) {
	jss = (jigglystruct*)
	    calloc(MI_NUM_SCREENS(mi), sizeof(jigglystruct));
	if(!jss) {
	    fprintf(stderr, "%s: No..memory...must...abort..\n", progname);
	    exit(1);
	}
    }

    js = &jss[MI_SCREEN(mi)];

    js->do_wireframe = MI_IS_WIREFRAME(mi);
# ifdef HAVE_JWZGLES
    js->do_wireframe = 0; /* GL_LINE unimplemented */
# endif

    js->shininess = shininess;

    subdivs = (complexity==1) ? 4 : (complexity==2) ? 5
	: (complexity==3) ? 6 : 5;

    js->spooky = spooky << (subdivs-3);

    if(!parse_color(js)) {
	fprintf(stderr, "%s: Bad color specification: '%s'.\n", progname, color);
	exit(-1);
    }
    
    if(random_parms)
	randomize_parameters(js);

    js->angle = frand(180);
    js->axis  = frand(M_PI);

    js->shape = tesselated_tetrahedron(1, subdivs, js);

    if(!do_tetrahedron)
	solid_spherify(js->shape, 1);

    if(js->color_style == COLOR_STYLE_CLOWNBARF)
	clownbarf_colorize(js->shape);

    calculate_parameters(js, subdivs);

    if((js->glx_context = init_GL(mi)) != NULL) {
	glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
	setup_opengl(mi, js);
	reshape_jigglypuff(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    }
    else {
	MI_CLEARWINDOW(mi);
    }
    js->trackball = gltrackball_init();
/*    _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
	   js->stable_distance, js->hold_strength, js->spherify_strength,
	   js->damping_velocity, js->damping_factor);
    _DEBUG("wire : %d\nspooky : %d\nstyle : %d\nshininess : %d\n",
	   js->do_wireframe, js->spooky, js->color_style, js->shininess);*/
}
Пример #27
0
inline std::complex<double> crand(){
	return std::complex<double>(frand(),frand());
}
Пример #28
0
        void advanceAnimation()
        {
            float timeElapsed = gm->elapsedTime();
            float radius = max(1.0f, gm->screenWidth() / gm->screenHeight());

            if (touched)
            {
                if (touchedDist <= s.starLength * 2)
                    touchedDist += timeElapsed * s.speed;
            } else
                PHLowPassFilter(touchedDist, 0.0f, timeElapsed, 5);
            float ss = s.starLength + touchedDist;

            float distance = timeElapsed * s.speed * (ss / s.starLength);

            while (!points.empty())
            {
                point & p = points.front();
                if (p.z - ss < -NEAR_PLANE)
                    break;
                points.pop_front();
            }

            bool reshape = touchedDist > 0.05;
            offset += distance;
            distanceLeft -= distance;
            while (distanceLeft <= 0)
            {
                for (int i = 0; i < chunk; i ++)
                {
                    point p;
                    p.z = -FAR_PLANE - distanceLeft - offset;
                    float r = frand(0.5f, 2.0f) * radius;
                    float angle = frand(0.0f, M_PI * 2.0f);
                    p.up = PHPoint(r, s.starWidth).rotated(angle);
                    p.down = PHPoint(r, -s.starWidth).rotated(angle);
                    distanceLeft += frand(0.5f, 1.0f) * starSpread;
                    points.push_back(p);
                }
                reshape = true;
            }


            if (reshape)
            {
                size_t n = points.size();
                if (!n)
                {
                    vao->disableDrawing();
                    return;
                }
                size_t vertices = n * 4;
                GLfloat * v = new GLfloat[vertices * 5];
                GLfloat * p = v;
                for (list<point>::iterator i = points.begin(); i != points.end(); i++)
                {
                    point & pt = *i;
                    pt.z += offset;

                    p[0] = pt.up.x;
                    p[1] = pt.up.y;
                    p[2] = pt.z;
                    p[3] = 0.0f;
                    p[4] = 0.0f;

                    p[5] = pt.down.x;
                    p[6] = pt.down.y;
                    p[7] = pt.z;
                    p[8] = 0.0f;
                    p[9] = 1.0f;

                    p[10] = pt.up.x;
                    p[11] = pt.up.y;
                    p[12] = pt.z - ss;
                    p[13] = 1.0f;
                    p[14] = 0.0f;

                    p[15] = pt.down.x;
                    p[16] = pt.down.y;
                    p[17] = pt.z - ss;
                    p[18] = 1.0f;
                    p[19] = 1.0f;

                    //PHLog("%f %f %f %f  %f %f", pt.up.x, pt.up.y, pt.down.x, pt.down.y, pt.z, pt.z - s.starLength);

                    p+= 20;
                }
                offset = 0.0f;

                PHGLCheckError();
                vbo->setDataOptimally(v, vertices * 5 * sizeof(GLfloat), PHGLVBO::dynamicDraw);
                delete[] v;

                elements->resize(n, vao);
            }

            PHVector3 pos = _body->position();
            pos.z = offset;
            _body->setPosition(pos);
        }
Пример #29
0
bool EffectDummyCreature_spell_dummy_npc(Unit* pCaster, uint32 uiSpellId, SpellEffectIndex uiEffIndex, Creature* pCreatureTarget, ObjectGuid /*originalCasterGuid*/)
{
    switch (uiSpellId)
    {
        case SPELL_ADMINISTER_ANTIDOTE:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCreatureTarget->GetEntry() != NPC_HELBOAR)
                    return true;

                // possible needs check for quest state, to not have any effect when quest really complete

                pCreatureTarget->UpdateEntry(NPC_DREADTUSK);
                return true;
            }
            return true;
        }
        case SPELL_APPLY_SALVE:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCaster->GetTypeId() != TYPEID_PLAYER)
                    return true;

                if (pCreatureTarget->GetEntry() != NPC_SICKLY_DEER && pCreatureTarget->GetEntry() != NPC_SICKLY_GAZELLE)
                    return true;

                // Update entry, remove aura, set the kill credit and despawn
                uint32 uiUpdateEntry = pCreatureTarget->GetEntry() == NPC_SICKLY_DEER ? NPC_CURED_DEER : NPC_CURED_GAZELLE;
                pCreatureTarget->RemoveAurasDueToSpell(SPELL_SICKLY_AURA);
                pCreatureTarget->UpdateEntry(uiUpdateEntry);
                ((Player*)pCaster)->KilledMonsterCredit(uiUpdateEntry);
                pCreatureTarget->ForcedDespawn(20000);

                return true;
            }
            return true;
        }
        case SPELL_INOCULATE_OWLKIN:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCreatureTarget->GetEntry() != NPC_OWLKIN)
                    return true;

                pCreatureTarget->UpdateEntry(NPC_OWLKIN_INOC);
                ((Player*)pCaster)->KilledMonsterCredit(NPC_OWLKIN_INOC);

                // set despawn timer, since we want to remove creature after a short time
                pCreatureTarget->ForcedDespawn(15000);

                return true;
            }
            return true;
        }
        case SPELL_FEL_SIPHON_DUMMY:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCreatureTarget->GetEntry() != NPC_FELBLOOD_INITIATE)
                    return true;

                pCreatureTarget->UpdateEntry(NPC_EMACIATED_FELBLOOD);
                return true;
            }
            return true;
        }
        case SPELL_SACRED_CLEANSING:
        {
            if (uiEffIndex == EFFECT_INDEX_1)
            {
                if (pCreatureTarget->GetEntry() != NPC_MORBENT)
                    return true;

                pCreatureTarget->UpdateEntry(NPC_WEAKENED_MORBENT);
                return true;
            }
            return true;
        }
        case SPELL_TAG_MURLOC_PROC:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCreatureTarget->GetEntry() == NPC_BLACKSILT_MURLOC)
                    pCreatureTarget->UpdateEntry(NPC_TAGGED_MURLOC);
            }
            return true;
        }
        case SPELL_ORB_OF_MURLOC_CONTROL:
        {
            pCreatureTarget->CastSpell(pCaster, SPELL_GREENGILL_SLAVE_FREED, true);

            // Freed Greengill Slave
            pCreatureTarget->UpdateEntry(NPC_FREED_GREENGILL_SLAVE);

            pCreatureTarget->CastSpell(pCreatureTarget, SPELL_ENRAGE, true);

            return true;
        }
        case SPELL_FUMPING:
        {
            if (uiEffIndex == EFFECT_INDEX_2)
            {
                switch (urand(0, 2))
                {
                    case 0:
                    {
                        pCaster->CastSpell(pCreatureTarget, SPELL_SUMMON_HAISHULUD, true);
                        break;
                    }
                    case 1:
                    {
                        for (int i = 0; i < 2; ++i)
                        {
                            if (Creature* pSandGnome = pCaster->SummonCreature(NPC_SAND_GNOME, pCreatureTarget->GetPositionX(), pCreatureTarget->GetPositionY(), pCreatureTarget->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_OOC_DESPAWN, 30000))
                                pSandGnome->AI()->AttackStart(pCaster);
                        }
                        break;
                    }
                    case 2:
                    {
                        for (int i = 0; i < 2; ++i)
                        {
                            if (Creature* pMatureBoneSifter = pCaster->SummonCreature(NPC_MATURE_BONE_SIFTER, pCreatureTarget->GetPositionX(), pCreatureTarget->GetPositionY(), pCreatureTarget->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_OOC_DESPAWN, 30000))
                                pMatureBoneSifter->AI()->AttackStart(pCaster);
                        }
                        break;
                    }
                }
                pCreatureTarget->ForcedDespawn();
            }
            return true;
        }
        case SPELL_THROW_GORDAWG_BOULDER:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                for (int i = 0; i < 3; ++i)
                {
                    if (irand(i, 2))                        // 2-3 summons
                        pCreatureTarget->SummonCreature(NPC_MINION_OF_GUROK, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_CORPSE_DESPAWN, 5000);
                }

                if (pCreatureTarget->getVictim())
                {
                    pCaster->DealDamage(pCreatureTarget, pCreatureTarget->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
                    return true;
                }

                // If not in combat, no xp or loot
                pCreatureTarget->SetDeathState(JUST_DIED);
                pCreatureTarget->SetHealth(0);
                return true;
            }
            return true;
        }
        case SPELL_EXPOSE_RAZORTHORN_ROOT:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCreatureTarget->GetEntry() != NPC_RAZORTHORN_RAVAGER)
                    return true;

                if (GameObject* pMound = GetClosestGameObjectWithEntry(pCreatureTarget, GO_RAZORTHORN_DIRT_MOUND, 20.0f))
                {
                    if (pMound->GetRespawnTime() != 0)
                        return true;

                    pCreatureTarget->CastSpell(pCreatureTarget, SPELL_SUMMON_RAZORTHORN_ROOT, true);
                    pMound->SetLootState(GO_JUST_DEACTIVATED);
                }
            }
            return true;
        }
        case SPELL_MELODIOUS_RAPTURE:
        {
            if (uiEffIndex == EFFECT_INDEX_0)
            {
                if (pCaster->GetTypeId() != TYPEID_PLAYER && pCreatureTarget->GetEntry() != NPC_DEEPRUN_RAT)
                    return true;

                pCreatureTarget->UpdateEntry(NPC_ENTHRALLED_DEEPRUN_RAT);
                pCreatureTarget->CastSpell(pCreatureTarget, SPELL_MELODIOUS_RAPTURE_VISUAL, false);
                pCreatureTarget->GetMotionMaster()->MoveFollow(pCaster, frand(0.5f, 3.0f), frand(M_PI_F * 0.8f, M_PI_F * 1.2f));

                ((Player*)pCaster)->KilledMonsterCredit(NPC_ENTHRALLED_DEEPRUN_RAT);
            }
            return true;
        }
    }

    return false;
}
Пример #30
0
void FluidEmitter::tick(QList<Particle *> *estimates, double secs) {
    for(int i = m_fs->ps.size()-1; i >= 0; i--) {
        Particle *p = estimates->at(m_fs->ps.at(i));
            //            std::cout << p << std::endl;
//            double lambda = m_fs->lambdas[i];
            //            std::cout << lambda << std::endl;
        //            if(lambda >= -.1 && glm::length(p->v) < .05 && glm::length(p->p - p->ep) < .05) {
        //            if(p->p.y >= 10 || fabs(p->p.x) >= 10 ) {
        if(glm::length(p->v) < .06 && p->p.y <= 5) {
            if(m_fs->lambdas[i] <= 0) {
                p->t -= 1;
                if(p->t <= 0) {
                    p->t = 0;

                    //                p->ph = SOLID;
                    //                Particle *newP = new Particle(p->p, 0, SOLID);
                    //                newP->v = p->v;
                    //            p->imass -= secs;
                    //            if(p->imass == 0)

                    p->imass = 0;
                    p->ph = SOLID;
                    p->ep = p->p;
                    p->v = glm::dvec2();
                    p->f = glm::dvec2();
                    //                grains.append(newP);
                    //                estimates->append(newP);
                    //                estimates->removeAt(m_fs->ps.at(i));
                    //                if(m_fs->ps.contains(i))
                    m_fs->removeParticle(i);
                    //                delete p;
                    //                p->imass = 1;
                    //                p->ph = SOLID;
                    //                m_fs->ps.removeAt(i);
                }
            } else {
                p->t += secs;
                if(p->t > 3) p->t = 3;
            }
            //        }
        }
    }


    //    for(int i=0; i<grains.size(); i++) {
    //        Particle *p = grains.at(i);
//        if(glm::length(p->v) <= .02) {
//            grains.removeAt(i);
//            p->imass = 0;
//            p->v = glm::dvec2();
//            p->f = glm::dvec2();
//            p->ep = p->p;
//        }
//    }

    timer += secs;
    totalTimer += secs;
    while(totalTimer < 5 && timer >= 1./m_particlesPerSec) {
        timer -= 1./m_particlesPerSec;
        if(m_fs != NULL) {
            Particle *p = new Particle(m_posn, 1, FLUID);
            p->v = glm::dvec2(frand(),1);
            m_fs->addParticle(estimates->size());
            estimates->append(p);
        }
    }
}