Beispiel #1
0
void Planet::PopGrowthProductionResearchPhase() {
    UniverseObject::PopGrowthProductionResearchPhase();

    // do not do production if planet was just conquered
    if (m_just_conquered)
        m_just_conquered = false;
    else
        ResourceCenterPopGrowthProductionResearchPhase();

    PopCenterPopGrowthProductionResearchPhase();

    // check for planets with zero population.  If they have a species set, then
    // they probably just starved
    if (!SpeciesName().empty() && GetMeter(METER_POPULATION)->Current() == 0.0) {
        // generate starvation sitrep for empire that owns this depopulated planet
        if (Empire* empire = Empires().Lookup(this->Owner()))
            empire->AddSitRepEntry(CreatePlanetStarvedToDeathSitRep(this->ID()));

        // remove species
        SetSpecies("");

    }

    GetMeter(METER_SHIELD)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_SHIELD));
    GetMeter(METER_DEFENSE)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_DEFENSE));
    GetMeter(METER_TROOPS)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_TROOPS));
    GetMeter(METER_REBEL_TROOPS)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_REBEL_TROOPS));

    StateChangedSignal();
}
Beispiel #2
0
/*	index - Index of the stack where our new value for the property should be */
int Lunem::LuaSetProp(lua_State* ls, string& prop, int index)
{
	if (prop == "species") SetSpecies(lua_tostring(ls, index));

	else return Actor::LuaSetProp(ls, prop, index);

	return 1;
}
Beispiel #3
0
void Lunem::ReadFromFile(FILE* f)
{
	char buffer[128];
	unsigned char c;
	int i;
	
	// read species string
	fread(&c, sizeof(c), 1, f); //length
	ASSERT(c > 0);

	if (c > 127) c = 127;
	fread(&buffer, c, 1, f);
	m_sSpecies.append(buffer, c);
	
	// read name string
	fread(&c, sizeof(c), 1, f); //length
	ASSERT(c > 0);

	if (c > 127) c = 127;
	fread(&buffer, c, 1, f);
	mName.append(buffer, c);

	console->AddMessage("Reading in, name: " + mName + " species: " + m_sSpecies);

	fread(&m_bLevel, sizeof(m_bLevel), 1, f);
	fread(&m_bGene, sizeof(m_bGene), 1, f);

	for (i = 0; i < MAX_COMBATANT_TYPES; ++i)
	{
		fread(&m_bType[i], sizeof(m_bType[i]), 1, f);
	}	
	
	fread(&m_bBaseAttack, sizeof(m_bBaseAttack), 1, f);
	fread(&m_bBaseDefense, sizeof(m_bBaseDefense), 1, f);
	fread(&m_bBaseSpeed, sizeof(m_bBaseSpeed), 1, f);
	fread(&m_bBaseHealth, sizeof(m_bBaseHealth), 1, f);
	fread(&m_iExp, sizeof(m_iExp), 1, f);
	fread(&m_iCurrentHealth, sizeof(m_iCurrentHealth), 1, f);

	//read skills
	for (i = 0; i < MAX_COMBATANT_SKILLS; ++i)
	{
		fread(&c, sizeof(c), 1, f); //length
		if (c > 0)
		{
			if (c > 127) c = 127;
			fread(&buffer, c, 1, f);
			m_sSkills[i].id.append(buffer, c);
		}
	}

	LoadFlags(f);
	
	SetSpecies(m_sSpecies);
}
Beispiel #4
0
void main (void)
{

	worldADT world;
	int i;
	double time=InitialTimeInterval;
	int numcreature;
	speciesADT *speciesP;
	creatureADT *creatureP; 


	while(TRUE)
	{
		Randomize();
		InitGraphics();
		InitWorldMap(NColumns,NRows);
		i=0;
		numcreature=0;
	
		world=NewWorld(NColumns,NRows);
		PrintInstructions1();

		speciesP=SetSpecies(&numcreature);
		speciesP=Shuffle(speciesP,numcreature);
	
		creatureP=GetBlock( numcreature * sizeof (creatureADT) );
		PlacingCreatures(world,creatureP,speciesP,numcreature);
		
		PrintInstructions2();

		while ( !MouseButtonIsDown() || WantToContinue(creatureP,numcreature,&time) )
		{
			TakeOneTurn(creatureP[i]);
			i=(i+1)%numcreature;
			Pause(time);
		}
				
		FreeWorld(world);
		FreeBlock(creatureP);

		if (!WantToPlayAgain())  {break;}

	}
}
Beispiel #5
0
void Planet::PopGrowthProductionResearchPhase() {
    UniverseObject::PopGrowthProductionResearchPhase();

    bool just_conquered = m_just_conquered;
    // do not do production if planet was just conquered
    m_just_conquered = false;

    if (!just_conquered)
        ResourceCenterPopGrowthProductionResearchPhase();

    PopCenterPopGrowthProductionResearchPhase();

    // check for planets with zero population.  If they have a species set, then
    // they probably just starved
    if (!SpeciesName().empty() && GetMeter(METER_POPULATION)->Current() == 0.0) {
        if (Empire* empire = Empires().Lookup(this->Owner())) {
            // generate starvation sitrep for empire that owns this depopulated planet
            empire->AddSitRepEntry(CreatePlanetStarvedToDeathSitRep(this->ID()));

            // record depopulation of planet with species while owned by this empire
            std::map<std::string, int>::iterator species_it =
                empire->SpeciesShipsLost().find(SpeciesName());
            if (species_it == empire->SpeciesPlanetsDepoped().end())
                empire->SpeciesPlanetsDepoped()[SpeciesName()] = 1;
            else
                species_it->second++;
        }
        // remove species
        SetSpecies("");
    }

    if (!just_conquered) {
        GetMeter(METER_SHIELD)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_SHIELD));
        GetMeter(METER_DEFENSE)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_DEFENSE));
        GetMeter(METER_TROOPS)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_TROOPS));
        GetMeter(METER_REBEL_TROOPS)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_REBEL_TROOPS));
        GetMeter(METER_SUPPLY)->SetCurrent(Planet::NextTurnCurrentMeterValue(METER_SUPPLY));
    }

    StateChangedSignal();
}
Beispiel #6
0
bool Planet::Colonize(int empire_id, const std::string& species_name, double population) {
    const Species* species = nullptr;

    // if desired pop > 0, we want a colony, not an outpost, so we need to do some checks
    if (population > 0.0) {
        // check if specified species exists and get reference
        species = GetSpecies(species_name);
        if (!species) {
            ErrorLogger() << "Planet::Colonize couldn't get species already on planet with name: " << species_name;
            return false;
        }
        // check if specified species can colonize this planet
        if (EnvironmentForSpecies(species_name) < PE_HOSTILE) {
            ErrorLogger() << "Planet::Colonize: can't colonize planet already populated by species " << species_name;
            return false;
        }
    }

    // reset the planet to unowned/unpopulated
    if (!OwnedBy(empire_id)) {
        Reset();
    } else {
        PopCenter::Reset();
        for (int building_id : m_buildings)
            if (auto building = GetBuilding(building_id))
                building->Reset();
        m_just_conquered = false;
        m_is_about_to_be_colonized = false;
        m_is_about_to_be_invaded = false;
        m_is_about_to_be_bombarded = false;
        SetOwner(ALL_EMPIRES);
    }

    // if desired pop > 0, we want a colony, not an outpost, so we have to set the colony species
    if (population > 0.0)
        SetSpecies(species_name);

    // find a default focus. use first defined available focus.
    // AvailableFoci function should return a vector of all names of
    // available foci.
    std::vector<std::string> available_foci = AvailableFoci();
    if (species && !available_foci.empty()) {
        bool found_preference = false;
        for (const std::string& focus : available_foci) {
            if (!focus.empty() && focus == species->PreferredFocus()) {
                SetFocus(focus);
                found_preference = true;
                break;
            }
        }

        if (!found_preference)
            SetFocus(*available_foci.begin());
    } else {
        DebugLogger() << "Planet::Colonize unable to find a focus to set for species " << species_name;
    }

    // set colony population
    GetMeter(METER_POPULATION)->SetCurrent(population);
    GetMeter(METER_TARGET_POPULATION)->SetCurrent(population);
    BackPropagateMeters();


    // set specified empire as owner
    SetOwner(empire_id);

    // if there are buildings on the planet, set the specified empire as their owner too
    for (auto& building : Objects().FindObjects<Building>(BuildingIDs()))
    { building->SetOwner(empire_id); }

    return true;
}
Beispiel #7
0
bool Planet::Colonize(int empire_id, const std::string& species_name, double population) {
    const Species* species = 0;

    // if desired pop > 0, we want a colony, not an outpost, so we need to do some checks
    if (population > 0.0) {
        // check if specified species exists and get reference
        species = GetSpecies(species_name);
        if (!species) {
            Logger().errorStream() << "Planet::Colonize couldn't get species already on planet with name: " << species_name;
            return false;
        }
        // check if specified species can colonize this planet
        if (EnvironmentForSpecies(species_name) < PE_HOSTILE) {
            Logger().errorStream() << "Planet::Colonize: can't colonize planet already populated by species " << species_name;
            return false;
        }
    }

    // reset the planet to unowned/unpopulated
    Reset();

    // if desired pop > 0, we want a colony, not an outpost, so we have to set the colony species
    if (population > 0.0)
        SetSpecies(species_name);

    // find a default focus. use first defined available focus.
    // AvailableFoci function should return a vector of all names of
    // available foci.
    std::vector<std::string> available_foci = AvailableFoci();
    if (species && !available_foci.empty()) {
        bool found_preference = false;
        for (std::vector<std::string>::const_iterator it = available_foci.begin();
             it != available_foci.end(); ++it)
        {
            if (!it->empty() && *it == species->PreferredFocus()) {
                SetFocus(*it);
                found_preference = true;
                break;
            }
        }

        if (!found_preference)
            SetFocus(*available_foci.begin());
    } else {
        Logger().debugStream() << "Planet::Colonize unable to find a focus to set for species " << species_name;
    }

    // set colony population
    GetMeter(METER_POPULATION)->SetCurrent(population);
    GetMeter(METER_TARGET_POPULATION)->SetCurrent(population);
    GetMeter(METER_HAPPINESS)->SetCurrent(20.0f);
    BackPropegateMeters();


    // set specified empire as owner
    SetOwner(empire_id);

    // if there are buildings on the planet, set the specified empire as their owner too
    std::vector<TemporaryPtr<Building> > buildings = Objects().FindObjects<Building>(BuildingIDs());
    for (std::vector<TemporaryPtr<Building> >::iterator building_it = buildings.begin();
         building_it != buildings.end(); ++building_it)
    { (*building_it)->SetOwner(empire_id); }

    return true;
}