コード例 #1
0
ファイル: weight.cpp プロジェクト: bholtsclaw/uox3
//o--------------------------------------------------------------------------o
//|	Function		-	SI32 CWeight::calcWeight( CItem *pack )
//|	Date			-	2/23/2003
//|	Developers		-	Zane
//|	Organization	-	UOX3 DevTeam
//o--------------------------------------------------------------------------o
//|	Description		-	Calculate the total weight of a pack based upon all items inside,
//|							their amounts, etc. This function should never need to be called
//|							but is available for bruteforce weight updating
//o--------------------------------------------------------------------------o
SI32 CWeight::calcWeight( CItem *pack )
{
    SI32 totalWeight = 0;
    SI32 contWeight = 0;

    CDataList< CItem * > *pCont = pack->GetContainsList();
    for( CItem *i = pCont->First(); !pCont->Finished(); i = pCont->Next() )
    {
        if( !ValidateObject( i ) )
            continue;

        if( i->IsContType() )	// Item is a container
        {
            CTile& tile = Map->SeekTile( i->GetID() );
            contWeight = static_cast<SI32>( tile.Weight() * 100);	// Add the weight of the container
            contWeight += calcWeight( i );	// Find and add the weight of the items in the container
            i->SetWeight( contWeight, false );		// Also update the weight property of the container
            totalWeight += contWeight;
            if( totalWeight >= MAX_WEIGHT )
                return MAX_WEIGHT;
        }
        else
        {
            if( !calcAddWeight( i, totalWeight ) )
                return MAX_WEIGHT;
        }
    }
    return totalWeight;
}
コード例 #2
0
ファイル: weight.cpp プロジェクト: bholtsclaw/uox3
//o--------------------------------------------------------------------------o
//|	Function		-	SI32 CWeight::calcCharWeight( CChar *mChar )
//|	Date			-	2/23/2003
//|	Developers		-	Zane
//|	Organization	-	UOX3 DevTeam
//o--------------------------------------------------------------------------o
//|	Description		-	Calculate the total weight of a character based upon all items he owns,
//|							This function should never need to be called but is available for
//|							bruteforce weight updating
//o--------------------------------------------------------------------------o
SI32 CWeight::calcCharWeight( CChar *mChar )
{
    SI32 totalWeight = 0;
    SI32 contWeight = 0;

    for( CItem *i = mChar->FirstItem(); !mChar->FinishedItems(); i = mChar->NextItem() )
    {
        if( !ValidateObject( i ) )
            continue;

        if( IsWeightedContainer( i ) )
        {
            if( i->GetLayer() == IL_PACKITEM )
            {
                CTile& tile = Map->SeekTile( i->GetID() );
                contWeight = static_cast<SI32>( tile.Weight() * 100);	// Add the weight of the container
                contWeight += calcWeight( i );	// Find and add the weight of the items in the container
                i->SetWeight( contWeight, false );		// Also update the weight property of the container
                totalWeight += contWeight;
            }
            else
                totalWeight += i->GetWeight();	// Normal item, just add its weight
        }
        if( totalWeight >= MAX_WEIGHT )
            return MAX_WEIGHT;
    }
    return totalWeight;
}
コード例 #3
0
ファイル: readFiles.cpp プロジェクト: nunomiguel1995/CAL
/**
 * Reads the edges from a file and loads them into the graph
 */
void readEdges(Graph<Node, Road> & g, GraphViewer *gv) {
	ifstream inFile;

	//Ler o ficheiro subroads.txt
	inFile.open("database/subroadsDemo.txt");

	if (!inFile) {
		cerr << "Unable to open file subroadsDemo.txt";
		exit(1);   // call system to stop
	}

	std::string line;

	unsigned long roadID;
	unsigned long node1ID, node2ID;

	while (std::getline(inFile, line)) {
		std::stringstream linestream(line);
		std::string data;

		linestream >> roadID;

		std::getline(linestream, data, ';'); // read up-to the first ; (discard ;).
		linestream >> node1ID;
		std::getline(linestream, data, ';'); // read up-to the first ; (discard ;).
		linestream >> node2ID;

		float weight = calcWeight(findNode(g, node1ID), findNode(g, node2ID));
		gv->addEdge(roadID, node1ID, node2ID, EdgeType::UNDIRECTED);
		Road r = readRoads(roadID, gv);
		if (r.is_two_way())
			g.addEdge1(findNode(g, node2ID), findNode(g, node1ID), weight, r);

		g.addEdge1(findNode(g, node1ID), findNode(g, node2ID), weight, r);

	}

	inFile.close();

}
コード例 #4
0
ファイル: cbody.hpp プロジェクト: BackupTheBerlios/hypnos-svn
	//! Gets the weight of the body, calculating it when necessary
	inline float getWeight()
	{ if ( weight <= 0 ) calcWeight(); return weight; }