コード例 #1
0
ファイル: BaseAI.cpp プロジェクト: cherez/the-machine
bool BaseAI::startTurn()
{
  static bool initialized = false;
  int count = 0;
  count = getShipTypeCount(c);
  shipTypes.clear();
  shipTypes.resize(count);
  for(int i = 0; i < count; i++)
  {
    shipTypes[i] = ShipType(getShipType(c, i));
  }

  count = getPlayerCount(c);
  players.clear();
  players.resize(count);
  for(int i = 0; i < count; i++)
  {
    players[i] = Player(getPlayer(c, i));
  }

  count = getShipCount(c);
  ships.clear();
  ships.resize(count);
  for(int i = 0; i < count; i++)
  {
    ships[i] = Ship(getShip(c, i));
  }

  if(!initialized)
  {
    initialized = true;
    init();
  }
  return run();
}
コード例 #2
0
ファイル: librfs.c プロジェクト: dwagon/celemp
Number CalcType(Ship shp)
/******************************************************************************/
/* Calculate the type of ship that it is        */
{
int  ratio;

TRLIB(printf("librfs:Calctype(shp: %d)\n",shp));

if (fleet[shp].cargo==0) {
	if(fleet[shp].fight==0)
		return(HULL);
	return(DeathStarType(shp));
	}
ratio=(100*fleet[shp].fight)/fleet[shp].cargo;
if(ratio>900)
	return(DeathStarType(shp));
if(ratio>200)
	return(BattleType(shp));
if(ratio>50)
	return(ShipType(shp));
return(CargoType(shp));
}
コード例 #3
0
ファイル: levelreader.cpp プロジェクト: idaohang/gpsi
	/**
	 * Parse the ship types.
	 *
	 * @return A map with ID's and shiptypes.
	*/
	std::map<std::string, ShipType> LevelReader::parseShipTypes() {
		std::map<std::string, ShipType> shipTypes;
		ticpp::Element* shipsNode = fLevel.FirstChild("level")->FirstChild("ships")->ToElement();
		ticpp::Iterator<ticpp::Element> shipTypeNode("ship");
		for (shipTypeNode = shipTypeNode.begin(shipsNode); shipTypeNode != shipTypeNode.end(); shipTypeNode++) {
			std::string name = (*shipTypeNode).GetAttribute("name");
			ticpp::Element* boundingshape = (*shipTypeNode).FirstChild("boundingshape")->ToElement();
			IBoundingShapeDescription* shape;
			parseBoundingShape(shape, boundingshape);
			
			ticpp::Element* weaponsNode = shipTypeNode->FirstChild("weapons")->ToElement();
			ticpp::Iterator<ticpp::Element> weaponNode("weapon");
			std::vector<std::string> weapons;
			for (weaponNode = weaponNode.begin(weaponsNode); weaponNode != weaponNode.end(); weaponNode++) {
				weapons.push_back(weaponNode->GetAttribute("name"));
			}
			Vector2 speed = parseVector(shipTypeNode->FirstChild("maxspeed")->ToElement());
			int hitpoints = shipTypeNode->GetAttribute<int>("hitpoints");
			
			shipTypes[name] = ShipType(name, shape, weapons, speed, hitpoints);
		}
		return shipTypes;
	}
コード例 #4
0
ファイル: ShipType.cpp プロジェクト: laarmen/pioneer
void ShipType::Init()
{
	static bool isInitted = false;
	if (isInitted)
		return;
	isInitted = true;

	// load all ship definitions
	namespace fs = FileSystem;
	for (fs::FileEnumerator files(fs::gameDataFiles, "ships", fs::FileEnumerator::Recurse); !files.Finished(); files.Next()) {
		const fs::FileInfo &info = files.Current();
		if (ends_with_ci(info.GetPath(), ".json")) {
			const std::string id(info.GetName().substr(0, info.GetName().size()-5));
			ShipType st = ShipType(id, info.GetPath());
			types.insert(std::make_pair(st.id, st));

			// assign the names to the various lists
			switch( st.tag ) {
			case TAG_SHIP:				player_ships.push_back(id);				break;
			case TAG_STATIC_SHIP:		static_ships.push_back(id);				break;
			case TAG_MISSILE:			missile_ships.push_back(id);			break;
				break;
			case TAG_NONE:
			default:
				break;
			}
		}
	}

#if ALLOW_LUA_SHIP_DEF
	lua_State *l = luaL_newstate();

	LUA_DEBUG_START(l);

	luaL_requiref(l, "_G", &luaopen_base, 1);
	luaL_requiref(l, LUA_DBLIBNAME, &luaopen_debug, 1);
	luaL_requiref(l, LUA_MATHLIBNAME, &luaopen_math, 1);
	lua_pop(l, 3);

	LuaConstants::Register(l);
	LuaVector::Register(l);
	LUA_DEBUG_CHECK(l, 0);

	// provide shortcut vector constructor: v = vector.new
	lua_getglobal(l, LuaVector::LibName);
	lua_getfield(l, -1, "new");
	assert(lua_iscfunction(l, -1));
	lua_setglobal(l, "v");
	lua_pop(l, 1); // pop the vector library table

	LUA_DEBUG_CHECK(l, 0);

	// register ship definition functions
	lua_register(l, "define_ship", define_ship);
	lua_register(l, "define_static_ship", define_static_ship);
	lua_register(l, "define_missile", define_missile);

	LUA_DEBUG_CHECK(l, 0);

	// load all ship definitions
	namespace fs = FileSystem;
	for (fs::FileEnumerator files(fs::gameDataFiles, "ships", fs::FileEnumerator::Recurse); !files.Finished(); files.Next()) {
		const fs::FileInfo &info = files.Current();
		if (ends_with_ci(info.GetPath(), ".lua")) {
			const std::string name = info.GetName();
			s_currentShipFile = name.substr(0, name.size() - 4);
			if (ShipType::types.find(s_currentShipFile) == ShipType::types.end())
			{
				pi_lua_dofile(l, info.GetPath());
				s_currentShipFile.clear();
			}
		}
	}

	LUA_DEBUG_END(l, 0);

	lua_close(l);
#endif

	//remove unbuyable ships from player ship list
	ShipType::player_ships.erase(
		std::remove_if(ShipType::player_ships.begin(), ShipType::player_ships.end(), ShipIsUnbuyable),
		ShipType::player_ships.end());

	if (ShipType::player_ships.empty())
		Error("No playable ships have been defined! The game cannot run.");
}
コード例 #5
0
void ComputerPlayer::assign(Map *cMap) {
    
    bool bLoopInvariant = true;
    
    //This will hold the added ship
    Ship *cAssignedShip = NULL;
    
    
    //Iterate the loop until a valid ship has been found
    while (bLoopInvariant) {
        
        //Just randomly place the ships until something works out
        
        //Choose a random ship type
        ShipType eShipType = ShipType((rand() % (ShipTypeTotalNumber-1)) + 1);
        
        //Choose a random direction
        ShipDirection eShipDirection = ShipDirection((rand() % (ShipDirectionTotalNumber-1)) + 1);
        
        //Create a ship at a guessed position
        cAssignedShip = new Ship(eShipType, eShipDirection, guess());
        
        //Iterate the loop until a valid ship has been found
        switch (m_ePlayerDifficulty) {
            case PlayerDifficultyEasy:
            case PlayerDifficultyMedium:
                
                //If the ship is in a valid position - its enough
                if (cMap->isValid(*cAssignedShip)) {
                    
                    bLoopInvariant = false;
                    
                }
                else {
                    
                    //Make another try
                    delete cAssignedShip;
                    
                }
                
                break;
                
            case PlayerDifficultyHard:
                
                //Needs to check that the ship is in valid position across an extended area
                if (checkExtendedArea(cAssignedShip, cMap)) {
                    
                    bLoopInvariant = false;
                    
                }
                else {
                    
                    //Make another try
                    delete cAssignedShip;
                    
                }
                
                break;
                
            default:
                break;
        }
        

        
    }
    
    //Add the ship to the map
    cMap->addShip(*cAssignedShip);
    
    //Delete after assignment
    delete cAssignedShip;
    
}