Example #1
0
/* comefrom: CityEvaluation */
DoProblems(void)
{
  register short x, z;
  short ThisProb, Max;

  for (z = 0; z < PROBNUM; z++)
    ProblemTable[z] = 0;
  ProblemTable[0] = CrimeAverage;		/* Crime */
  ProblemTable[1] = PolluteAverage;		/* Pollution */
  ProblemTable[2] = LVAverage * .7;		/* Housing */
  ProblemTable[3] = CityTax * 10;		/* Taxes */
  ProblemTable[4] = AverageTrf();		/* Traffic */
  ProblemTable[5] = GetUnemployment();		/* Unemployment */
  ProblemTable[6] = GetFire();			/* Fire */
  VoteProblems();
  for (z = 0; z < PROBNUM; z++)
    ProblemTaken[z] = 0;
  for (z = 0; z < 4; z++) {
    Max = 0;
    for (x = 0; x < 7; x++) {
      if ((ProblemVotes[x] > Max) && (!ProblemTaken[x])) {
	ThisProb = x;
	Max = ProblemVotes[x];
      }
    }
    if (Max) {
      ProblemTaken[ThisProb] = 1;
      ProblemOrder[z] = ThisProb;
    }
    else {
      ProblemOrder[z] = 7;
      ProblemTable[7] = 0;
    }
  }
}
Example #2
0
/* comefrom: CityEvaluation */
GetScore(void)
{
  register x, z;
  short OldCityScore;
  float SM, TM;

  OldCityScore = CityScore;
  x = 0;
  for (z = 0; z < 7; z++)
    x += ProblemTable[z];	/* add 7 probs */

  x = x / 3;			/* 7 + 2 average */
  if (x > 256) x = 256;

  z = (256 - x) * 4;
  if (z > 1000) z = 1000;
  if (z < 0 ) z = 0;

  if (ResCap) z = z * .85;
  if (ComCap) z = z * .85;
  if (IndCap) z = z * .85;
  if (RoadEffect < 32)  z = z - (32 - RoadEffect);
  if (PoliceEffect < 1000) z = z * (.9 + (PoliceEffect / 10000.1));
  if (FireEffect < 1000) z = z * (.9 + (FireEffect / 10000.1));
  if (RValve < -1000) z = z * .85;
  if (CValve < -1000) z = z * .85;
  if (IValve < -1000) z = z * .85;

  SM = 1.0;
  if ((CityPop == 0) || (deltaCityPop == 0))
    SM = 1.0;
  else if (deltaCityPop == CityPop)
    SM = 1.0;
  else if (deltaCityPop > 0)
    SM = ((float)deltaCityPop/CityPop) + 1.0;
  else if (deltaCityPop < 0)  
    SM = .95 + ((float) deltaCityPop/(CityPop - deltaCityPop));
  z = z * SM;
  z = z - GetFire();		/* dec score for fires */
  z = z - (CityTax);

  TM = unPwrdZCnt + PwrdZCnt;	/* dec score for unpowered zones */
  if (TM) SM = PwrdZCnt / TM;
  else SM = 1.0;
  z = z * SM; 

  if (z > 1000) z = 1000;
  if (z < 0 ) z = 0;

  CityScore = (CityScore + z) / 2; 

  deltaCityScore = CityScore - OldCityScore;
}
CFire * CFireManagerSA::GetFire ( CFireSAInterface * fire )
{
    DEBUG_TRACE("CFire * CFireManagerSA::GetFire ( CFireSAInterface * fire )");
	DWORD dwID = ((DWORD)fire - CLASS_CFireManager + 4) / sizeof(CFireSAInterface);
    return GetFire ( dwID );
}
Example #4
0
/**********************************************************
* DEBRIS GAME
* DESCRIPTION: This is a game where you need to shoot blocks
**********************************************************/
void Debris(void)
{
   char xMoveStart = 1;
   char fireIndex = 0;
   char moveYStart = 0;
   char yPosStart = 1;
   char index = 0;
   char index2 = 0;
   char jetHitCheck = 1;
   char lastCheck = 0;
   char numShots = 0;
   char yStart = 1;
   unsigned int ballSpeed = DEBRIS_DEBRISMOVERATE;
   unsigned int health = 47;
   unsigned int ballsDestroyed = 0;
   unsigned int highScore = EEProm_Read_16(debrisHighScore_Addr);
   struct Solid balls[DEBRIS_MAXDEBRIS];
   struct Fire ammo[DEBRIS_MAXPROJECTILES];
   struct Jet jet;

   if (health == 0)
   {
      health = 47;
   }

   //Assign pointers to allocated objects
   for (index = 0; index < DEBRIS_MAXDEBRIS; index++)
   {
      balls[index].enabled = 0; //Balls start disabled
   }
   LcdClear();

   //Initialize game objects
   constructJet(&jet, 15, 2);

   //Initialize balls
   reset(&balls[0], 80, 4, 1, 1, 1);
   reset(&balls[1], 60, 0, 3, 2, 1);
   reset(&balls[2], 70, 3, 1, 1, 1);
   reset(&balls[3], 60, 2, 3, 2, 1);
   reset(&balls[4], 80, 1, 1, 1, 1);
   display_jet(&jet, 0);
   DisplayHealth(health, 0);

   //Start Timers
   StartTimer(0, DEBRIS_USERMOVERATE_MS);     //Move player timer
   StartTimer(1, DEBRIS_RATEOFFIRE_MS);       //Fire timer
   StartTimer(2, DEBRIS_PROJECTILESPEED_MS);  //Fire move timer
   StartTimer(3, ballSpeed);                  //Move balls

   //Enter game loop
   for (;;)
   {
	  //Check user move button
	  if (CheckTimer(0))
	  {
		  if (GetEnterButton()) //User wants to pause the game
		  {
			  if (Pause(showJetScore, ballsDestroyed,  health, highScore) == 1)
			  {
				  return;
			  }
			  display_jet(&jet, 0);
			  DisplayHealth(health, 0);
		  }
		  else if (GetLeft()) //Left button is being pressed
		  {
			  jet_moveLeft(&jet, 0);
		  }
		  else if (GetRight())
		  {
			  jet_moveRight(&jet, 0);
		  }
		  if (GetUp())
		  {
			  jet_moveUp(&jet);
		  }
		  else if (GetDown())
		  {
			  jet_moveDown(&jet);
		  }
		  StartTimer(0, DEBRIS_USERMOVERATE_MS); //Reset this timer
	  }
      //Check fire buttons
      if (CheckTimer(1)) //Now we can fire
      {
    	  if (GetFire()) //User took the chance to fire
    	  {
             if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
             numShots++;
             startFire(&ammo[fireIndex], &jet, 0);
             StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer.
             fireIndex++;
             SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetSecFire()) //Shockwave cannon
    	  {
    		 if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    	     startFire(&ammo[fireIndex], &jet, 2);
    		 StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300); //Restart the fire timer.
    		 numShots++;
    		 fireIndex++;
    		 SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetRightFire()) //Fire Reverse
    	  {
    		 if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    		 startFire(&ammo[fireIndex], &jet, 1);
    	     StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer.
    	     numShots++;
    	     fireIndex++;
    	     SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetRightSecFire()) //Reverse Shockwave cannon
    	  {
    		  if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    		  startFire(&ammo[fireIndex], &jet, 3);
    	      StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300);
    	      numShots++;
    	      fireIndex++;
    	      SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
      }
      //Moves the weapons fire
      if (CheckTimer(2))
      {
          //Check each ammo value to see if it hit a ball
          for (index = 0; index < DEBRIS_MAXPROJECTILES; index++)
          {
             if (ammo[index].enabled == 1) //This gives the game a performance boost but can cause inconsistant ball speeds
             {
                if (autoMove(&ammo[index]) == 1)
                {

                }
                if (lastCheck == 0)
                {
             	  lastCheck = 1;
                   //Check each bullet to see if it hit a ball
                   for (index2 = 0; index2 < DEBRIS_MAXDEBRIS; index2++)
                   {
                      //If a ball is hit, reset it so it starts over again.
             	     if (fire_checkHit(&ammo[index], &balls[index2]) == 1)//ammo[index].fireOutput == 1)
                      {
             	    	SendData(SOUND_BLOCK_DESTROYED); //Block hit sound
             	        balls[index2].enabled = 0;
             	        displaySolid(&balls[index2], 1);
                         if (ammo[index].weapon != 2 && ammo[index].weapon != 3)
                         {
                 	       ammo[index].enabled = 0;
                 	       displayFire(&ammo[index], 1);
                         }
                         //Ball speed increases every time 3 balls are dispatched
                         if (ballsDestroyed % 3 == 0 && ballSpeed > 15)
                         {
                         	ballSpeed--;
                         }
                         changeBallStart(&balls[index2], &moveYStart, &yPosStart, &xMoveStart, &yStart);
                         ballsDestroyed++;
                         if (ballsDestroyed > highScore)
                         {
                         	highScore = ballsDestroyed;
                         	EEProm_Write_16(debrisHighScore_Addr, highScore);
                         }
                      }
                   }
                }
                else
                {
             	   lastCheck = 0;
                }
             }
          }
         StartTimer(2, DEBRIS_PROJECTILESPEED_MS);
      }
      //Move the balls
      if (CheckTimer(3))
      {
          for (index = 0; index < DEBRIS_MAXDEBRIS; index++)
          {
         	if (balls[index].enabled == 1) //Gives a small performance boost at the cost of ball speed consistancy
         	{
         	   autoMoveSolid(&balls[index]);
         	   if (jetHitCheck == 0)
         	   {
                   //Ball hits the jet
         		  jetHitCheck = 1;
                   if (jet_checkHit(&jet, &balls[index]) != 0x00)
                   {
                	  SendData(SOUND_BLOCK_DESTROYED); //Block hit sound
                      balls[index].enabled = 0;
                      displaySolid(&balls[index], 1);
                      display_jet(&jet, 0);
         	          health--;
         	         DisplayHealth(health, 0);
         	         //Jet was destroyed
         	         if (health == 0)
         	         {
         	        	display_jet(&jet, 1);
         	    	    constructJet(&jet, 15, 2);
         	    	    health = 47;
         	    	    ballsDestroyed = 0;
         	    	    display_jet(&jet, 0);
         	         }
         	         changeBallStart(&balls[index], &moveYStart, &yPosStart, &xMoveStart, &yStart);
                  }
         	   }
         	   else
         	   {
         		   jetHitCheck = 0;
         	   }
             }
         }
         StartTimer(3, ballSpeed);
      }
   }
}