예제 #1
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;
}
예제 #2
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;
}
예제 #3
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;
}
예제 #4
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;
}