void GameStatsMenu::calculateScore(int level)
{
    Human_UnitsDestroyed = 0;
	AI_UnitsDestroyed = 0;

    Human_StructuresDestroyed = 0;
	AI_StructuresDestroyed = 0;

	Human_SpiceHarvested = 0.0;
	AI_SpiceHarvested = 0.0;

	totalTime = currentGame->GetGameTime()/1000;

    totalScore = level*45;

    double totalHumanCredits = 0.0;
	for(int i=0; i < MAX_PLAYERS; i++) {
        House* pHouse = currentGame->house[i];
        if(pHouse != NULL) {
            if(pHouse->isAI() == true) {
                AI_UnitsDestroyed += pHouse->getNumDestroyedUnits();
                AI_StructuresDestroyed += pHouse->getNumDestroyedStructures();
                AI_SpiceHarvested += pHouse->getHarvestedSpice();

                totalScore -= pHouse->getDestroyedValue();
            } else {
                Human_UnitsDestroyed += pHouse->getNumDestroyedUnits();
                Human_StructuresDestroyed += pHouse->getNumDestroyedStructures();
                Human_SpiceHarvested += pHouse->getHarvestedSpice();

                totalHumanCredits += pHouse->getCredits();

                totalScore += pHouse->getDestroyedValue();
            }
        }
	}

	totalScore += ((int) totalHumanCredits) / 100;

    for(RobustList<StructureClass*>::const_iterator iter = structureList.begin(); iter != structureList.end(); ++iter) {
        StructureClass* pStructure = *iter;
        if(pStructure->getOwner()->isAI() == false) {
            totalScore += currentGame->objectData.data[pStructure->getItemID()].price / 100;
        }
    }

    totalScore -= ((totalTime/60) + 1);

    for(RobustList<UnitClass*>::const_iterator iter = unitList.begin(); iter != unitList.end(); ++iter) {
        UnitClass* pUnit = *iter;
        if(pUnit->getItemID() == Unit_Harvester) {
            HarvesterClass* pHarvester = (HarvesterClass*) pUnit;
            if(pHarvester->getOwner()->isAI() == true) {
                AI_SpiceHarvested += pHarvester->getAmountOfSpice();
            } else {
                Human_SpiceHarvested += pHarvester->getAmountOfSpice();
            }
        }
    }

    if(currentGame->CheatsEnabled() == true) {
        rank = "Cheater";
    } else {
        int rankID = DuneText_SandFlea;

        if(totalScore >= 25)   rankID++;
        if(totalScore >= 50)   rankID++;
        if(totalScore >= 100)  rankID++;
        if(totalScore >= 150)  rankID++;
        if(totalScore >= 200)  rankID++;
        if(totalScore >= 300)  rankID++;
        if(totalScore >= 400)  rankID++;
        if(totalScore >= 500)  rankID++;
        if(totalScore >= 700)  rankID++;
        if(totalScore >= 1000) rankID++;
        if(totalScore >= 1400) rankID++;
    //    if(totalScore >= 1800) rankID++;

        rank = pTextManager->getDuneText(rankID);
    }
}