Exemplo n.º 1
0
void CItemSpawn::GenerateItem(CResourceDef *pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateItem");

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex());

	CItemContainer *pCont = dynamic_cast<CItemContainer *>(GetParent());
	BYTE iCount = pCont ? static_cast<unsigned char>(pCont->ContentCount(rid)) : GetCount();
	if ( iCount >= GetAmount() )
		return;

	CItem *pItem = CreateTemplate(id);
	if ( pItem == NULL )
		return;

	WORD iAmountPile = static_cast<WORD>(minimum(USHRT_MAX,m_itSpawnItem.m_pile));
	if ( iAmountPile > 1 )
	{
		CItemBase *pItemDef = pItem->Item_GetDef();
		ASSERT(pItemDef);
		if ( pItemDef->IsStackableType() )
			pItem->SetAmount(Calc_GetRandVal(iAmountPile) + 1);
	}

	pItem->SetAttr(m_Attr & (ATTR_OWNED | ATTR_MOVE_ALWAYS));
	pItem->SetDecayTime(g_Cfg.m_iDecay_Item);	// it will decay eventually to be replaced later
	pItem->MoveNearObj(this, m_itSpawnItem.m_DistMax);
	AddObj(pItem->GetUID());
}
Exemplo n.º 2
0
void TInifile::InitCore(WCHAR *_ini_file)
{
	iniFile = _ini_file;

	Lock();
	HANDLE	hFile = ::CreateFileW(iniFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);

	AddObj(rootSec = new TIniSection());

	if (hFile != INVALID_HANDLE_VALUE) {
		DWORD	size  = ::GetFileSize(hFile, 0); // I don't care 4GB over :-)
		VBuf	vbuf(size + 1); // already 0 fill

		if (::ReadFile(hFile, vbuf, size, &size, 0)) {
#define MAX_INI_LINE	(64 * 1024)
			DynBuf		buf(MAX_INI_LINE);
			DynBuf		val(MAX_INI_LINE);
			char		name[1024], *tok;
			BOOL		is_section;
			TIniSection	*target_sec=rootSec;

			for (tok=strtok(vbuf, "\r\n"); tok; tok=strtok(NULL, "\r\n")) {
				BOOL	ret = Parse(tok, &is_section, name, val);
				if (!ret) {
					target_sec->AddKey(NULL, tok);
				}
				else if (is_section) {
					target_sec = new TIniSection();
					target_sec->Set(name);
					AddObj(target_sec);
				}
				else {
					target_sec->AddKey(name, val);
				}
			}
		}
		::CloseHandle(hFile);
//		GetFileInfo(iniFile, &iniFt, &iniSize);
	}
	UnLock();
}
Exemplo n.º 3
0
void TInifile::Init(const char *_ini_file)
{
	if (_ini_file) ini_file = strdup(_ini_file);

	Lock();
	FILE	*fp = fopen(ini_file, "r");

	AddObj(root_sec = new TIniSection());

	if (fp) {
#define MAX_INI_LINE	(64 * 1024)
		char	*buf = new char [MAX_INI_LINE];
		char	*val = new char [MAX_INI_LINE];
		char	name[1024];
		BOOL	is_section;

		TIniSection	*target_sec=root_sec;

		while (fgets(buf, MAX_INI_LINE, fp)) {
			BOOL	ret = Parse(buf, &is_section, name, val);

			if (!ret) {
				target_sec->AddKey(NULL, buf);
			}
			else if (is_section) {
				target_sec = new TIniSection();
				target_sec->Set(name);
				AddObj(target_sec);
			}
			else {
				target_sec->AddKey(name, val);
			}
		}
		delete [] val;
		delete [] buf;
		fclose(fp);
//		GetFileInfo(ini_file, &ini_ft, &ini_size);
	}
	UnLock();
}
Exemplo n.º 4
0
void TInifile::SetSection(const char *section)
{
	if (cur_sec && cur_sec != root_sec && !cur_sec->TopObj()) {
		DelObj(cur_sec);
		delete cur_sec;
	}

	if ((cur_sec = SearchSection(section)) == NULL) {
		cur_sec = new TIniSection();
		cur_sec->Set(section);
		AddObj(cur_sec);
	}
}
Exemplo n.º 5
0
void CItemSpawn::GenerateChar(CResourceDef *pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateChar");

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef *pSpawnGroup = static_cast<const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		size_t i = pSpawnGroup->GetRandMemberIndex();
		if ( i != pSpawnGroup->BadMemberIndex() )
			rid = pSpawnGroup->GetMemberID(i);
	}

	if ( (rid.GetResType() != RES_CHARDEF) && (rid.GetResType() != RES_UNKNOWN) )
		return;

	CPointMap pt = GetTopPoint();
	CRegionBase *pRegion = pt.GetRegion(REGION_TYPE_AREA);
	if ( !pRegion )
		return;

	CChar *pChar = CChar::CreateBasic(static_cast<CREID_TYPE>(rid.GetResIndex()));
	if ( !pChar )
		return;

	pChar->NPC_LoadScript(true);
	pChar->StatFlag_Set(STATF_Spawned);

	// Try placing the char near the spawn
	if ( !pChar->MoveNearObj(this, m_itSpawnChar.m_DistMax) || !pChar->CanSeeLOS(pt) )
	{
		// If this fails, try placing the char over the spawn
		if ( !pChar->MoveTo(pt) )
		{
			DEBUG_ERR(("Spawn UID:0%lx is unable to place a character inside the world.\n", static_cast<DWORD>(GetUID())));
			pChar->Delete();
			return;
		}
	}

	AddObj(pChar->GetUID());
	pChar->NPC_CreateTrigger();		// removed from NPC_LoadScript() and triggered after char placement and attachment to the spawnitem
	pChar->Update();

	size_t iCount = GetTopSector()->GetCharComplexity();
	if ( iCount > g_Cfg.m_iMaxCharComplexity )
		g_Log.Event(LOGL_WARN, "%" FMTSIZE_T " chars at %s. Sector too complex!\n", iCount, GetTopSector()->GetBasePoint().WriteUsed());
}
Exemplo n.º 6
0
bool CItemSpawn::r_LoadVal(CScript & s)
{
	ADDTOCALLSTACK("CitemSpawn:r_LoadVal");
	EXC_TRY("LoadVal");

	if (g_Serv.IsLoading())
	{
		if (!strnicmp(s.GetKey(), "more2", 5))	//More2 shouldn't be loaded as it's being set with ADDOBJ
			return true;
	}
	int iCmd = FindTableSorted(s.GetKey(), sm_szLoadKeys, COUNTOF(sm_szLoadKeys) - 1);
	if (iCmd < 0)
		return CItem::r_LoadVal(s);

	switch (iCmd)
	{
		case ISPW_ADDOBJ:
		{
			CGrayUID uid = static_cast<CGrayUID>(s.GetArgVal());
			if ( uid.ObjFind() )
				AddObj(uid);
			return true;
		}
		case ISPW_DELOBJ:
		{
			CGrayUID uid = static_cast<CGrayUID>(s.GetArgVal());
			if (uid.ObjFind())
				DelObj(uid);
			return true;
		}
		case ISPW_RESET:
			KillChildren();
			return true;
		case ISPW_START:
			SetTimeout(0);
			return true;
		case ISPW_STOP:
			KillChildren();
			SetTimeout(-1);
			return true;
		default:
			break;
	}
	EXC_CATCH;
	return false;
}
Exemplo n.º 7
0
//*******************************************************************
int CSolver:: AddColumnDef( char* colname, double objval,
			    char  coltype, double lowbnd, double upbnd){
      int rc;
  try {
       m_ColMap[colname] = m_nColCount;

       rc = AddObj( m_nColCount, objval, coltype, colname);

       SetColumnBounds(m_nColCount,lowbnd,upbnd);
       m_nColCount++;
  }
  catch(...) {
       Message( "AddColumnDef exception");
	   Message( colname );
       
  }
    return rc;
}
Exemplo n.º 8
0
Arquivo: Mix.cpp Projeto: alltom/taps
int
Mixer::Connect(char* mess, void* input){

	switch (FindMsg(mess)){

	case 21:
    AddObj((SndObj *) input);
	return 1;

    case 22:
    DeleteObj((SndObj *) input);
	return 1;
	
	default:
    return SndObj::Connect(mess,input);
     
	}
}
Exemplo n.º 9
0
void CItemSpawn::GenerateChar(CResourceDef *pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateChar");
	if ( !IsTopLevel() )
		return;

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef *pSpawnGroup = static_cast<const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		size_t i = pSpawnGroup->GetRandMemberIndex();
		if ( i != pSpawnGroup->BadMemberIndex() )
			rid = pSpawnGroup->GetMemberID(i);
	}

	if ( (rid.GetResType() != RES_CHARDEF) && (rid.GetResType() != RES_UNKNOWN) )
		return;

	CChar *pChar = CChar::CreateBasic(static_cast<CREID_TYPE>(rid.GetResIndex()));
	if ( !pChar )
		return;

	CPointMap pt = GetTopPoint();
	pChar->NPC_LoadScript(true);
	pChar->StatFlag_Set(STATF_Spawned);
	pChar->MoveTo(pt);

	// Check if the NPC can spawn in this region
	CRegionBase *pRegion = GetTopPoint().GetRegion(REGION_TYPE_AREA);
	if ( !pRegion || (pRegion->IsGuarded() && pChar->Noto_IsEvil()) )
	{
		pChar->Delete();
		return;
	}

	AddObj(pChar->GetUID());
	pChar->NPC_CreateTrigger();		// removed from NPC_LoadScript() and triggered after char placement and attachment to the spawnitem
	pChar->Update();

	size_t iCount = GetTopSector()->GetCharComplexity();
	if ( iCount > g_Cfg.m_iMaxCharComplexity )
		g_Log.Event(LOGL_WARN, "%d chars at %s. Sector too complex!\n", iCount, GetTopSector()->GetBasePoint().WriteUsed());
}
Exemplo n.º 10
0
void CItemSpawn::GenerateItem(CResourceDef * pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateItem");

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex());
	int iDistMax = m_itSpawnItem.m_DistMax;
	int iAmountPile = m_itSpawnItem.m_pile;

	int iCount = 0;
	CItemContainer * pCont = dynamic_cast <CItemContainer *>( GetParent());

	if ( pCont != NULL )
		iCount = pCont->ContentCount( rid );
	else
		iCount = GetCount();

	if ( iCount >= GetAmount())
		return;

	CItem * pItem = CreateTemplate( id );
	if ( pItem == NULL )
		return;

	pItem->SetAttr( m_Attr & ( ATTR_OWNED | ATTR_MOVE_ALWAYS ));

	if ( iAmountPile > 1 )
	{
		CItemBase * pItemDef = pItem->Item_GetDef();
		ASSERT(pItemDef);
		if ( pItemDef->IsStackableType())
		{
			if ( iAmountPile == 0 || iAmountPile > GetAmount())
				iAmountPile = GetAmount();
			pItem->SetAmount( Calc_GetRandVal(iAmountPile) + 1 );
		}
	}

	pItem->SetDecayTime( g_Cfg.m_iDecay_Item );	// It will decay eventually to be replaced later.
	pItem->MoveNearObj( this, iDistMax );
	AddObj(pItem->GetUID());
	pItem->m_uidSpawnItem = GetUID();
}
Exemplo n.º 11
0
bool CItemSpawn::r_LoadVal(CScript & s)
{
	ADDTOCALLSTACK("CitemSpawn:r_LoadVal");
	EXC_TRY("LoadVal");

	int iCmd = FindTableSorted(s.GetKey(), sm_szLoadKeys, COUNTOF(sm_szLoadKeys) - 1);
	if ( iCmd < 0 )
		return CItem::r_LoadVal(s);

	switch ( iCmd )
	{
		case ISPW_ADDOBJ:
		{
			AddObj(static_cast<CGrayUID>(s.GetArgVal()));
			return true;
		}
		case ISPW_AMOUNT:
		{
			SetAmount(static_cast<BYTE>(s.GetArgVal()));
			return true;
		}
		case ISPW_DELOBJ:
		{
			DelObj(static_cast<CGrayUID>(s.GetArgVal()));
			return true;
		}
		case ISPW_RESET:
			KillChildren();
			return true;
		case ISPW_START:
			SetTimeout(0);
			return true;
		case ISPW_STOP:
			KillChildren();
			SetTimeout(-1);
			return true;
		default:
			break;
	}
	EXC_CATCH;
	return false;
}
Exemplo n.º 12
0
BOOL AttachNode(NodeType* pnode, ObjDescType* ds)
{
  return AddObj(pnode, &Node_Carrier, ds);
}
Exemplo n.º 13
0
BOOL AttachRoutine(RoutineType* pRt, ObjDescType* prtds)
{
  return AddObj(pRt,&Rt_Carrier, prtds);
}
Exemplo n.º 14
0
void CItemSpawn::GenerateChar(CResourceDef * pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateChar");
	if ( !IsTopLevel() || ( m_itSpawnChar.m_current >= GetAmount() ) || ( GetTopSector()->GetCharComplexity() > g_Cfg.m_iMaxCharComplexity ))
		return;

	int iDistMax = m_itSpawnChar.m_DistMax;
	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef * pSpawnGroup = STATIC_CAST <const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		size_t i = pSpawnGroup->GetRandMemberIndex();
		if ( i != pSpawnGroup->BadMemberIndex() )
		{
			rid = pSpawnGroup->GetMemberID(i);
		}
	}

	if (( rid.GetResType() != RES_CHARDEF ) && ( rid.GetResType() != RES_UNKNOWN ))
		return;

	CREID_TYPE id = static_cast<CREID_TYPE>(rid.GetResIndex());

	bool isBadPlaceToSpawn = false;
	CChar * pChar = CChar::CreateBasic(id);
	if( pChar == NULL )
	{
		return;
	}

	pChar->NPC_LoadScript(true);
	AddObj(pChar->GetUID());
	pChar->m_uidSpawnItem = GetUID();		// SpawnItem for this char
	pChar->StatFlag_Set( STATF_Spawned );
	pChar->MoveTo(GetTopPoint());
	pChar->NPC_CreateTrigger(); //Removed from NPC_LoadScript() and triggered after char placement

	if( pChar->GetRegion() == NULL )
	{
		isBadPlaceToSpawn = true;
	}
	else if( pChar->GetRegion()->IsGuarded() && pChar->Noto_IsEvil() )
	{
		isBadPlaceToSpawn = true;
	}

	// Deny definitely known a bad place to spawn (like red NPCs in guarded areas)
	// Usually caused by wide range near the edge of the towns
	if( isBadPlaceToSpawn )
	{
		pChar->Delete();
		//m_itSpawnChar.m_current--;
		return;
	}

	ASSERT(pChar->m_pNPC);
	if ( iDistMax )
	{
		pChar->m_ptHome = GetTopPoint();
		pChar->m_pNPC->m_Home_Dist_Wander = static_cast<WORD>(iDistMax);
	}
	pChar->Update();

}
Exemplo n.º 15
0
BOOL AttachOperation(OperationType* pOp, ObjDescType* pods)
{
		return 	AddObj(pOp, &Op_Carrier, pods);
}