Ejemplo n.º 1
0
Archivo: Game.cpp Proyecto: Sun42/rtype
void	Game::collisionWithEnnemies(Player * sender, Packet & answerPacket,
				    unsigned int idBallKiller, unsigned int idVictim,
				    unsigned int idVictimBall, unsigned int lifeOfShip,
				    unsigned int powerShoot, unsigned char typeVictim)
{
  this->_mutexVictims.lock();

  std::list<Victim>::iterator	it = this->_victims.begin();
  std::list<Victim>::iterator	itEnd = this->_victims.end();

  for(; it != itEnd; ++it)
    {
      if ((*it).isTheVictim(idVictim, idVictimBall, typeVictim))
	break;
    }

  if (it == itEnd)
    {
      std::cerr << "new victim\n" << std::endl;
      this->_victims.push_front(Victim(idVictim, idVictimBall, typeVictim, lifeOfShip));
      it = this->_victims.begin();
    }
  std::cout << "isKilled? " << std::boolalpha << (*it).isKilled() << std::endl;
  if (!(*it).isKilled())
    {
      std::cout << "lifeOfShip" << lifeOfShip << "powerShoot " << powerShoot << std::endl;
      *it -= powerShoot;
      std::cout << "isKilled? " << std::boolalpha << (*it).isDead() << std::endl;
      if ((*it).isDead())
	{
	  std::cout << "la victime est morte\n" << std::endl;
	  (*it).setKiller(sender->getIdShip(), idBallKiller);
	  std::cout << "idKiller " << (*it).getIdKiller() << std::endl
		    << "idBallKiller " << (*it).getIdBallKiller()  << std::endl
		    << "typeVictim" << (*it).getTypeVictim() << std::endl
		    << "idVictim " << (*it).getIdVictim() << std::endl
		    << "idVictimBall " << (*it).getIdVictimBall() << std::endl;
      
	  this->sendToAllPlayers(answerPacket << (*it).getIdKiller() << (*it).getIdBallKiller() << (*it).getTypeVictim() << (*it).getIdVictim() << (*it).getIdVictimBall());
	}
    }
  else
    {
      std::cout << "idKiller " << (*it).getIdKiller() << std::endl
		<< "idBallKiller " << (*it).getIdBallKiller()  << std::endl
		<< "typeVictim" << (*it).getTypeVictim() << std::endl
		<< "idVictim " << (*it).getIdVictim() << std::endl
		<< "idVictimBall " << (*it).getIdVictimBall() << std::endl;

      this->sendToAllPlayers(answerPacket << (*it).getIdKiller() << (*it).getIdBallKiller() << (*it).getTypeVictim() << (*it).getIdVictim() << (*it).getIdVictimBall());
    }
  this->_mutexVictims.unlock();
}
Ejemplo n.º 2
0
Archivo: p6.c Proyecto: sidwubf/bq
int
main()
{
	Victim();
	return 0;
}
Ejemplo n.º 3
0
int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
{
	char Command;
	char *pStr;
	int Optional = 0;
	int Error = 0;

	pResult->ResetVictim();

	pStr = pResult->m_pArgsStart;

	while(1)
	{
		// fetch command
		Command = *pFormat;
		pFormat++;

		if(!Command)
			break;

		if(Command == '?')
			Optional = 1;
		else
		{
			pStr = str_skip_whitespaces(pStr);

			if(!(*pStr)) // error, non optional command needs value
			{
				if(!Optional)
				{
					Error = 1;
					break;
				}

				while(*(pFormat - 1))
				{
					if(*(pFormat - 1) == 'v')
					{
						pResult->SetVictim(CResult::VICTIM_ME);
						break;
					}
					pFormat++;
				}
				break;
			}

			// add token
			if(*pStr == '"')
			{
				char *pDst;
				pStr++;
				pResult->AddArgument(pStr);

				pDst = pStr; // we might have to process escape data
				while(1)
				{
					if(pStr[0] == '"')
						break;
					else if(pStr[0] == '\\')
					{
						if(pStr[1] == '\\')
							pStr++; // skip due to escape
						else if(pStr[1] == '"')
							pStr++; // skip due to escape
					}
					else if(pStr[0] == 0)
						return 1; // return error

					*pDst = *pStr;
					pDst++;
					pStr++;
				}

				// write null termination
				*pDst = 0;


				pStr++;
			}
			else
			{
				char* pVictim = 0;

				if (Command != 'v')
					pResult->AddArgument(pStr);
				else
					pVictim = pStr;

				if(Command == 'r') // rest of the string
					break;
				else if(Command == 'v') // validate victim
					pStr = str_skip_to_whitespace(pStr);
				else if(Command == 'i') // validate int
					pStr = str_skip_to_whitespace(pStr);
				else if(Command == 'f') // validate float
					pStr = str_skip_to_whitespace(pStr);
				else if(Command == 's') // validate string
					pStr = str_skip_to_whitespace(pStr);

				if(pStr[0] != 0) // check for end of string
				{
					pStr[0] = 0;
					pStr++;
				}

				if (pVictim)
					pResult->SetVictim(Victim(pVictim));
			}
		}
	}

	return Error;
}