Пример #1
0
bool Fleet::removeShips(uint32_t type, uint32_t number){
  std::map<std::pair<int32_t, uint32_t>, uint32_t> ships = ((RefQuantityListObjectParam*)(obj->getParameter(4,1)))->getRefQuantityList();
  if(ships[std::pair<int32_t, uint32_t>(rst_Design, type)] >= number){
    ships[std::pair<int32_t, uint32_t>(rst_Design, type)] -= number;
    if(ships[std::pair<int32_t, uint32_t>(rst_Design, type)] == 0){
      ships.erase(std::pair<int32_t, uint32_t>(rst_Design, type));
    }
    ((RefQuantityListObjectParam*)(obj->getParameter(4,1)))->setRefQuantityList(ships);
    DesignStore* ds = Game::getGame()->getDesignStore();
    bool colonise = false;
    for(std::map<std::pair<int32_t, uint32_t>, uint32_t>::iterator itcurr = ships.begin();
        itcurr != ships.end(); ++itcurr){
      if(ds->getDesign(itcurr->first.second)->getPropertyValue(ds->getPropertyByName("Colonise")) == 1.0){
        colonise = true;
        break;
      }
    }
    OrderManager* om = Game::getGame()->getOrderManager();
    OrderQueueObjectParam* orderqueue = ((OrderQueueObjectParam*)(obj->getParameter(3,1)));
    if(colonise){
      std::set<uint32_t> allowed = orderqueue->getAllowedOrders();
      allowed.insert(om->getOrderTypeByName("Colonise"));
      orderqueue->setAllowedOrders(allowed);
    }else{
      std::set<uint32_t> allowed = orderqueue->getAllowedOrders();
      allowed.erase(om->getOrderTypeByName("Colonise"));
      orderqueue->setAllowedOrders(allowed);
    }
    obj->touchModTime();
    return true;
  }
  return false;
}
Пример #2
0
long long Fleet::maxSpeed(){
  double speed = 1e100;
  DesignStore* ds = Game::getGame()->getDesignStore();
  std::map<std::pair<int32_t, uint32_t>, uint32_t> ships = ((RefQuantityListObjectParam*)(obj->getParameter(4,1)))->getRefQuantityList();
  for(std::map<std::pair<int32_t, uint32_t>, uint32_t>::iterator itcurr = ships.begin();
      itcurr != ships.end(); ++itcurr){
        speed = fmin(speed, ds->getDesign(itcurr->first.second)->getPropertyValue(ds->getPropertyByName("Speed")));
  }
  return (long long)(floor(speed));
}
Пример #3
0
void Fleet::addShips(uint32_t type, uint32_t number){
  std::map<std::pair<int32_t, uint32_t>, uint32_t> ships = ((RefQuantityListObjectParam*)(obj->getParameter(4,1)))->getRefQuantityList();
  ships[std::pair<int32_t, uint32_t>(rst_Design, type)] += number;
  ((RefQuantityListObjectParam*)(obj->getParameter(4,1)))->setRefQuantityList(ships);
  DesignStore* ds = Game::getGame()->getDesignStore();
  OrderManager* om = Game::getGame()->getOrderManager();
  if(ds->getDesign(type)->getPropertyValue(ds->getPropertyByName("Colonise")) == 1.0){
    std::set<uint32_t> allowed = ((OrderQueueObjectParam*)(obj->getParameter(3,1)))->getAllowedOrders();
    allowed.insert(om->getOrderTypeByName("Colonise"));
    ((OrderQueueObjectParam*)(obj->getParameter(3,1)))->setAllowedOrders(allowed);
  }
  obj->touchModTime();
}
Пример #4
0
void taeRuleset::createComponents() {
    DesignStore *ds = Game::getGame()->getDesignStore();

    Component* comp = new Component();
    map<unsigned int, string> propList;

    //Merchants
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("MerchantCargo");
    comp->setDescription("A cargo hold outfitted to carry businessmen");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 1)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Scientists
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("ScientistCargo");
    comp->setDescription("A cargo hold outfitted to carry scientists");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 2)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Settlers
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("SettlerCargo");
    comp->setDescription("A cargo hold outfitted to carry settlers");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 3)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Mining Robots
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("MiningCargo");
    comp->setDescription("A cargo hold outfitted to carry mining robots");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 4)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Merchant Leader
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("MerchantLeaderCargo");
    comp->setDescription("A cargo hold outfitted to carry powerful business leaders");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 5)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Lead Scientist
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("ScientistLeaderCargo");
    comp->setDescription("A cargo hold outfitted to carry a lead scientist");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 6)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Government Official
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("SettlerLeaderCargo");
    comp->setDescription("A cargo hold outfitted to a government leader");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 7)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Mining Foreman
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("MiningLeaderCargo");
    comp->setDescription("A cargo hold outfitted to a highly specialized mining robot leader");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Passengers")] = "(lambda (design) 8)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

    //Weapons Arsenal
    comp = new Component();
    comp->addCategoryId(ds->getCategoryByName("Ships"));
    comp->setName("Weapon");
    comp->setDescription("The weapons arsenal for the ship");
    comp->setTpclRequirementsFunction(
        "(lambda (design) "
            "(if (= (designType._num-components design) 1) "
            "(cons #t \"\") "
            "(cons #f \"This is a complete component, nothing else can be included\")))");
    propList.clear();
    propList[ds->getPropertyByName("Bombs")] = "(lambda (design) 1)";
    comp->setPropertyList(propList);
    ds->addComponent(comp);

}
Пример #5
0
bool Colonise::doOrder(IGObject * ob){
  //if not close, move
  IGObject* target = Game::getGame()->getObjectManager()->getObject(ob->getParent());
  if(target == NULL || target->getType() != Game::getGame()->getObjectTypeManager()->getObjectTypeByName("Planet")){
    
    Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Target was not valid.", ob->getID());
    Game::getGame()->getObjectManager()->doneWithObject(ob->getParent());
    Message * msg = new Message();
    msg->setSubject("Colonise order canceled");
    msg->setBody("Not at a planet, colonisation canceled");
    msg->addReference(rst_Action_Order, rsorav_Canceled);
    msg->addReference(rst_Object, ob->getID());
    Game::getGame()->getPlayerManager()->getPlayer(((Fleet*)(ob->getObjectBehaviour()))->getOwner())->postToBoard(msg);

    return true;
  }
  
  Fleet* fleet = (Fleet*)(ob->getObjectBehaviour());
  Planet* planet = (Planet*)(target->getObjectBehaviour());
  
  Message * msg = new Message();
  msg->addReference(rst_Object, ob->getID());
  msg->addReference(rst_Object, target->getID());

  if(planet->getOwner() != fleet->getOwner()){

    if(planet->getOwner() != 0){
      Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Planet already owned.", 
        ob->getID());
    
      msg->setSubject("Colonisation failed");
      msg->setBody("The planet you tried to colonise, is already owned by someone else.");
      msg->addReference(rst_Action_Order, rsorav_Canceled);
    }else{

      DesignStore* ds = Game::getGame()->getDesignStore();
      int shiptype = 0;
      int shiphp = 2000000;
      std::map<uint32_t, uint32_t> ships = fleet->getShips();
      unsigned int colonisePropID = ds->getPropertyByName( "Colonise");
      unsigned int armorPropID = ds->getPropertyByName( "Armour");
      for(std::map<uint32_t, uint32_t>::iterator itcurr = ships.begin();
	  itcurr != ships.end(); ++itcurr){
	Design *design = ds->getDesign(itcurr->first);
	if(design->getPropertyValue(colonisePropID) != 0.0 && shiphp > (int)design->getPropertyValue(armorPropID)){
	  shiptype = itcurr->first;
	  shiphp = (int)design->getPropertyValue(armorPropID);
	}
      }
      
      Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): shiptype %d", 
        ob->getID(), shiptype);
      if(shiptype != 0){
        uint32_t oldowner = planet->getOwner();
	planet->setOwner(fleet->getOwner());
        Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->addOwnedObject(target->getID());
        uint32_t queueid = static_cast<OrderQueueObjectParam*>(target->getParameterByType(obpT_Order_Queue))->getQueueId();
        OrderQueue* queue = Game::getGame()->getOrderManager()->getOrderQueue(queueid);
        queue->removeOwner(oldowner);
        queue->addOwner(fleet->getOwner());
	
	fleet->removeShips(shiptype, 1);
	
	msg->setSubject("Colonised planet");
	msg->setBody("You have colonised a planet!");
	msg->addReference(rst_Action_Order, rsorav_Completion);
        
      }else{
	msg->setSubject("Colonisation failed");
	msg->setBody("Your fleet did not have a frigate to colonise the planet");
	msg->addReference(rst_Action_Order, rsorav_Invalid);
      }
      
      if(fleet->totalShips() == 0){
	Game::getGame()->getObjectManager()->scheduleRemoveObject(ob->getID());
        Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->removeOwnedObject(ob->getID());
      }
      
    }
  }else{
    Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Was already owned by the player!", 
      ob->getID());

    msg->setSubject("Colonisation failed");
    msg->setBody("You already own the planet you tried to colonise");
    msg->addReference(rst_Action_Order, rsorav_Canceled);
  }
  
  Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->postToBoard(msg);
  Game::getGame()->getObjectManager()->doneWithObject(target->getID());
  return true;
  
}