Exemple #1
0
// effectue le tour de jeu de l'oya selon le fonctionnement de l'IA
t_action IA_effectuerTour(t_jeu *jeu) {
    // action choisie au hasard...
    t_action action = {randN(jeu->nbCaseX), randN(3)+1};
    while(!t_jeu_oyaPossedePiece(jeu, action.typePiece)) {
        action.typePiece++;
        if(action.typePiece > 3)
            action.typePiece = 1;
    }
    return action;
}
Exemple #2
0
inline int CParticle::ChangeDir (int d)
{
	int	h = d;

if (h)
	h = h / 2 - randN (h);
return (d * 10 + h) / 10;
}
void test(Pooma::Tester &t, int numElements)
{  
  std::vector<int> v;
  std::map<int, int> m;
  
  int i;
  for (i = 0; i < numElements; i++)
    {
      int e = randN(numElements);
      v.push_back(e);
      std::map<int, int>::iterator ei = m.find(e);
      if (ei != m.end())
        (*ei).second += 1;
      else
        m[e] = 1;
    }
  
  std::sort(v.begin(), v.end());
  for (i = 0; i < numElements; i++)
    t.out() << v[i] << " ";
  t.out() << std::endl;
      
  std::vector<int>::iterator mc = 
    Pooma::Algorithms::find_most_common(v.begin(), v.end());

  if (numElements == 0)
    t.check ("zero length", mc == v.end());
  else
    {  
      int cmc, nmc = -1;
      std::map<int, int>::const_iterator j = m.begin();
      while (j != m.end())
        {
          if ((*j).second > nmc)
            {
              nmc = (*j).second;
              cmc = (*j).first;
            }
          t.out() << (*j).first << ":" << (*j).second << " ";
          ++j;
        }
  
      t.out() << std::endl;  
      t.check("most common", *mc, cmc);
    }
}
Exemple #4
0
int CParticle::Create (CFixVector *vPos, CFixVector *vDir, CFixMatrix *mOrient,
							  short nSegment, int nLife, int nSpeed, char nParticleSystemType, char nClass,
						     float nScale, tRgbaColorf *colorP, int nCurTime, int bBlowUp,
							  float fBrightness, CFixVector *vEmittingFace)
{

	static tRgbaColorf	defaultColor = {1,1,1,1};

	tRgbaColorf	color;
	CFixVector	vDrift;
	int			nRad, nFrames, nType = particleImageManager.GetType (nParticleSystemType);

if (nScale < 0)
	nRad = (int) -nScale;
else if (gameOpts->render.particles.bSyncSizes)
	nRad = (int) PARTICLE_SIZE (gameOpts->render.particles.nSize [0], nScale);
else
	nRad = (int) nScale;
if (!nRad)
	nRad = I2X (1);
m_nType = nType;
m_bEmissive = (nParticleSystemType == LIGHT_PARTICLES);
m_nClass = nClass;
m_nSegment = nSegment;
m_nBounce = 0;
color = colorP ? *colorP : defaultColor;
m_color [0] =
m_color [1] = color;
if ((nType == BULLET_PARTICLES) || (nType == BUBBLE_PARTICLES)) {
	m_bBright = 0;
	m_nFade = -1;
	}
else {
	m_bBright = (nType == SMOKE_PARTICLES) ? (rand () % 50) == 0 : 0;
	if (colorP) {
		if (nType != LIGHT_PARTICLES) {
			m_color [0].red *= RANDOM_FADE;
			m_color [0].green *= RANDOM_FADE;
			m_color [0].blue *= RANDOM_FADE;
			}
		m_nFade = 0;
		}
	else {
		m_color [0].red = 1.0f;
		m_color [0].green = 0.5f;
		m_color [0].blue = 0.0f;
		m_nFade = 2;
		}
	if (m_bEmissive)
		m_color [0].alpha = (float) (SMOKE_START_ALPHA + 64) / 255.0f;
	else if (nParticleSystemType != GATLING_PARTICLES) {
		if (!colorP)
			m_color [0].alpha = (float) (SMOKE_START_ALPHA + randN (64)) / 255.0f;
		else {
			if (colorP->alpha < 0)
				m_color [0].alpha = -colorP->alpha;
			else {
				if (2 == (m_nFade = (char) colorP->alpha)) {
					m_color [0].red = 1.0f;
					m_color [0].green = 0.5f;
					m_color [0].blue = 0.0f;
					}
				m_color [0].alpha = (float) (SMOKE_START_ALPHA + randN (64)) / 255.0f;
				}
			}
		}
#if 1
	if (gameOpts->render.particles.bDisperse && !m_bBright) {
		fBrightness = 1.0f - fBrightness;
		m_color [0].alpha += fBrightness * fBrightness / 8.0f;
		}
#endif
	}
//nSpeed = (int) (sqrt (nSpeed) * (float) I2X (1));
nSpeed *= I2X (1);
if (vDir) {
	CAngleVector	a;
	CFixMatrix		m;
	float				d;
	a [PA] = randN (I2X (1) / 4) - I2X (1) / 8;
	a [BA] = randN (I2X (1) / 4) - I2X (1) / 8;
	a [HA] = randN (I2X (1) / 4) - I2X (1) / 8;
	m = CFixMatrix::Create (a);
	vDrift = m * (*vDir);
	CFixVector::Normalize (vDrift);
	d = (float) CFixVector::DeltaAngle (vDrift, *vDir, NULL);
	if (d) {
		d = (float) exp ((I2X (1) / 8) / d);
		nSpeed = (fix) ((float) nSpeed / d);
		}
#if 0
	if (!colorP)	// hack for static particleSystem w/o user defined color
		m_color [0].green =
		m_color [0].blue = 1.0f;
#endif
	vDrift *= nSpeed;
	if ((nType == SMOKE_PARTICLES) || (nType == BUBBLE_PARTICLES))
		m_vDir = *vDir * (I2X (3) / 4 + I2X (randN (16)) / 64);
	else
		m_vDir = *vDir;
	m_bHaveDir = 1;
	}
else {
	CFixVector	vOffs;
	vDrift [X] = nSpeed - randN (2 * nSpeed);
	vDrift [Y] = nSpeed - randN (2 * nSpeed);
	vDrift [Z] = nSpeed - randN (2 * nSpeed);
	vOffs = vDrift;
	m_vDir.SetZero ();
	m_bHaveDir = 1;
	}
m_vDrift = vDrift;
if (vEmittingFace)
	m_vPos = *RandomPointOnQuad (vEmittingFace, vPos);
else if (nType != BUBBLE_PARTICLES)
	m_vPos = *vPos + vDrift * (I2X (1) / 64);
else {
	//m_vPos = *vPos + vDrift * (I2X (1) / 32);
	nSpeed = vDrift.Mag () / 16;
	vDrift = CFixVector::Avg ((*mOrient).RVec () * (nSpeed - randN (2 * nSpeed)), (*mOrient).UVec () * (nSpeed - randN (2 * nSpeed)));
	m_vPos = *vPos + vDrift + (*mOrient).FVec () * (I2X (1) / 2 - randN (I2X (1)));
#if 1
	m_vDrift.SetZero ();
#else
	CFixVector::Normalize (m_vDrift);
	m_vDrift *= I2X (32);
#endif
	}
if ((nType != BUBBLE_PARTICLES) && mOrient) {
		CAngleVector	vRot;
		CFixMatrix		mRot;

	vRot [BA] = 0;
	vRot [PA] = 2048 - ((d_rand () % 9) * 512);
	vRot [HA] = 2048 - ((d_rand () % 9) * 512);
	mRot = CFixMatrix::Create (vRot);
	m_mOrient = *mOrient * mRot;
	}
if (nLife < 0)
	nLife = -nLife;
if (nType == SMOKE_PARTICLES) {
	if (gameOpts->render.particles.bDisperse)
		nLife = (nLife * 2) / 3;
	nLife = nLife / 2 + randN (nLife / 2);
	}
m_nLife =
m_nTTL = nLife;
m_nMoved = nCurTime;
m_nDelay = 0; //bStart ? randN (nLife) : 0;
if (nType == SMOKE_PARTICLES)
	nRad += randN (nRad);
else if (nType == BUBBLE_PARTICLES)
	nRad = nRad / 10 + randN (9 * nRad / 10);
else
	nRad *= 2;
if ((m_bBlowUp = bBlowUp)) {
	m_nRad = nRad / 2;
	m_nWidth =
	m_nHeight = m_nRad;
	m_nRad += m_nRad / bBlowUp;
	}
else {
	m_nWidth =
	m_nHeight = nRad;
	m_nRad = nRad / 2;
	}
nFrames = nParticleFrames [0][nType];
if (nType == BULLET_PARTICLES) {
	m_nFrame = 0;
	m_nRotFrame = 0;
	m_nOrient = 3;
	}
else if (nType == BUBBLE_PARTICLES) {
	m_nFrame = rand () % (nFrames * nFrames);
	m_nRotFrame = 0;
	m_nOrient = 0;
	}
else if (nType == LIGHT_PARTICLES) {
	m_nFrame = 0;
	m_nRotFrame = 0;
	m_nOrient = 0;
	}
else {
	m_nFrame = rand () % (nFrames * nFrames);
	m_nRotFrame = m_nFrame / 2;
	m_nOrient = rand () % 4;
	}
#if 1
if (m_bEmissive)
	m_color [0].alpha *= ParticleBrightness (colorP);
else if (nParticleSystemType == SMOKE_PARTICLES)
	m_color [0].alpha /= colorP ? color.red + color.green + color.blue + 2 : 2;
else if (nParticleSystemType == BUBBLE_PARTICLES)
	m_color [0].alpha /= 2;
else if (nParticleSystemType == LIGHT_PARTICLES)
	m_color [0].alpha /= 5;
#	if 0
else if (nParticleSystemType == GATLING_PARTICLES)
	;//m_color [0].alpha /= 6;
#	endif
#endif
return 1;
}
int CParticle::Update (int nCurTime, float fBrightness, int nThread)
{
    if ((m_nLife <= 0) /*|| (m_color [0].alpha < 0.01f)*/)
        return 0;

    fix t = nCurTime - m_nMoved;
    m_nMoved = nCurTime;

#if !ENABLE_UPDATE
    m_nLife -= t;
    m_decay = ((m_nType == BUBBLE_PARTICLES) || (m_nType == WATERFALL_PARTICLES)) ? 1.0f : float (m_nLife) / float (m_nTTL);
#else
    UpdateColor (fBrightness, nThread);

    if (m_nDelay > 0) {
        m_nDelay -= t;
        return 1;
    }

    if (!UpdateDrift (t, nThread))
        return 0;

    if (m_nTTL < 0)
        return 1;

#if SMOKE_SLOWMO
    m_nLife -= (int) (t / gameStates.gameplay.slowmo [0].fSpeed);
#else
    m_nLife -= t;
#	if 0
    if ((m_nType == FIRE_PARTICLES) && !m_bReversed && (m_nLife <= m_nTTL / 4 + randN (m_nTTL / 4))) {
        m_vDrift = -m_vDrift;
        m_bReversed = 1;
    }
#	endif
#	if DBG
    if ((m_nLife <= 0) && (m_nType == 2))
        m_nLife = -1;
#	endif
#endif
    if (m_nLife < 0)
        m_nLife = 0;
    UpdateDecay ();

    if ((m_nType <= SMOKE_PARTICLES) && (m_nRad > 0)) {
        if (m_bBlowUp) {
            if (m_nWidth >= m_nRad)
                m_nRad = 0;
            else {
                m_nWidth += m_nRad * 0.1f;
                if (m_nWidth > m_nRad)
                    m_nWidth = m_nRad;
                m_nHeight += m_nRad * 0.1f;
                if (m_nHeight > m_nRad)
                    m_nHeight = m_nRad;
                m_color [0].alpha *= (1.0f + 0.0725f / m_bBlowUp);
                if (m_color [0].alpha > 1)
                    m_color [0].alpha = 1;
            }
        }
        else {
            if (m_nWidth <= m_nRad)
                m_nRad = 0;
            else {
                m_nRad *= 1.2f;
                m_color [0].alpha *= 1.0725f;
                if (m_color [0].alpha > 1)
                    m_color [0].alpha = 1;
            }
        }
    }
#endif
    return 1;
}
int CParticle::Create (CFixVector *vPos, CFixVector *vDir, CFixMatrix *mOrient,
                       short nSegment, int nLife, int nSpeed, char nParticleSystemType, char nClass,
                       float nScale, tRgbaColorf *colorP, int nCurTime, int bBlowUp, char nFadeType,
                       float fBrightness, CFixVector *vEmittingFace)
{

    tRgbaColorf	color;
    int			nType = particleImageManager.GetType (nParticleSystemType);

    m_bChecked = 0;
    m_bBlowUp = bBlowUp && gameOpts->render.particles.bDisperse;
    if (nScale < 0)
        m_nRad = float (-nScale);
    else if (gameOpts->render.particles.bSyncSizes)
        m_nRad = float (PARTICLE_SIZE (gameOpts->render.particles.nSize [0], nScale, m_bBlowUp));
    else
        m_nRad = float (nScale);
    if (!m_nRad)
        m_nRad = 1.0f;
    m_nType = nType;
    m_bEmissive = (nParticleSystemType == LIGHT_PARTICLES) ? 1 : (nParticleSystemType == FIRE_PARTICLES) ? 2 : 0;
    m_nClass = nClass;
    m_nFadeType = nFadeType;
    m_nSegment = nSegment;
    m_nBounce = ((m_nType == BUBBLE_PARTICLES) || (m_nType == WATERFALL_PARTICLES)) ? 1 : 2;
    m_bReversed = 0;
    m_nMoved = nCurTime;
    if (nLife < 0)
        nLife = -nLife;
    m_nLife = nLife;
    m_nDelay = 0; //bStart ? randN (nLife) : 0;

    m_color [0] =
        m_color [1] =
            color = (colorP && (m_bEmissive < 2)) ? *colorP : defaultParticleColor;

    if ((nType == BULLET_PARTICLES) || (nType == BUBBLE_PARTICLES)) {
        m_bBright = 0;
        m_nFadeState = -1;
    }
    else {
        m_bBright = (nType <= SMOKE_PARTICLES) ? (rand () % 50) == 0 : 0;
        if (colorP) {
            if (!m_bEmissive) {
                m_color [0].red *= RANDOM_FADE;
                m_color [0].green *= RANDOM_FADE;
                m_color [0].blue *= RANDOM_FADE;
            }
            m_nFadeState = 0;
        }
        else {
            m_color [0].red = 1.0f;
            m_color [0].green = 0.5f;
            m_color [0].blue = 0.0f;
            m_nFadeState = 2;
        }
        if (m_bEmissive)
            m_color [0].alpha = float (SMOKE_START_ALPHA + 64) / 255.0f;
        else if (nParticleSystemType != GATLING_PARTICLES) {
            if (!colorP)
                m_color [0].alpha = float (3 * SMOKE_START_ALPHA / 4 + randN (SMOKE_START_ALPHA / 2)) / 255.0f;
            else {
                if (colorP->alpha < 0) {
                    ubyte a = ubyte (-colorP->alpha * 255.0f * 0.25f + 0.5f);
                    m_color [0].alpha = float (3 * a + randN (2 * a)) / 255.0f;
                }
                else {
                    if (2 == (m_nFadeState = char (colorP->alpha))) {
                        m_color [0].red = 1.0f;
                        m_color [0].green = 0.5f;
                        m_color [0].blue = 0.0f;
                    }
                    m_color [0].alpha = float (3 * SMOKE_START_ALPHA / 4 + randN (SMOKE_START_ALPHA / 2)) / 255.0f;
                }
            }
            if (m_bBlowUp && !m_bBright) {
                fBrightness = 1.0f - fBrightness;
                m_color [0].alpha += fBrightness * fBrightness / 8.0f;
            }
        }
    }
#if 0
    if (nType == FIRE_PARTICLES)
        nSpeed = int (sqrt (double (nSpeed)) * float (I2X (1)));
    else
#endif
        nSpeed *= I2X (1);
    if (!vDir) {
        m_vDrift [X] = nSpeed - randN (2 * nSpeed);
        m_vDrift [Y] = nSpeed - randN (2 * nSpeed);
        m_vDrift [Z] = nSpeed - randN (2 * nSpeed);
        m_vDir.SetZero ();
        m_bHaveDir = 1;
    }
    else {
        m_vDir = *vDir;

        CAngleVector	a;
        CFixMatrix		m;
        a [PA] = randN (I2X (1) / 4) - I2X (1) / 8;
        a [BA] = randN (I2X (1) / 4) - I2X (1) / 8;
        a [HA] = randN (I2X (1) / 4) - I2X (1) / 8;
        m = CFixMatrix::Create (a);
        if (nType == WATERFALL_PARTICLES)
            CFixVector::Normalize (m_vDir);
        m_vDrift = m * m_vDir;
        CFixVector::Normalize (m_vDrift);
        if (nType == WATERFALL_PARTICLES) {
            fix dot = CFixVector::Dot (m_vDir, m_vDrift);
            if (dot < I2X (1) / 2)
                return 0;
        }
        float d = float (CFixVector::DeltaAngle (m_vDrift, m_vDir, NULL));
        if (d) {
            d = (float) exp ((I2X (1) / 8) / d);
            nSpeed = (fix) ((float) nSpeed / d);
        }
        m_vDrift *= nSpeed;
        if (nType <= FIRE_PARTICLES)
            m_vDir *= (I2X (3) / 4 + I2X (randN (16)) / 64);
#if DBG
        if (CFixVector::Dot (m_vDrift, m_vDir) < 0)
            d = 0;
#endif
        m_bHaveDir = 1;
    }

    if (vEmittingFace)
        m_vPos = *RandomPointOnQuad (vEmittingFace, vPos);
    else if (nType != BUBBLE_PARTICLES)
        m_vPos = *vPos + m_vDrift * (I2X (1) / 64);
    else {
        //m_vPos = *vPos + vDrift * (I2X (1) / 32);
        nSpeed = m_vDrift.Mag () / 16;
        CFixVector v = CFixVector::Avg ((*mOrient).RVec () * (nSpeed - randN (2 * nSpeed)), (*mOrient).UVec () * (nSpeed - randN (2 * nSpeed)));
        m_vPos = *vPos + v + (*mOrient).FVec () * (I2X (1) / 2 - randN (I2X (1)));
    }

    if ((nType != BUBBLE_PARTICLES) && mOrient) {
        CAngleVector	vRot;
        CFixMatrix		mRot;

        vRot [BA] = 0;
        vRot [PA] = 2048 - ((d_rand () % 9) * 512);
        vRot [HA] = 2048 - ((d_rand () % 9) * 512);
        mRot = CFixMatrix::Create (vRot);
        m_mOrient = *mOrient * mRot;
    }

    if (nType <= SMOKE_PARTICLES) {
        if (m_bBlowUp)
            m_nLife = 2 * m_nLife / 3;
        m_nLife = 4 * m_nLife / 5 + randN (2 * m_nLife / 5);
        m_nRad += float (randN (int (m_nRad)));
    }
    else if (nType == FIRE_PARTICLES) {
        m_nLife = 3 * m_nLife / 4 + randN (m_nLife / 4);
        m_nRad += float (randN (int (m_nRad)));
    }
    else if (nType == BUBBLE_PARTICLES)
        m_nRad = m_nRad / 10 + float (randN (int (9 * m_nRad / 10)));
    else
        m_nRad *= 2;

//m_nRad *= 0.5f;
    m_vStartPos = m_vPos;

    if (m_bBlowUp) {
        m_nWidth = (nType == WATERFALL_PARTICLES) ? m_nRad * 0.6666667f : m_nRad;
        m_nHeight = m_nRad;
    }
    else {
        m_nWidth = (nType == WATERFALL_PARTICLES) ? m_nRad * 0.3333333f : m_nRad * 2;
        m_nHeight = m_nRad * 2;
    }
    m_nWidth /= 65536.0f;
    m_nHeight /= 65536.0f;
    m_nRad /= 65536.0f;

    m_nFrames = ParticleImageInfo (nType).nFrames;
    m_deltaUV = 1.0f / float (m_nFrames);
    if (nType == BULLET_PARTICLES) {
        m_iFrame = 0;
        m_nRotFrame = 0;
        m_nOrient = 3;
    }
    else if (nType == BUBBLE_PARTICLES) {
        m_iFrame = rand () % (m_nFrames * m_nFrames);
        m_nRotFrame = 0;
        m_nOrient = 0;
    }
    else if ((nType == LIGHT_PARTICLES) /*|| (nType == WATERFALL_PARTICLES)*/) {
        m_iFrame = 0;
        m_nRotFrame = 0;
        m_nOrient = 0;
    }
    else if (nType == FIRE_PARTICLES) {
        m_iFrame = (rand () % 10 < 6) ? 0 : 2;	// more fire than smoke (60:40)
        if (m_iFrame < 2)
            m_nLife  = 9 * m_nLife / 10;
        else
            m_nLife  = 10 * m_nLife / 9;
        m_nRotFrame = rand () % PARTICLE_POSITIONS;
        m_nOrient = rand () % 4;
    }
    else {
        m_iFrame = rand () % (m_nFrames * m_nFrames);
        m_nRotFrame = rand () % PARTICLE_POSITIONS;
        m_nOrient = rand () % 4;
#if 1
#endif
    }
    m_nTTL = m_nLife;

    m_nRenderType = RenderType ();
    m_bAnimate = (nType != FIRE_PARTICLES) && (gameOpts->render.particles.nQuality > 1) && (m_nFrames > 1);
    m_bRotate = (m_nRenderType <= SMOKE_PARTICLES) ? 1 : (m_nRenderType == FIRE_PARTICLES + PARTICLE_TYPES) ? -1 : 0;

    UpdateDecay ();
    UpdateTexCoord ();
#if 0
    if (colorP && (colorP->alpha < 0))
        m_color [0].alpha /= 2.0f;
    else
#endif
    {
        if (m_bEmissive)
            m_color [0].alpha = 1.0f;
        else if (nParticleSystemType == SIMPLE_SMOKE_PARTICLES)
            m_color [0].alpha /= 3.5f - float (gameOpts->render.particles.nQuality) / 2.0f; //colorP ? 2.0f + (color.red + color.green + color.blue) / 3.0f : 2.0f;
        else if (nParticleSystemType == SMOKE_PARTICLES)
            m_color [0].alpha /= colorP ? 3.0f - (color.red + color.green + color.blue) / 3.0f : 2.5f;
        else if (nParticleSystemType == BUBBLE_PARTICLES)
            m_color [0].alpha /= 2.0f;
        else if (nParticleSystemType == GATLING_PARTICLES)
            m_color [0].alpha /= 4.0f;
#	if 0
        else if (nParticleSystemType == GATLING_PARTICLES)
            ;//m_color [0].alpha /= 6;
#	endif
    }
    SetupColor (fBrightness);
    return 1;
}