Exemple #1
0
uint32_t TDebugProtocol::writeItem(const std::string& str) {
  uint32_t size = 0;
  size += startItem();
  size += writePlain(str);
  size += endItem();
  return size;
}
Exemple #2
0
uint32_t TDebugProtocol::writeStructBegin(const char* name) {
  uint32_t size = 0;
  size += startItem();
  size += writePlain(string(name) + " {\n");
  indentUp();
  write_state_.push_back(STRUCT);
  return size;
}
Exemple #3
0
uint32_t DebugProtocolWriter::writeMapBegin(TType keyType,
                                            TType valueType,
                                            uint32_t size) {
  startItem();
  writePlain("map<{},{}>[{}] {{\n",
             fieldTypeName(keyType),
             fieldTypeName(valueType),
             size);
  pushState(MAP_KEY);
  return 0;
}
/**
 *	This method overrides the base class' implementation to return the
 *	appropriate end points for this kind of link, using the start item
 *	and the end point.
 *
 *	@param s				Return parameter for the start point position.
 *	@param index			Return parameter for the end point position.
 *	@param absoluteCoords	True to use absolute coordinates instead of local.
 *	@return					True if successful, false otherwise.
 */
/*virtual*/ bool EditorChunkPointLink::getEndPoints(
	Vector3 &s, Vector3 &e, bool absoluteCoords ) const
{
    EditorChunkItem *start  = (EditorChunkItem *)startItem().getObject();

    // Maybe it's still loading...
    if ( start == NULL || start->chunk() == NULL)
    {
        return false;
    }

    Vector3 lStartPt = start->edTransform().applyToOrigin();
    s = start->chunk()->transform().applyPoint( lStartPt );
	e = endPoint_;

	// Get the start height, and check if it's in the ground
	bool foundHeight;
	float sh  = heightAtPos(s.x, s.y + NEXT_HEIGHT_SAMPLE, s.z, &foundHeight);
	float sd = s.y - sh;
	if (!foundHeight)
		sd = 0.0f;

	bool inAir = fabs(sd) > AIR_THRESHOLD;
	if ( !inAir )
	{
		// It's in the ground, get height at the middle and interpolate it to
		// the end using the start height.
		Vector3 mid = (e - s) / 2.0f + s;
		float mh = heightAtPos(mid.x, mid.y + NEXT_HEIGHT_SAMPLE, mid.z);
		float h = (mh-sh) * 2.0f + sh;
		if ( h > e.y )
		{
			// It's not in the air, and the terrain occluding the link, so
			// make the end point as high as the terrain at that position.
			float oldLength = ( e - s ).length();
			e.y = h;
			// Preserve the length
			Vector3 dir = ( e - s );
			dir.normalise();
			e = dir * oldLength + s;
		}
	}

    if (!absoluteCoords)
    {
        Matrix m = outsideChunk()->transform();
        m.invert();
        s = m.applyPoint(s);
        e = m.applyPoint(e);
    }

    return true;
}
Exemple #5
0
uint32_t TDebugProtocol::writeSetBegin(const TType elemType,
                                       const uint32_t size) {
  // TODO(dreiss): Optimize short sets.
  uint32_t bsize = 0;
  bsize += startItem();
  bsize += writePlain(
      "set<" + fieldTypeName(elemType) + ">"
      "[" + boost::lexical_cast<string>(size) + "] {\n");
  indentUp();
  write_state_.push_back(SET);
  return bsize;
}
Exemple #6
0
uint32_t TDebugProtocol::writeMapBegin(const TType keyType,
                                       const TType valType,
                                       const uint32_t size) {
  // TODO(dreiss): Optimize short maps?
  uint32_t bsize = 0;
  bsize += startItem();
  bsize += writePlain(
      "map<" + fieldTypeName(keyType) + "," + fieldTypeName(valType) + ">"
      "[" + boost::lexical_cast<string>(size) + "] {\n");
  indentUp();
  write_state_.push_back(MAP_KEY);
  return bsize;
}
Exemple #7
0
Arrow::~Arrow()
{
    hide();
    setToolTip("");
    startItem()->removeArrow(this);
    endItem()->removeArrow(this);
    handleList.clear();

    if(editingMode && manager){
        Application* mainApplication = manager->getKnowledgeBase()->getApplication();
        manager->getKnowledgeBase()->removeConnectionFromApplication(mainApplication, connection);
    }
}
/**
 *  This method overrides the base class' method to render to the sorted
 *	channel, to ensure transparency gets rendered properly.
 */
/*virtual*/ void EditorChunkPointLink::draw()
{
    if (startItem() == NULL)
        return;

    if 
    (
        edShouldDraw()
		&&
		!WorldManager::instance().drawSelection()
        &&
        !Moo::rc().reflectionScene() 
        && 
        !Moo::rc().mirroredTransform()
        &&
        enableDraw()
    )
    {
		Moo::SortedChannel::addDrawItem( new SortedLinkItem( this ) );
	}
}
/**
 *  This method is called by the sorted channel drawing item created in the
 *	'draw' method. It also checks to see if one of the end points of the link
 *	is in a read-only chunk. If so, it will set a shader constant to draw it
 *	in red.
 */
/*virtual*/ void EditorChunkPointLink::drawInternal()
{
	if ( materialEffect()->pEffect() && materialEffect()->pEffect()->pEffect() )
	{
		EditorChunkItem* start =
			static_cast<EditorChunkItem*>(startItem().getObject());

		int16 gridX;
		int16 gridZ;
		WorldManager::instance().chunkDirMapping()->gridFromChunkName( chunkId_, gridX, gridZ );
		
		static uint32 s_currentFrame = -16;
		static int s_drawReadOnlyRed = 1;
		if (Moo::rc().frameTimestamp() != s_currentFrame)
		{
			s_currentFrame = Moo::rc().frameTimestamp();
			s_drawReadOnlyRed = Options::getOptionInt( "render/misc/shadeReadOnlyAreas", 1 );
		}
		bool drawRed = false;
		if (s_drawReadOnlyRed)
		{
			if ( start != NULL && !EditorChunkCache::instance( *(start->chunk()) ).edIsWriteable() )
				drawRed = true;
			else if ( !EditorChunk::outsideChunkWriteable( gridX, gridZ ) )
				drawRed = true;
		}

		if ( drawRed )
		{
			materialEffect()->pEffect()->pEffect()->SetBool("colourise", TRUE);
		}
		else
		{
			materialEffect()->pEffect()->pEffect()->SetBool("colourise", FALSE);
		}
	}
	EditorChunkLink::draw();
}
Exemple #10
0
productionProgress_e Production::step(Base * b, SavedGame * g, const Mod *m, Language *lang)
{
	int done = getAmountProduced();
	_timeSpent += _engineers;

	if (done < getAmountProduced())
	{
		int produced;
		if (!getInfiniteAmount())
		{
			produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce
		}
		else
		{
			produced = getAmountProduced() - done;
		}
		int count = 0;
		do
		{
			for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i)
			{
				if (_rules->getCategory() == "STR_CRAFT")
				{
					Craft *craft = new Craft(m->getCraft(i->first, true), b, g->getId(i->first));
					craft->setStatus("STR_REFUELLING");
					b->getCrafts()->push_back(craft);
					break;
				}
				else if (_rules->getCategory() == "STR_VEHICLE")
				{
					Soldier *soldier = m->genSoldier(g, i->first);
					b->getSoldiers()->push_back(soldier);
					break;
				}
				else
				{
					if (m->getItem(i->first, true)->getBattleType() == BT_NONE)
					{
						for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
						{
							(*c)->reuseItem(i->first);
						}
					}
					if (getSellItems())
						g->setFunds(g->getFunds() + (m->getItem(i->first, true)->getSellCost() * i->second));
					else
						b->getStorageItems()->addItem(i->first, i->second);
				}
			}
			// Spawn persons (soldiers, engineers, scientists, ...)
			const std::string &spawnedPersonType = _rules->getSpawnedPersonType();
			if (spawnedPersonType != "")
			{
				if (spawnedPersonType == "STR_SCIENTIST")
				{
					Transfer *t = new Transfer(24);
					t->setScientists(1);
					b->getTransfers()->push_back(t);
				}
				else if (spawnedPersonType == "STR_ENGINEER")
				{
					Transfer *t = new Transfer(24);
					t->setEngineers(1);
					b->getTransfers()->push_back(t);
				}
				else
				{
					RuleSoldier *rule = m->getSoldier(spawnedPersonType);
					if (rule != 0)
					{
						Transfer *t = new Transfer(24);
						Soldier *s = m->genSoldier(g, rule->getType());
						if (_rules->getSpawnedPersonName() != "")
						{
							s->setName(lang->getString(_rules->getSpawnedPersonName()));
						}
						t->setSoldier(s);
						b->getTransfers()->push_back(t);
					}
				}
			}
			count++;
			if (count < produced)
			{
				// We need to ensure that player has enough cash/item to produce a new unit
				if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
				if (!haveEnoughMaterialsForOneMoreUnit(b, m)) return PROGRESS_NOT_ENOUGH_MATERIALS;
				startItem(b, g, m);
			}
		}
		while (count < produced);
	}
	if (getAmountProduced() >= _amount && !getInfiniteAmount()) return PROGRESS_COMPLETE;
	if (done < getAmountProduced())
	{
		// We need to ensure that player has enough cash/item to produce a new unit
		if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
		if (!haveEnoughLivingSpaceForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_LIVING_SPACE;
		if (!haveEnoughMaterialsForOneMoreUnit(b, m)) return PROGRESS_NOT_ENOUGH_MATERIALS;
		startItem(b, g, m);
	}
	return PROGRESS_NOT_COMPLETE;
}
Exemple #11
0
productionProgress_e Production::step(Base * b, SavedGame * g, const Mod *m)
{
	int done = getAmountProduced();
	_timeSpent += _engineers;

	if (done < getAmountProduced())
	{
		int produced;
		if (!getInfiniteAmount())
		{
			produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce
		}
		else
		{
			produced = getAmountProduced() - done;
		}
		int count = 0;
		do
		{
			for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i)
			{
				if (_rules->getCategory() == "STR_CRAFT")
				{
					Craft *craft = new Craft(m->getCraft(i->first, true), b, g->getId(i->first));
					craft->setStatus("STR_REFUELLING");
					b->getCrafts()->push_back(craft);
					break;
				}
				else
				{
					if (m->getItem(i->first, true)->getBattleType() == BT_NONE)
					{
						for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
						{
							(*c)->reuseItem(i->first);
						}
					}
					if (getSellItems())
						g->setFunds(g->getFunds() + (m->getItem(i->first, true)->getSellCost() * i->second));
					else
						b->getStorageItems()->addItem(i->first, i->second);
				}
			}
			count++;
			if (count < produced)
			{
				// We need to ensure that player has enough cash/item to produce a new unit
				if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
				if (!haveEnoughMaterialsForOneMoreUnit(b, m)) return PROGRESS_NOT_ENOUGH_MATERIALS;
				startItem(b, g, m);
			}
		}
		while (count < produced);
	}
	if (getAmountProduced() >= _amount && !getInfiniteAmount()) return PROGRESS_COMPLETE;
	if (done < getAmountProduced())
	{
		// We need to ensure that player has enough cash/item to produce a new unit
		if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
		if (!haveEnoughMaterialsForOneMoreUnit(b, m)) return PROGRESS_NOT_ENOUGH_MATERIALS;
		startItem(b, g, m);
	}
	return PROGRESS_NOT_COMPLETE;
}
Exemple #12
0
productionProgress_e Production::step(Base * b, SavedGame * g, const Ruleset *r)
{
    int done = getAmountProduced();
    _timeSpent += _engineers;

    if (!Options::canManufactureMoreItemsPerHour && done < getAmountProduced())
    {
        // enforce pre-TFTD manufacturing rules: extra hours are wasted
        _timeSpent = (done + 1) * _rules->getManufactureTime();
    }

    if (done < getAmountProduced())
    {
        int produced;
        if (!getInfiniteAmount())
        {
            produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce
        }
        else
        {
            produced = getAmountProduced() - done;
        }
        int count = 0;
        do
        {
            for (std::map<std::string,int>::const_iterator i = _rules->getProducedItems().begin(); i != _rules->getProducedItems().end(); ++i)
            {
                if (_rules->getCategory() == "STR_CRAFT")
                {
                    Craft *craft = new Craft(r->getCraft(i->first), b, g->getId(i->first));
                    craft->setStatus("STR_REFUELLING");
                    b->getCrafts()->push_back(craft);
                    break;
                }
                else
                {
                    // Check if it's ammo to reload a craft
                    if (r->getItem(i->first)->getBattleType() == BT_NONE)
                    {
                        for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
                        {
                            if ((*c)->getStatus() != "STR_READY")
                                continue;
                            for (std::vector<CraftWeapon*>::iterator w = (*c)->getWeapons()->begin(); w != (*c)->getWeapons()->end(); ++w)
                            {
                                if ((*w) != 0 && (*w)->getRules()->getClipItem() == i->first && (*w)->getAmmo() < (*w)->getRules()->getAmmoMax())
                                {
                                    (*w)->setRearming(true);
                                    (*c)->setStatus("STR_REARMING");
                                }
                            }
                        }
                    }
                    // Check if it's fuel to refuel a craft
                    if (r->getItem(i->first)->getBattleType() == BT_NONE)
                    {
                        for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
                        {
                            if ((*c)->getStatus() != "STR_READY")
                                continue;
                            if ((*c)->getRules()->getRefuelItem() == i->first && 100 > (*c)->getFuelPercentage())
                                (*c)->setStatus("STR_REFUELLING");
                        }
                    }
                    if (getSellItems())
                        g->setFunds(g->getFunds() + (r->getItem(i->first)->getSellCost() * i->second));
                    else
                        b->getItems()->addItem(i->first, i->second);
                }
            }
            count++;
            if (count < produced)
            {
                // We need to ensure that player has enough cash/item to produce a new unit
                if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
                if (!haveEnoughMaterialsForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_MATERIALS;
                startItem(b,g);
            }
        }
        while (count < produced);
    }
    if (getAmountProduced() >= _amount && !getInfiniteAmount()) return PROGRESS_COMPLETE;
    if (done < getAmountProduced())
    {
        // We need to ensure that player has enough cash/item to produce a new unit
        if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
        if (!haveEnoughMaterialsForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_MATERIALS;
        startItem(b,g);
    }
    return PROGRESS_NOT_COMPLETE;
}
Exemple #13
0
productionProgress_e Production::step(Base * b, SavedGame * g, const Ruleset *r)
{
	int done = getAmountProduced ();
	_timeSpent += _engineers;
	if (done < getAmountProduced ())
	{
		bool allowAutoSellProduction = Options::getBool("allowAutoSellProduction");
		bool canManufactureMoreItemsPerHour = Options::getBool("canManufactureMoreItemsPerHour");
		int produced = std::min(getAmountProduced(), _amount) - done; // std::min is required because we don't want to overproduce
		int count = 0;
		do
		{
			if (_rules->getCategory() == "STR_CRAFT")
			{
				Craft *craft = new Craft(r->getCraft(_rules->getName()), b, g->getId(_rules->getName()));
				craft->setStatus("STR_REFUELLING");
				b->getCrafts()->push_back(craft);
			}
			else
			{
				// Check if it's ammo to reload a craft
				if (r->getItem(_rules->getName())->getBattleType() == BT_NONE)
				{
					for (std::vector<Craft*>::iterator c = b->getCrafts()->begin(); c != b->getCrafts()->end(); ++c)
					{
						if ((*c)->getStatus() != "STR_READY")
							continue;
						for (std::vector<CraftWeapon*>::iterator w = (*c)->getWeapons()->begin(); w != (*c)->getWeapons()->end(); ++w)
						{
							if ((*w) != 0 && (*w)->getRules()->getClipItem() == _rules->getName() && (*w)->getAmmo() < (*w)->getRules()->getAmmoMax())
							{
								(*w)->setRearming(true);
								(*c)->setStatus("STR_REARMING");
							}
						}
					}
				}
				if (allowAutoSellProduction && getAmountTotal() == std::numeric_limits<int>::max())
					g->setFunds(g->getFunds() + r->getItem(_rules->getName())->getSellCost());
				else
					b->getItems()->addItem(_rules->getName(), 1);
			}
			if (!canManufactureMoreItemsPerHour) break;
			count++;
			if (count < produced)
			{
				// We need to ensure that player has enough cash/item to produce a new unit
				if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
				if (!haveEnoughMaterialsForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_MATERIALS;
				startItem(b,g);
			}
		}
		while (count < produced);
	}
	if (getAmountProduced () >= _amount) return PROGRESS_COMPLETE;
	if (done < getAmountProduced ())
	{
		// We need to ensure that player has enough cash/item to produce a new unit
		if (!haveEnoughMoneyForOneMoreUnit(g)) return PROGRESS_NOT_ENOUGH_MONEY;
		if (!haveEnoughMaterialsForOneMoreUnit(b)) return PROGRESS_NOT_ENOUGH_MATERIALS;
		startItem(b,g);
	}
	return PROGRESS_NOT_COMPLETE;
}
Exemple #14
0
uint32_t DebugProtocolWriter::writeSetBegin(TType elemType, uint32_t size) {
  startItem();
  writePlain("set<{}>[{}] {{\n", fieldTypeName(elemType), size);
  pushState(SET);
  return 0;
}
Exemple #15
0
uint32_t DebugProtocolWriter::writeStructBegin(const char* name) {
  startItem();
  writePlain("{} {{\n", name);
  pushState(STRUCT);
  return 0;
}