Ejemplo n.º 1
0
/*
 * PDS is ready
 */
void	CPDSLib::ready(uint32 lastUpdateId)
{
	nlassert(_PDSConnected);

	nlinfo("PDS is ready to work");
	_PDSReady = true;

	// set up next update Id
	_UpdateId = lastUpdateId+1;

	// flush previous messages that have already been written on hd
	if ((sint)lastUpdateId >= 0)
	{
		flushAcknowledged(lastUpdateId);
	}

	// prepare PD string mapper for sheet ids
	CPDStringMapper	sheetIdStringMapper;

	std::vector<NLMISC::CSheetId>	sheetIds;
	NLMISC::CSheetId::buildIdVector(sheetIds);

	uint	i;
	for (i=0; i<sheetIds.size(); ++i)
	{
		NLMISC::CSheetId	sheetId = sheetIds[i];
		sheetIdStringMapper.setMapping(sheetId.toString(), sheetId.asInt());
	}

	CMessage	msgout("PD_SHEETID_MAPPING");
	msgout.serial(_DatabaseId);
	msgout.serial(sheetIdStringMapper);
	CUnifiedNetwork::getInstance()->send("PDS", msgout);

	// if there are still some messages in queue, resend them
	if (!_QueuedMessages.empty())
	{
		// sort them before, so they are in right order
		// this is in theory useless, since new messages are inserted at end
		std::sort(_QueuedMessages.begin(), _QueuedMessages.end(), CQueuedMessagePred());

		TQueuedMessages::iterator	it;
		for (it=_QueuedMessages.begin(); it!=_QueuedMessages.end(); ++it)
		{
			uint32	updateId = (*it).first;

			if (updateId != _UpdateId)
				nlwarning("CPDSLib::ready(): update id '%d' is not consistent with message id '%d' to be sent", _UpdateId, updateId);

			_UpdateId = updateId+1;

			NLNET::CMessage*	msg = (*it).second;
			CUnifiedNetwork::getInstance()->send("PDS", *msg);
		}
	}
}
Ejemplo n.º 2
0
//-----------------------------------------------
// isUserColorSupported :
// Test whether user color is supported for this equipment
//-----------------------------------------------
bool isUserColorSupported(const CPlayerSheet::CEquipment &equip)
{
	NLMISC::CSheetId si;
	if(!si.buildSheetId(equip.Item))
		return false;

	CItemSheet *is = dynamic_cast<CItemSheet *>(SheetMngr.get(si));
	if(!is)
		return false;

	return is->Color == -1; // user color supported by the item
}// isUserColorSupported //
Ejemplo n.º 3
0
void CSoundAnimMarker::addSound(const NLMISC::CSheetId& soundName)
{
	pair<TMarkerSoundSet::iterator, bool> inserted;
	inserted = _Sounds.insert(soundName);
	if (inserted.second == false)
	{
		nlwarning("Duplicate sound (%s)",/* CStringMapper::unmap(soundName).c_str()*/soundName.toString().c_str());
	}
}
Ejemplo n.º 4
0
//-----------------------------------------------
// getColor :
//-----------------------------------------------
sint8 getColor(const CPlayerSheet::CEquipment &equip)
{
	NLMISC::CSheetId si;
	if(!si.buildSheetId(equip.Item))
		return -2;

	CItemSheet *is = dynamic_cast<CItemSheet *>(SheetMngr.get(si));
	if(!is)
		return -2;

	if(is->Color == -1) // user color supported by the item
	{
		return equip.Color;
	}
	else
	{
		return is->Color;
	}
}// getColor //
Ejemplo n.º 5
0
//=======================================================================
sint CSheetManager::getVSIndex(const std::string &itemName, SLOTTYPE::EVisualSlot slot)
{
	NLMISC::CSheetId si;
	if (!si.buildSheetId(itemName))
	{
		nlwarning("<CSheetManager::getVSIndex> : cannot build id from item %s for the slot %d.", itemName.c_str(), slot);
		return -1;
	}

	TEntitySheetMap::iterator it =  _EntitySheetContainer.find(si);;
	if (it == _EntitySheetContainer.end())
	{
		nlwarning("<CSheetManager::getVSIndex> : cannot find %s for the slot %d.", itemName.c_str(), slot);
		return -1;
	}
	if (it->second.EntitySheet == 0 || it->second.EntitySheet->type() != CEntitySheet::ITEM)
	{
		nlwarning("<CSheetManager::getVSIndex> : %s is not an item for the slot %d.", itemName.c_str(), slot);
		return -1;
	}

	CItemSheet *is = static_cast<CItemSheet *>(it->second.EntitySheet);

	const TVisualSlotItemArray *ia = getVSItems(is);
	if (ia == NULL)
	{
		nlwarning("<CSheetManager::getVSIndex> : no items for the slot %d. while looking for %s", slot, itemName.c_str());
		return -1;
	}

	TVisualSlotItemArray::const_iterator first(ia->begin()), last(ia->end());
	for(; first != last; ++first)
	{
		if (first->first == slot)
		{
			return first->second;
		}
	}

	nlwarning("<CSheetManager::getVSIndex> : cannot find %s for the slot %d.", itemName.c_str(), slot);
	return -1;
}
Ejemplo n.º 6
0
void CSoundAnimMarker::removeSound(const NLMISC::CSheetId &soundName)
{
	TMarkerSoundSet::iterator iter = _Sounds.find(soundName);
    if (iter != _Sounds.end())
	{
		_Sounds.erase(iter);
	}
	else
	{
		nlwarning("No sound was removed (%s)", soundName.toString().c_str()/*CStringMapper::unmap(soundName).c_str()*/);
	}
}
bool CRingAccess::isSheetClient(const NLMISC::CSheetId& sheet) const
{

	static const std::string racesStr[] = { "matis_", "fyros_", "tryker_", "zorai_"};
	static const uint32 racesLen[] = { 6, 6, 7 ,6 };
	static const std::string sexsStr[] = { "male", "female"};
	static const uint32 sexsLen[] = { 4, 6};
	static const std::string basic = "basic_";
	static const uint32 basicLength = 6;


	std::string sheetStr = sheet.toString();
	uint32 sheetLength = (uint32)sheetStr.length();



	if (sheetLength >= basicLength && sheetStr.substr(0, basicLength) == basic)
	{
		// good thing is a basic_* something
		for (uint32 i = 0; i < 4 ; ++i)
		{
			const uint32 raceLength = racesLen[i];
			if (  sheetLength > basicLength + raceLength && sheetStr.substr(basicLength, raceLength) ==  racesStr[i])
			{

				// good thing is a basic_race_
				for (uint32 j = 0; j < 2 ; ++j)
				{
					uint32 sexLength = sexsLen[j];
					if (sheetLength > basicLength + raceLength + sexLength && sheetStr.substr(basicLength + raceLength, sexLength)  == sexsStr[j])
					{
						return true;
					}
				}
			}
		}
	}

	return false;
}
Ejemplo n.º 8
0
/*
 * Spawn the source as an entity in mirror. Return false in case of failure.
 */
bool CToxicCloud::spawn( const NLMISC::CSheetId &sheet )
{
	// Add into mirror
	CEntityId entityId = CEntityId::getNewEntityId( RYZOMID::fx_entity );
	if ( ! Mirror.createEntity( entityId ) )
		return false;
	_DataSetRow = TheDataset.getDataSetRow( entityId );

	// Set the sheet id
	CMirrorPropValue<TYPE_SHEET> sheetMirror( TheDataset, _DataSetRow, DSPropertySHEET );
	sheetMirror = sheet.asInt();

	// Set the initial position
	CMirrorPropValue<TYPE_POSX> posX( TheDataset, _DataSetRow, DSPropertyPOSX );
	CMirrorPropValue<TYPE_POSY> posY( TheDataset, _DataSetRow, DSPropertyPOSY );
	posX = (TYPE_POSX)(_Pos.x * 1000.0f);
	posY = (TYPE_POSY)(_Pos.y * 1000.0f);

	// Set the mode
	MBEHAV::TMode md;
	md.setModeAndPos( MBEHAV::NORMAL, _DataSetRow );
	CMirrorPropValue<MBEHAV::TMode> mode( TheDataset, _DataSetRow, DSPropertyMODE );
	mode = md;

	// Set the WhoSeesMe bitfield (every bit set to 1)
	const uint64 bitfield = IsRingShard? R2_VISION::buildWhoSeesMe(R2_VISION::WHOSEESME_VISIBLE_PLAYER,true): UINT64_CONSTANT(0xffffffffffffffff);
	CMirrorPropValue<TYPE_WHO_SEES_ME> whoSeesMe(TheDataset, _DataSetRow, DSPropertyWHO_SEES_ME );
	whoSeesMe = bitfield;

	// Contextual properties init
	CMirrorPropValue<TYPE_CONTEXTUAL> contextualProperties(TheDataset, _DataSetRow, DSPropertyCONTEXTUAL );
	contextualProperties = 0;

	TheDataset.declareEntity( _DataSetRow );
	return true;
}
Ejemplo n.º 9
0
void CMirrors::initSheetServer( const TDataSetRow& entityIndex, const NLMISC::CSheetId& sheetId )
{
	nlassert(sheetId != NLMISC::CSheetId::Unknown);
	CMirrorPropValue<TYPE_SHEET> value( *DataSet, entityIndex, DSPropertySHEET_SERVER );
	value = sheetId.asInt();
}
Ejemplo n.º 10
0
void CMirrors::initSheet( const TDataSetRow& entityIndex, const NLMISC::CSheetId& sheetId )
{
	CMirrorPropValue<TYPE_SHEET> value( *DataSet, entityIndex, DSPropertySHEET );
	value = sheetId.asInt();
}
Ejemplo n.º 11
0
//***************************************************************
std::string CToolCreateEntity::cloneEntityIntoScenario(CEntityCL *clonee,
												const NLMISC::CVector &createPosition,
												float createAngle,
												bool  newAction,
												bool  createGhost
											   )
{
	//H_AUTO(R2_CToolCreateEntity_cloneEntityIntoScenario)
	if (!clonee) return "";
	std::string instanceId;
	bool isBotObject = isBotObjectSheet(clonee->sheetId());

	if (!getEditor().verifyRoomLeft(isBotObject ? 0 : 1, isBotObject ? 1 : 0)) { return ""; }

	std::string className;
	// if class is given in the palette node, then use it. Default to 'Npc' else
	CObject *paletteNode = getDMC().getPaletteElement(_PaletteId);
	if (paletteNode && paletteNode->findIndex("Class") != -1)
	{
		className = getString(paletteNode, "Class");
	}
	if (className.empty())
	{
		className = "Npc";
	}

	ucstring readableName;
	// retrieve name from the palette id
	CLuaState &ls = getEditor().getLua();
	getEditor().getEnv()["PaletteIdToTranslation"][_PaletteId].push();
	if (ls.isString(-1))
	{
		readableName.fromUtf8(ls.toString(-1));
	}
	if (readableName.empty())
	{
		// if no name found then give a default one
		readableName = CI18N::get(isBotObject ? "uiR2EDNameBotObject" : "uiR2EDNameNPC");
	}

	// except for creatures, posfix the name with a number
	std::string creaturePaletteRoot = "palette.entities.creatures";
	if (_PaletteId.substr(0, creaturePaletteRoot.size()) != creaturePaletteRoot)
	{
		readableName = getEditor().genInstanceName(readableName);
	}
	else
	{
		className = "NpcCreature";

		// is Plant
		std::string sheetClient = getString(paletteNode, "SheetClient");
		getEditor().getLua().push(sheetClient);
		if (getEditor().getEnv().callMethodByNameNoThrow("isNPCPlant", 1, 1))
		{
			CLuaObject result(getEditor().getLua());
			bool isPlant = result.toBoolean();
			if (isPlant)
				className = "NpcPlant";
		}
	}

	if (newAction)
	{
		getDMC().newAction(NLMISC::CI18N::get("uiR2EDCreateAction") + readableName);
	}
	// send network commands to create entity on server
	std::auto_ptr<CObject> desc(getDMC().newComponent(className));

	if (desc.get())
	{
		// TMP FIX : if the created entity is a custom npc, then retrieve look from the clonee visual properties
		if (className == "NpcCustom")
		{
			SPropVisualA vA;
			SPropVisualB vB;
			SPropVisualC vC;
			const string propNameA = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPA);
			const string propNameB = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPB);
			const string propNameC = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPC);
			CCDBNodeLeaf *leafA = CInterfaceManager::getInstance()->getDbProp(propNameA);
			CCDBNodeLeaf *leafB = CInterfaceManager::getInstance()->getDbProp(propNameB);
			CCDBNodeLeaf *leafC = CInterfaceManager::getInstance()->getDbProp(propNameC);
			if (!leafA)
			{
				nlwarning("Can't find DB leaf %s", propNameA.c_str());
				return "";
			}
			if (!leafB)
			{
				nlwarning("Can't find DB leaf %s", propNameB.c_str());
				return "";
			}
			if (!leafC)
			{
				nlwarning("Can't find DB leaf %s", propNameC.c_str());
				return "";
			}

			vA.PropertyA = leafA->getValue64();
			vB.PropertyB = leafB->getValue64();
			vC.PropertyC = leafC->getValue64();
			nlassert(desc->isTable());
			CObjectTable *props = (CObjectTable *) desc.get();

			props->set("GabaritHeight",     (double)vC.PropertySubData.CharacterHeight);
			props->set("GabaritTorsoWidth", (double)vC.PropertySubData.TorsoWidth);
			props->set("GabaritArmsWidth",  (double)vC.PropertySubData.ArmsWidth);
			props->set("GabaritLegsWidth",  (double)vC.PropertySubData.LegsWidth);
			props->set("GabaritBreastSize", (double)vC.PropertySubData.BreastSize);

			props->set("HairColor", (double)vA.PropertySubData.HatColor);
			props->set("Tattoo",    (double)vC.PropertySubData.Tattoo);
			props->set("EyesColor", (double)vC.PropertySubData.EyesColor);

			props->set("MorphTarget1", (double)vC.PropertySubData.MorphTarget1);
			props->set("MorphTarget2", (double)vC.PropertySubData.MorphTarget2);
			props->set("MorphTarget3", (double)vC.PropertySubData.MorphTarget3);
			props->set("MorphTarget4", (double)vC.PropertySubData.MorphTarget4);
			props->set("MorphTarget5", (double)vC.PropertySubData.MorphTarget5);
			props->set("MorphTarget6", (double)vC.PropertySubData.MorphTarget6);
			props->set("MorphTarget7", (double)vC.PropertySubData.MorphTarget7);
			props->set("MorphTarget8", (double)vC.PropertySubData.MorphTarget8);

			props->set("Sex", (double)vA.PropertySubData.Sex);

			CVisualSlotManager * vsManager = CVisualSlotManager::getInstance();
			NLMISC::CSheetId * sheetId = NULL;

			if(vA.PropertySubData.HatModel == 0)
			{
				props->set("HatModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.HatModel, SLOTTYPE::HEAD_SLOT);
				if (sheetId)
				{
					props->set("HairType",  (double)sheetId->asInt());
				}
			}

			if(vA.PropertySubData.JacketModel == 0)
			{
				props->set("JacketModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.JacketModel, SLOTTYPE::CHEST_SLOT);
				if (sheetId)
				{
					props->set("JacketModel",  (double)sheetId->asInt());
				}
			}

			if(vA.PropertySubData.TrouserModel == 0)
			{
				props->set("TrouserModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.TrouserModel, SLOTTYPE::LEGS_SLOT);
				if (sheetId)
				{
					props->set("TrouserModel",  (double)sheetId->asInt());
				}
			}

			if(vB.PropertySubData.FeetModel == 0)
			{
				props->set("FeetModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vB.PropertySubData.FeetModel, SLOTTYPE::FEET_SLOT);
				if (sheetId)
				{
					props->set("FeetModel",  (double)sheetId->asInt());
				}
			}

			if(vB.PropertySubData.HandsModel == 0)
			{
				props->set("HandsModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vB.PropertySubData.HandsModel, SLOTTYPE::HANDS_SLOT);
				if (sheetId)
				{
					props->set("HandsModel",  (double)sheetId->asInt());
				}
			}

			if(vA.PropertySubData.ArmModel == 0)
			{
				props->set("ArmModel", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.ArmModel, SLOTTYPE::ARMS_SLOT);
				if (sheetId)
				{
					props->set("ArmModel",  (double)sheetId->asInt());
				}
			}

			double weaponRH=0, weaponLH=0;
			if(vA.PropertySubData.WeaponRightHand == 0)
			{
				props->set("WeaponRightHand", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.WeaponRightHand, SLOTTYPE::RIGHT_HAND_SLOT);
				if (sheetId)
				{
					weaponRH = (double)sheetId->asInt();
				}
				props->set("WeaponRightHand",  weaponRH);
			}

			if(vA.PropertySubData.WeaponLeftHand == 0)
			{
				props->set("WeaponLeftHand", 0);
			}
			else
			{
				sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.WeaponLeftHand, SLOTTYPE::LEFT_HAND_SLOT);
				if (sheetId)
				{
					weaponLH = (double)sheetId->asInt();
				}
				props->set("WeaponLeftHand",  weaponLH);
			}

			props->set("JacketColor", (double)vA.PropertySubData.JacketColor);
			props->set("TrouserColor", (double)vA.PropertySubData.TrouserColor);
			props->set("FeetColor", (double)vB.PropertySubData.FeetColor);
			props->set("HandsColor", (double)vB.PropertySubData.HandsColor);
			props->set("ArmColor", (double)vA.PropertySubData.ArmColor);

			CPlayerR2CL * player = (CPlayerR2CL*)dynamic_cast<CPlayerR2CL*>(clonee);
			if(player != NULL)
			{
				std::string race, gender, sheetClient;
				switch(player->people())
				{
				case EGSPD::CPeople::Fyros:
					sheetClient = "basic_fyros_";
					race = "Fyros";
					break;

				case EGSPD::CPeople::Matis:
					sheetClient = "basic_matis_";
					race = "Matis";
					break;

				case EGSPD::CPeople::Tryker:
					sheetClient = "basic_tryker_";
					race = "Tryker";
					break;

				case EGSPD::CPeople::Zorai:
					sheetClient = "basic_zorai_";
					race = "Zorai";
					break;

				default:
					nlwarning("CToolCreateEntity::commit unknown people");
				}
				switch(player->getGender())
				{
				case GSGENDER::female:
					sheetClient = sheetClient+"female.creature";
					gender = "female";
					break;

				case GSGENDER::male:
					sheetClient = sheetClient+"male.creature";
					gender = "male";
					break;

				default:
					nlwarning("CToolCreateEntity::commit unknown gender");
				}

				props->set("SheetClient", sheetClient);

				// random name
				getEditor().getLua().push(race);
				getEditor().getLua().push(gender);
				if (getEditor().getEnv().callMethodByNameNoThrow("randomNPCName", 2, 1))
				{
					CLuaObject result(getEditor().getLua());
					std::string name = result.toString();
					props->set("Name", name);
				}
			}

			getEditor().getLua().push(getString(paletteNode, "Equipment"));
			getEditor().getLua().push(weaponRH);
			getEditor().getLua().push(weaponLH);
			getEditor().getLua().push(getString(paletteNode, "Sheet"));
			getEditor().getLua().push(getString(paletteNode, "SheetModel"));
			if (getEditor().getEnv().callMethodByNameNoThrow("searchSheet", 5, 1))
			{
				CLuaObject result(getEditor().getLua());
				std::string sheet = result.toString();
				props->set("Sheet", sheet);
			}
			else
			{
				nlwarning("SearchSheet failed : Palette Id = %s", _PaletteId.c_str());
				return "";
			}
		}
		else
		{
			desc->set("Name", readableName.toUtf8());
		}

		desc->set("Base", _PaletteId);
		desc->setObject("Position", buildVector(CVectorD(createPosition)));
		desc->set("Angle", createAngle);
		//desc->set("Name", readableName.toUtf8());

		instanceId = getString(desc.get(), "InstanceId");
		if (!instanceId.empty())
		{
			if (!createGhost)
			{
				// selection asked when instance is created
				getEditor().setCookie(instanceId, "Select", true);
			}
			else
			{
				getEditor().setCookie(instanceId, "GhostDuplicate", true);
			}
		}

		// send creation command
		// tmp : static npc counter
		// add in component list of default feature
		if (getEditor().getDefaultFeature())
		{
			std::string targetInstanceId;
			// if object is a bot object, it is considered to be permanent content
			// and should be created in the base act
			CInstance *targetAct =  isBotObject ? getEditor().getBaseAct() : getEditor().getCurrentAct();
			if (!targetAct)
			{
				nlwarning("Can't find act when creating an entity");
			}
			else
			{
				if (_AutoGroup.getGroupingCandidate())
				{
					nlassert(!createGhost); // either autogroup or arraymode, both at the same time not supported
					_AutoGroup.group(desc.get(), createPosition);
				}
				else
				{
					// create standalone
					desc->setGhost(createGhost);
					getDMC().requestInsertNode(getEditor().getDefaultFeature(targetAct)->getId(),
											   "Components",
											   -1,
											   "",
											   desc.get());
				}
			}
		}
	}
	return instanceId;
}
Ejemplo n.º 12
0
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	// create a system crafted item
	static CGameItemPtr createSystemCraftedItem( uint16 quantity, const NLMISC::CSheetId& sheet )
	{
		if (quantity == 0) return NULL;
		
		// if quantity > 1, check if item is stackable and check stack quantity
		if (quantity > 1)
		{
			const CStaticItem* form = CSheets::getForm( sheet );
			if( form )
			{
				if( form->Stackable < quantity )
				{
					quantity = (uint16) form->Stackable;
				}
			}
			else
			{
				nlwarning("<CFaberActionCommon::createACraftedItem> can't found form for item %s", sheet.toString().c_str());
			}
		}
		
		if (quantity > 1)
		{
			CSheetId idSheetStack("stack.sitem");
			CGameItemPtr stackItem = GameItemManager.createItem( idSheetStack, (uint16)1, CEntityId::Unknown, (sint16)0, false, CEntityId::Unknown );
			if( stackItem == NULL )
			{
				nlwarning("<CFaberActionCommon::createACraftedItem> Error while creating stack bag %s -> returned a NULL pointer", idSheetStack.toString().c_str() );
				return NULL;
			}
			else
			{
				uint32 hp = 0;
				uint32 hpmax = 0;
				for( int q = 0; q < quantity; ++q )
				{
					CGameItemPtr itemTmp = GameItemManager.createItem( const_cast< CSheetId& > ( sheet ), 1, const_cast<NLMISC::CEntityId&>(stackItem->getId()), (sint16)-1, true, CEntityId::Unknown );
					if (!hp && itemTmp != NULL)
					{
						hp = itemTmp->hp();
						hpmax = itemTmp->standardHP();
					}
				}
				return stackItem;	
			}
		}
		else // do not create a stack, as there is only one object
		{
			CGameItemPtr item = GameItemManager.createItem( const_cast< CSheetId& > ( sheet ), (uint16)1, CEntityId::Unknown, (sint16)0, true, CEntityId::Unknown  );
			if( item == NULL)
			{
				nlwarning("<CFaberActionCommon::createACraftedItem> Error while creating item %s -> returned a NULL pointer", sheet.toString().c_str() );
				return NULL;
			}
			return item;
		}
	} // createSystemCraftedItem //
Ejemplo n.º 13
0
//-----------------------------------------------
// CStaticLightCycle readGeorges
//-----------------------------------------------
void CStaticLightCycle::readGeorges( const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const NLMISC::CSheetId &sheetId )
{
	if( form )
	{
		UFormElm& root = form->getRootNode();

		vector< string > season;
		season.push_back( string("Spring") );
		season.push_back( string("Summer") );
		season.push_back( string("Autumn") );
		season.push_back( string("Winter") );

		uint NbSeasons = 4;
		LightCycles.resize( NbSeasons );

		for( uint i = 0; i < NbSeasons; ++i )
		{
			UFormElm* SeasonElt = NULL;
			if( ! ( root.getNodeByName( &SeasonElt, season[ i ].c_str() ) && SeasonElt ) )
			{
				nlwarning("<CStaticLightCycle readGeorges> can get node %s in sheet %s", season[ i ].c_str(), sheetId.toString().c_str() );
			}
			else
			{
				// Day hour
				if( ! SeasonElt->getValueByName( LightCycles[ i ].DayHour, "DayHour" ) )
				{
					nlwarning("<CStaticLightCycle readGeorges> can get value DayHour in node %d on SeasonElt structure in sheet %s", i, sheetId.toString().c_str() );
				}

				// Day to dusk hour
				if( ! SeasonElt->getValueByName( LightCycles[ i ].DayToDuskHour, "DayToDuskHour" ) )
				{
					nlwarning("<CStaticLightCycle readGeorges> can get value DayToDuskHour in node %d on SeasonElt structure in sheet %s", i, sheetId.toString().c_str() );
				}

				// Dusk to night hour
				if( ! SeasonElt->getValueByName( LightCycles[ i ].DuskToNightHour, "DuskToNightHour" ) )
				{
					nlwarning("<CStaticLightCycle readGeorges> can get value DuskToNightHour in node %d on SeasonElt structure in sheet %s", i, sheetId.toString().c_str() );
				}

				// Night hour
				if( ! SeasonElt->getValueByName( LightCycles[ i ].NightHour, "NightHour" ) )
				{
					nlwarning("<CStaticLightCycle readGeorges> can get value NightHour in node %d on SeasonElt structure in sheet %s", i, sheetId.toString().c_str() );
				}

				// Night to day hour
				if( ! SeasonElt->getValueByName( LightCycles[ i ].NightToDayHour, "NightToDayHour" ) )
				{
					nlwarning("<CStaticLightCycle readGeorges> can get value NightToDayHour in node %d on SeasonElt structure in sheet %s", i, sheetId.toString().c_str() );
				}
			}
		}
	}
}// CStaticLightCycle readGeorges
Ejemplo n.º 14
0
//-----------------------------------------------
// CFaberPhrase systemCraftItem:
//-----------------------------------------------
CGameItemPtr CFaberPhrase::systemCraftItem( const NLMISC::CSheetId& sheet, const std::vector< NLMISC::CSheetId >& Mp, const std::vector< NLMISC::CSheetId >& MpFormula )
{
	H_AUTO(CFaberPhrase_systemCraftItem);

	std::vector< const CStaticBrick* > bricks;
	_RootFaberPlan = CSheets::getSBrickForm( sheet );
	const CStaticBrick * rootFaberBricks = CSheets::getSBrickForm( CSheetId("bcpa01.sbrick") );
	if( rootFaberBricks )
	{
		_RootFaberBricks = true;
	}
	else
	{
		nlwarning("<CFaberPhrase::systemCraftItem> Can't found form of root faber brick bcpa01.sbrick");
		return 0;
	}

	CGameItemPtr craftedItem = 0;

	if( _RootFaberPlan && _RootFaberPlan->Faber )
	{
		_CraftedItemStaticForm = CSheets::getForm( _RootFaberPlan->Faber->CraftedItem );
		if( _CraftedItemStaticForm == 0 )
		{
			return 0;
		}

		bricks.push_back( rootFaberBricks );
		bricks.push_back( _RootFaberPlan );

		for( vector< NLMISC::CSheetId >::const_iterator it = Mp.begin(); it != Mp.end(); ++it )
		{
			const CStaticItem * mp = CSheets::getForm( (*it) );
			if( mp == 0 )
			{
				nlwarning("<CFaberPhrase::systemCraftItem> Can't found form for Mp %s for craft %s item", (*it).toString().c_str(), sheet.toString().c_str() );
				return 0;
			}
			_Mps.push_back( mp );
		}

		// Check quantity of gived Mps
		if( _RootFaberPlan->Faber->NeededMps.size() > _Mps.size() )
		{
			nlwarning("<CFaberPhrase::systemCraftItem> Not enought gived RM for crafting %s (gived Mp %d, Needed Mp %d)", sheet.toString().c_str(), _Mps.size(), _RootFaberPlan->Faber->NeededMps.size() );
			return 0;
		}

		for( vector< NLMISC::CSheetId >::const_iterator it = MpFormula.begin(); it != MpFormula.end(); ++it )
		{
			const CStaticItem * mp = CSheets::getForm( (*it) );
			if( mp == 0 )
			{
				nlwarning("<CFaberPhrase::systemCraftItem> Can't found form for Mp Formula %s for craft %s item", (*it).toString().c_str(), sheet.toString().c_str() );
				return 0;
			}
			_MpsFormula.push_back( mp );
		}

		// Check quantity of gived Mps formula
		if( _RootFaberPlan->Faber->NeededMpsFormula.size() > _MpsFormula.size() )
		{
			nlwarning("<CFaberPhrase::systemCraftItem> Not enought gived RM formula for crafting %s (gived Mp %d, Needed Mp %d)", sheet.toString().c_str(), _MpsFormula.size(), _RootFaberPlan->Faber->NeededMpsFormula.size() );
			return 0;
		}

		// build the craft action
		_FaberAction = IFaberActionFactory::buildAction( _ActorRowId, this, _CraftedItemStaticForm->Type );
		if ( !_FaberAction )
		{
			nlwarning( "<CFaberPhrase build> could not build action for root faber %s", _RootFaberPlan->SheetId.toString().c_str() );
			return 0;
		}
		_FaberAction->systemApply(this);
		if( _CraftedItem != 0 )
		{
			_CraftedItem->setDefaultColor();
		}
		craftedItem = _CraftedItem;
		_CraftedItem = 0;
	}
	return craftedItem;
} // systemCraftItem //
Ejemplo n.º 15
0
//-----------------------------------------------
// createInGameItem
//-----------------------------------------------
CGameItemPtr CGameItemManager::createInGameItem( uint16 quality, uint32 quantity, const NLMISC::CSheetId &sheet, const CEntityId &creatorId , const std::string * phraseId)
{
	H_AUTO(GIM_createInGameItem);

	static const CSheetId preorderSheetId("pre_order.sitem");
	
	if ( quantity == 0 || quality ==0 )
		return NULL;

//	static const CSheetId idSheetStack("stack.sitem");
	const CStaticItem* form = CSheets::getForm( sheet );
	if (!form)
	{
		nlwarning("<CCharacter::createInGameItem> Cannot find form of item %s", sheet.toString().c_str());
		return NULL;
	}

	CGameItemPtr item;
	CGameItemPtr sellingItem;
	// if item can be sold, get it in the sold items list
	if (	form->Family != ITEMFAMILY::RAW_MATERIAL 
		&&	form->Family != ITEMFAMILY::HARVEST_TOOL
		&&	form->Family != ITEMFAMILY::CRAFTING_TOOL
		&&	form->Family != ITEMFAMILY::CRYSTALLIZED_SPELL
		&&	form->Family != ITEMFAMILY::ITEM_SAP_RECHARGE
		&&	form->Family != ITEMFAMILY::FOOD
		)
	{
		vector< CGameItemPtr >::const_iterator it;
		const vector< CGameItemPtr >::const_iterator itEnd = CStaticItems::getStaticItems().end();
		for( it = CStaticItems::getStaticItems().begin(); it != itEnd; ++it )
		{
			if( (*it)->getSheetId() == sheet )
			{
				sellingItem = *it;
				break;
			}
		}
	}

	switch( form->Family )
	{
		case ITEMFAMILY::CRAFTING_TOOL:
		case ITEMFAMILY::HARVEST_TOOL:
		case ITEMFAMILY::RAW_MATERIAL:
		case ITEMFAMILY::TELEPORT:
		case ITEMFAMILY::CRYSTALLIZED_SPELL:
		case ITEMFAMILY::ITEM_SAP_RECHARGE:
		case ITEMFAMILY::MISSION_ITEM:
		case ITEMFAMILY::PET_ANIMAL_TICKET:
		case ITEMFAMILY::HANDLED_ITEM:
		case ITEMFAMILY::CONSUMABLE:
		case ITEMFAMILY::XP_CATALYSER:
		case ITEMFAMILY::SCROLL:
		case ITEMFAMILY::FOOD:
		case ITEMFAMILY::SCROLL_R2:
		case ITEMFAMILY::GENERIC_ITEM:
		{
			item = GameItemManager.createItem( const_cast< CSheetId& > ( sheet ), quality, true, true, creatorId);
		}
		break;
	default:
		{
			if( sellingItem != NULL )
			{
				item = sellingItem->getItemCopy();
				item->quality( quality );
				if ( phraseId )
					item->setPhraseId(*phraseId);
			}
			else if (sheet == preorderSheetId)
			{
				item = GameItemManager.createItem(sheet, quality, true, form->DropOrSell, creatorId);
			}
		}
		if( item == NULL)
		{
			nlwarning("<CCharacter::createInGameItem> Error while creating item : NULL pointer");
			return NULL;
		}
	}
	quantity = min(quantity, item->getMaxStackSize());
	item->setStackSize(quantity);
	return item;
} // createInGameItem //
Ejemplo n.º 16
0
//--------------------------------------------------------------
//						loadFromGeorges()  
//--------------------------------------------------------------
void CStaticHarvestable::loadFromGeorges( const UForm &form, const NLMISC::CSheetId &sheetId )
{	
	_Mps.clear();
/*
//	getVarListFromParents	(&form, arrayList,	"Harvest");

	std::set<NLGEORGES::UFormElm*>	arrayList;
	{
		NLGEORGES::UFormElm	*tmpelem=NULL;
		const_cast<NLGEORGES::UFormElm*>(&form.getRootNode())->getNodeByName(&tmpelem, "Harvest");
		if (tmpelem)
		{
			arrayList.insert(tmpelem);
		}
	}

	if (arrayList.empty())
	{
		return;
	}

	for	(std::set<NLGEORGES::UFormElm*>::iterator	it=arrayList.begin(), itEnd=arrayList.end(); it!=itEnd;++it)
	{
		NLGEORGES::UFormElm	*elem=*it;
*/
		{
			string value;
			if	(	form.getRootNode().getValueByName( value, (string("Harvest.")+"Skill").c_str() )
				&&	!value.empty()	)
			{
				_HarvestSkill = SKILLS::toSkill( value );
			}

		}

		// in Georges sheet MP starts with MP1 and ends with MP10
		if (VerboseQuartering)
			nldebug("QRTR: Loading RMs of creatures %s", sheetId.toString().c_str());
		for (uint i = 1 ; i <= NbRawMaterials ; ++i)
		{
			const string mpName=NLMISC::toString("MP%u",i);
			CStaticCreatureRawMaterial	mp;
			
			if( form.getRootNode().getValueByName( mp.MpCommon.AssociatedItemName, ("Harvest." +mpName+".AssociatedItem").c_str())
				&& !mp.MpCommon.AssociatedItemName.empty() )
			{
				if (VerboseQuartering)
					nldebug("QRTR: %s=%s", mpName.c_str(), mp.MpCommon.AssociatedItemName.c_str());

				form.getRootNode().getValueByName( mp.MpCommon.Name,		("Harvest." +mpName+".Name").c_str()			);
				uint16 sheetQuantity;
				form.getRootNode().getValueByName( sheetQuantity,			("Harvest." +mpName+".Quantity").c_str()		);
				if ( sheetQuantity != 0 )
				{
					nlwarning( "Quantity set to %hu in %s", sheetQuantity, sheetId.toString().c_str() );
				}
				form.getRootNode().getValueByName( mp.MpCommon.MinQuality,	("Harvest." +mpName+".MinQuality").c_str()		);
				form.getRootNode().getValueByName( mp.MpCommon.MaxQuality,	("Harvest." +mpName+".MaxQuality").c_str()		);
	//			harvest->getValueByName( mp.PresenceProbabilities,	(mpName+".PresenceProbabilities").c_str()	);

				mp.ItemId = mp.MpCommon.AssociatedItemName;
				if ( mp.MpCommon.MinQuality == 0)
					mp.MpCommon.MinQuality = 1;
				if ( mp.MpCommon.MaxQuality == 0)
					mp.MpCommon.MaxQuality = 5;
				/// end temp hack

				const CStaticItem *staticItem = CSheets::getForm( mp.ItemId );
				if ( staticItem )
				{
					string itemSheetCode = mp.ItemId.toString();

					// Identify the usage of the RM (if it is a raw material for mission or craft) or fixed quantity (for invasion reward)
					if ( ( itemSheetCode.find( "ixx" ) != string::npos) ||
						 ( itemSheetCode.find( "cxx" ) != string::npos ) )
					{
						if (VerboseQuartering)
							nldebug("QRTR: For invasions");

						if( itemSheetCode == "m0077ixxcc01.sitem" )
						{
							mp.UsageAndQuantity.Usage = (uint16)RMUTotalQuantity;
							mp.UsageAndQuantity.QuantityVar = (TRMQuantityVariable)(RMQVForceBase+5);
						}
						else
						{
							// Invasion/goo raw material: fixed quantity, depending on creature local level
							//nldebug( "%s/%s: fixed quantity", sheetId.toString().c_str(), itemSheetCode.c_str() );
							mp.UsageAndQuantity.Usage = (uint16)RMUFixedQuantity;
							string creatureCode = sheetId.toString();
							uint16 creatureLocalLevel;
							form.getRootNode().getValueByName( creatureLocalLevel, "Basics.LocalCode" );
							if ( itemSheetCode.size() >= 12 )
							{
								uint itemVariant = (uint)(itemSheetCode[11] - '0');
								switch ( itemVariant )
								{
								case 1:
									if ( creatureLocalLevel < 5 )
										mp.UsageAndQuantity.QuantityVar = (TRMQuantityVariable)(RMQVForceBase+(uint)creatureLocalLevel) ;
									else if ( creatureLocalLevel < 7 )
										mp.UsageAndQuantity.QuantityVar = RMQVInvasion5;
									else if ( creatureLocalLevel < 9 )
										mp.UsageAndQuantity.QuantityVar = RMQVInvasion7;
									else
									{
										nlwarning( "Invalid creature local level in %s", creatureCode.c_str() );
										mp.UsageAndQuantity.QuantityVar = RMQVForceBase; // 0
									}
									break;
								case 2:
									if ( creatureLocalLevel < 5 )
										mp.UsageAndQuantity.QuantityVar = RMQVForceBase; // 0
									else if ( creatureLocalLevel < 7 )
										mp.UsageAndQuantity.QuantityVar = (TRMQuantityVariable)(RMQVForceBase+1) ;
									else if ( creatureLocalLevel < 9 )
										mp.UsageAndQuantity.QuantityVar = (TRMQuantityVariable)(RMQVForceBase+3) ;
									else
									{
										nlwarning( "Invalid creature local level in %s", creatureCode.c_str() );
										mp.UsageAndQuantity.QuantityVar = RMQVForceBase; // 0
									}
									break;
								default:;
								}
							}
						}
						//nldebug( "Creature: %s, RM: %s, Quantity: %hu", creatureCode.c_str(), itemSheetCode.c_str(), mp.UsageAndQuantity.Quantity );

						// Add item only if it has not a 0 fixed-quantity
						if ( mp.quantityVariable() >= NBRMQuantityVariables )
							nlwarning( "Invalid quantity variable" );
						else if ( mp.quantityVariable() != RMQVForceBase )
							_Mps.push_back( mp );
						else
						{
							if (VerboseQuartering)
								nldebug("QRTR: Qtty=0, not added");
						}

					}
					else if ( staticItem->Mp && (! staticItem->Mp->MpFaberParameters.empty()) )
					{
						if (VerboseQuartering)
							nldebug("QRTR: For craft");

						// Raw material for craft
						mp.UsageAndQuantity.Usage = (uint16)RMUTotalQuantity;
						uint16 creatureLocalLevel;
						form.getRootNode().getValueByName( creatureLocalLevel, "Basics.LocalCode" );
						if ( creatureLocalLevel < 5 )
						{
							// Identify the type of creature
							if ( (itemSheetCode.size() > 7) &&
								((itemSheetCode[6]=='h') || (itemSheetCode[6]=='b') || (itemSheetCode[6]=='p')) )
							{
								mp.UsageAndQuantity.QuantityVar = RMQVHerbivore;
							}
							else
							{
								mp.UsageAndQuantity.QuantityVar = RMQVCarnivore;
							}
						}
						else
						{
							switch ( creatureLocalLevel )
							{
							case 5:
							case 8:
								mp.UsageAndQuantity.QuantityVar = RMQVBoss5;
								break;
							case 7:
								mp.UsageAndQuantity.QuantityVar = RMQVBoss7;
								break;
							default: // 6 and non-nomenclatured sheets
								mp.UsageAndQuantity.QuantityVar = RMQVForceBase;
							}
						}

						// Add item only if it has not a 0 fixed-quantity
						if ( mp.quantityVariable() >= NBRMQuantityVariables )
							nlwarning( "Invalid quantity variable" );
						else if ( mp.quantityVariable() != RMQVForceBase )
							_Mps.push_back( mp );
						else
						{
							if (VerboseQuartering)
								nldebug("QRTR: Qtty=0, not added");
						}
					}
					else
					{
						if (VerboseQuartering)
							nldebug("QRTR: For missions");

						// Raw material or item for mission
						_ItemsForMissions.push_back( mp.ItemId );
					}
				}
				else
				{
					// Cancel adding if item not found
					if (VerboseQuartering)
						nldebug("QRTR: %s not found", mp.MpCommon.AssociatedItemName.c_str());
				}
			}

		}

//	}

} // loadFromGeorges //
Ejemplo n.º 17
0
// ***************************************************************************
void CSheetManagerEntry::readGeorges (const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const NLMISC::CSheetId &sheetId)
{
	// Load the form with given sheet id
	if (form)
	{
//		if (EntitySheet != NULL)
//			delete EntitySheet;

		CEntitySheet *sheet = NULL;

		std::string extension = NLMISC::CSheetId::fileExtensionFromType(sheetId.getSheetType());

		// create the new structure
		if (extension == "creature")
			sheet = new CCharacterSheet;
		else if(extension == "player")
			sheet = new CPlayerSheet;
		else if(extension == "fx")
			sheet = new CFXSheet;
		else if(extension == "building")
			sheet = new CBuildingSheet;
		else if(extension == "sitem" || extension == "item" )
			sheet = new CItemSheet;
		else if(extension == "plant")
			sheet = new CPlantSheet;
		else if(extension == "death_impact")
			sheet = new CPactSheet;
		else if(extension == "mission")
			sheet = new CMissionSheet;
		else if(extension == "race_stats")
			sheet = new CRaceStatsSheet;
		else if(extension == "light_cycle")
			sheet = new CLightCycleSheet;
		else if(extension == "weather_setup")
			sheet = new CWeatherSetupSheet;
		else if(extension == "continent")
			sheet = new CContinentSheet;
		else if(extension == "world")
			sheet = new CWorldSheet;
		else if(extension == "weather_function_params")
			sheet = new CWeatherFunctionParamsSheet;
		else if(extension == "mission_icon")
			sheet = new CMissionIconSheet;
		else if(extension == "sbrick")
			sheet = new CSBrickSheet;
		else if(extension == "sphrase")
			sheet = new CSPhraseSheet;
		else if(extension == "skill_tree")
			sheet = new CSkillsTreeSheet;
		else if(extension == "titles")
			sheet = new CUnblockTitlesSheet;
		else if(extension == "succes_chances_table")
			sheet = new CSuccessTableSheet;
		else if(extension == "automaton_list")
			sheet = new CAutomatonListSheet;
		else if(extension == "animset_list")
			sheet = new CAnimationSetListSheet;
		else if(extension == "animation_fx")
			sheet = new CAnimationFXSheet;
		else if(extension == "id_to_string_array")
			sheet = new CIDToStringArraySheet;
		else if(extension == "emot")
			sheet = new CEmotListSheet;
		else if(extension == "forage_source")
			sheet = new CForageSourceSheet;
		else if(extension == "flora")
			sheet = new CFloraSheet;
		else if(extension == "animation_fx_set")
			sheet = new CAnimationFXSetSheet;
		else if(extension == "attack_list")
			sheet = new CAttackListSheet;
		else if(extension == "text_emotes")
			sheet = new CTextEmotListSheet;
		else if(extension == "sky")
			sheet = new CSkySheet;
		else if(extension == "outpost")
			sheet = new COutpostSheet;
		else if(extension == "outpost_building")
			sheet = new COutpostBuildingSheet;
		else if(extension == "outpost_squad")
			sheet = new COutpostSquadSheet;
		else if(extension == "faction")
			sheet = new CFactionSheet;
		else
		{
			nlwarning("CSheetManager::loadSheet: Do not know how to create the class from the sheet '%s'.", sheetId.toString().c_str());
			return;
		}

		// Build the sheet from an external file.
		sheet->Id = sheetId;
		sheet->build(form->getRootNode());

		EntitySheet = sheet;
		SheetMngr.processSheet(EntitySheet);
	}
	// Error while loading the form.
	else
	{
//		nlwarning("CSheetManager::loadSheet: Cannot load the form '%s'.", filename.c_str());
		EntitySheet = 0;
	}
}
Ejemplo n.º 18
0
//=======================================================
void CSeasonFXSheet::build(const NLGEORGES::UFormElm &item, NLMISC::CSheetId parentId, const std::string &prefix)
{
	bool ok = true;
 	ok &= item.getValueByName(FXName, (prefix + "FXName").c_str());
	if (FXName.empty()) return;
	uint32 fxMode = 0;
	ok &= item.getValueByName(fxMode, (prefix + "Mode").c_str());
	Mode = (TMode) fxMode;
	ok &= item.getValueByName(CycleDuration, (prefix + "CycleDuration").c_str());
	ok &= item.getValueByName(StartHourMin, (prefix + "StartHourMin").c_str());
	ok &= item.getValueByName(StartHourMax, (prefix + "StartHourMax").c_str());
	ok &= item.getValueByName(EndHourMin, (prefix + "EndHourMin").c_str());
	ok &= item.getValueByName(EndHourMax, (prefix + "EndHourMax").c_str());
	ok &= item.getValueByName(InheritScale, (prefix + "InheritScale").c_str());
	ok &= item.getValueByName(InheritRot, (prefix + "InheritRot").c_str());
	ok &= item.getValueByName(AngleMin, (prefix + "AngleMin").c_str());
	ok &= item.getValueByName(AngleMax, (prefix + "AngleMax").c_str());
	ok &= item.getValueByName(DontRotate, (prefix + "DontRotate").c_str());
	ok &= item.getValueByName(DontRotateAroundLocalZ, (prefix + "DontRotateAroundLocalZ").c_str());
	ok &= item.getValueByName(ScaleMin.x, (prefix + "ScaleMinX").c_str());
	ok &= item.getValueByName(ScaleMin.y, (prefix + "ScaleMinY").c_str());
	ok &= item.getValueByName(ScaleMin.z, (prefix + "ScaleMinZ").c_str());
	ok &= item.getValueByName(ScaleMax.x, (prefix + "ScaleMaxX").c_str());
	ok &= item.getValueByName(ScaleMax.y, (prefix + "ScaleMaxY").c_str());
	ok &= item.getValueByName(ScaleMax.z, (prefix + "ScaleMaxZ").c_str());
	ok &= item.getValueByName(UniformScale, (prefix + "UniformScale").c_str());
	ok &= item.getValueByName(WantScaling, (prefix + "WantScaling").c_str());
	ok &= item.getValueByName(AlignOnWater, (prefix + "AlignOnWater").c_str());
	ok &= item.getValueByName(ZOffset, (prefix + "ZOffset").c_str());

	// Anti Crash
	if(CycleDuration<=0)
	{
		nlwarning("FX: CPlantSheet '%s' has a season with a CycleDuration<=0: %f !!!!! setting it to 0.1.",
			parentId.toString().c_str(), CycleDuration);
		CycleDuration= 0.1f;
	}

	StartHourMin = fmodf(StartHourMin, CycleDuration);
	StartHourMax = fmodf(StartHourMax, CycleDuration);
	EndHourMin   = fmodf(EndHourMin, CycleDuration);
	EndHourMax   = fmodf(EndHourMax, CycleDuration);

	nlassert(isValidDouble(StartHourMin));
	nlassert(isValidDouble(StartHourMax));
	nlassert(isValidDouble(EndHourMin));
	nlassert(isValidDouble(EndHourMax));
	nlassert(isValidDouble(CycleDuration));

	for(uint k = 0; k < 4; ++k)
	{
		ok &= item.getValueByName(UserParamsMin[k], (prefix + NLMISC::toString("UserParam%dMin", (int) k)).c_str());
		ok &= item.getValueByName(UserParamsMax[k], (prefix + NLMISC::toString("UserParam%dMax", (int) k)).c_str());
	}
	ok &= item.getValueByName(MinDuration, (prefix + "MinDuration").c_str());
	ok &= item.getValueByName(MaxDuration, (prefix + "MaxDuration").c_str());
	// prevent from overlapping interval
	if (Mode != AlwaysStarted && Mode != UseDuration && Mode != Spawn)
	{
		float startHourMin = StartHourMin;
		float startHourMax = StartHourMax;
		if (startHourMax < startHourMin)
		{
			startHourMax += CycleDuration;
		}
		float endHourMin = EndHourMin;
		float endHourMax = EndHourMax;
		if (endHourMax < endHourMin)
		{
			endHourMax += CycleDuration;
		}
		if (!(startHourMax <= endHourMin || startHourMin >= endHourMax))
		{
			// intervals overlap -> bad
			nlwarning("Overlapping time intervals for fx spawn.");
			if (startHourMin <= endHourMin)
			{
				float inter = endHourMin;
				if (inter >= CycleDuration)
				{
					inter -= CycleDuration;
				}
				StartHourMax = inter;
			}
			else
			{
				float inter = startHourMin;
				if (inter >= CycleDuration)
				{
					inter -= CycleDuration;
				}
				EndHourMax = inter;
			}
		}
	}
	// compute duration of start interval
	float startHourMaxInterval;
	if (StartHourMin <= StartHourMax)
	{
		startHourMaxInterval = StartHourMax - StartHourMin;
	}
	else
	{
		startHourMaxInterval = CycleDuration - StartHourMin + StartHourMax;
	}
	NLMISC::clamp(MinDuration, 0.f, CycleDuration /*- startHourMaxInterval*/);
	NLMISC::clamp(MaxDuration, 0.f, CycleDuration /*- startHourMaxInterval*/);

	if (!ok)
	{
		nldebug("Key not found.");
	}
}
Ejemplo n.º 19
0
//-----------------------------------------------
// readGeorges for CStaticSkillsTree
//
//-----------------------------------------------
void CStaticSkillsTree::readGeorges( const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const NLMISC::CSheetId &sheetId )
{
	if( form )
	{
		UFormElm& root = form->getRootNode();
		
		UFormElm *arraySkillElt = NULL;
		if( root.getNodeByName( &arraySkillElt, "SkillData" ) )
		{
			if( arraySkillElt )
			{
				uint NbSkills;
				nlverify( arraySkillElt->getArraySize( NbSkills ) );

				nlassertex( NbSkills == SKILLS::NUM_SKILLS, ("(%u != %u) Please synchronise game_share/skill.* with leveldesign/game_element/xp_table/skills.skill_tree (use skill_extractor.exe)", NbSkills, SKILLS::NUM_SKILLS));

				SkillsTree.resize( NbSkills );
				
				for( uint i = 0; i < NbSkills; ++i )
				{
					UFormElm* SkillElt = NULL;
					if( ! ( arraySkillElt->getArrayNode( &SkillElt, i ) && SkillElt ) )
					{
						nlwarning("<CStaticSkillsTree::readGeorges> can't get array node of SkillElt in sheet %s", sheetId.toString().c_str() );
					}
					else
					{
						// Skill
						string SkillName;
						SkillElt->getValueByName( SkillName, "Skill" );
						SKILLS::ESkills skill = SKILLS::toSkill( SkillName );
						nlassert( skill != SKILLS::unknown );
						if (skill == SKILLS::unknown)
						{
							continue;
						}
						SkillsTree[ skill ].Skill = skill;

						if( ! SkillElt->getValueByName( SkillsTree[ skill ].SkillCode, "SkillCode" ) )
						{
							nlwarning("<CStaticSkillsTree::readGeorges> can't get node SkillCode in sheet %s", sheetId.toString().c_str() );
						}

						// Skill Code
						if( ! SkillElt->getValueByName( SkillsTree[ skill ].SkillCode, "SkillCode" ) )
						{
							nlwarning("<CStaticSkillsTree::readGeorges> can't get node SkillCode in sheet %s", sheetId.toString().c_str() );
						}

						// Max skill value
						if( ! SkillElt->getValueByName( SkillsTree[ skill ].MaxSkillValue, "MaxSkillValue" ) )
						{
							nlwarning("<CStaticSkillsTree::readGeorges> can't get node MaxSkillValue in sheet %s", sheetId.toString().c_str() );
						}

						// Type of stage
						if( ! SkillElt->getValueByName( SkillsTree[ skill ].StageType, "Type of Stage" ) )
						{
							nlwarning("<CStaticSkillsTree::readGeorges> can't get node 'Type of Stage' in sheet %s", sheetId.toString().c_str() );
						}

						// ParentSkill
						if( ! SkillElt->getValueByName( SkillName, "ParentSkill" ) )
						{
							nlwarning("<CStaticSkillsTree::readGeorges> can't get node ParentSkills in sheet %s", sheetId.toString().c_str() );
						}
						else
						{	
							SkillsTree[ skill ].ParentSkill = SKILLS::toSkill( SkillName );
						}

						// ChildSkills
						UFormElm *arrayChildSkillElt = NULL;
						if( SkillElt->getNodeByName( &arrayChildSkillElt, "ChildSkills" ) )
						{
							if( arrayChildSkillElt )
							{
								uint NbChildSkills;
								nlverify( arrayChildSkillElt->getArraySize( NbChildSkills ) );
								
								SkillsTree[ skill ].ChildSkills.resize( NbChildSkills );
								
								for( uint i = 0; i < NbChildSkills; ++i )
								{
									string childSkillName;
									arrayChildSkillElt->getArrayValue( childSkillName, i );
									SKILLS::ESkills childSkill = SKILLS::toSkill( childSkillName );
									nlassert( childSkill != SKILLS::unknown );
									if (skill == SKILLS::unknown)
									  {
										continue;
									  }
									SkillsTree[ skill ].ChildSkills[ i ] = childSkill;
								}
							}
						}
					}
				}
			}
		}
	}
}