Ejemplo n.º 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();
}
Ejemplo n.º 2
0
speciesADT *SetSpecies(int *numcreature)
{
	string str;
	int numspecies=0,k;
	speciesADT *speciesP=GetBlock( MaxCreatures * sizeof (speciesADT) );
	speciesADT species;
	FILE *infile;
	symtabADT symtab=NewSymbolTable();

	while (TRUE)
	{
		printf("Input a species name (Food,Hop,Flytrap,Rover,Loner):  ");
		str=GetLine();
		if (StringEqual (str,"") && *numcreature==0)
		{
			printf("No.You must at least enter one species!\n");
		}
		else if (StringEqual(str,"") && *numcreature!=0)
		{
			break;
		}
		else 
		{
			infile=fopen(Concat("Creatures\\", str),"r");
			if (infile==NULL)  {printf("No such data file.Try again.\n");}
			else 
			{
				species=ReadSpecies(str);
				if (Lookup(symtab,SpeciesName(species))==UNDEFINED)
				{
					printf("%s ",SpeciesName(species));
					numspecies++;
					Enter (symtab,SpeciesName(species),species);
				}
				fclose(infile);
				for (k=*numcreature ; k<=*numcreature+9 ; k++)
				{
					speciesP[k]=species;
				}
				*numcreature = *numcreature + 10 ;
				if (*numcreature==MaxCreatures || numspecies==MaxSpecies)  { break; }
			}
		}
	}
	return speciesP;
}
Ejemplo n.º 3
0
bool Planet::HasTag(const std::string& name) const {
    const Species* species = GetSpecies(SpeciesName());
    if (!species)
        return false;
    const std::vector<std::string>& tags = species->Tags();
    for (std::vector<std::string>::const_iterator it = tags.begin(); it != tags.end(); ++it)
        if (*it == name)
            return true;
    return false;
}
Ejemplo n.º 4
0
void PopulationPanel::CompleteConstruction() {
    AccordionPanel::CompleteConstruction();
    SetName("PopulationPanel");

    auto pop = GetPopCenter();
    if (!pop)
        throw std::invalid_argument("Attempted to construct a PopulationPanel with an object id is not a PopCenter");

    m_expand_button->LeftPressedSignal.connect(
        boost::bind(&PopulationPanel::ExpandCollapseButtonPressed, this));

    const auto obj = GetUniverseObject(m_popcenter_id);
    if (!obj) {
        ErrorLogger() << "Invalid object id " << m_popcenter_id;
        return;
    }

    // small meter indicators - for use when panel is collapsed
    m_meter_stats.push_back({
        METER_POPULATION,
        GG::Wnd::Create<StatisticIcon>(ClientUI::SpeciesIcon(pop->SpeciesName()),
                                       obj->InitialMeterValue(METER_POPULATION), 3, false,
                                       MeterIconSize().x, MeterIconSize().y)});
    m_meter_stats.push_back({
        METER_HAPPINESS,
        GG::Wnd::Create<StatisticIcon>(ClientUI::MeterIcon(METER_HAPPINESS),
                                       obj->InitialMeterValue(METER_HAPPINESS), 3, false,
                                       MeterIconSize().x, MeterIconSize().y)});
    m_meter_stats.push_back({
        METER_CONSTRUCTION,
        GG::Wnd::Create<StatisticIcon>(ClientUI::MeterIcon(METER_CONSTRUCTION),
                                       obj->InitialMeterValue(METER_CONSTRUCTION), 3, false,
                                       MeterIconSize().x, MeterIconSize().y)});

    // meter and production indicators
    std::vector<std::pair<MeterType, MeterType>> meters;

    for (auto& meter_stat : m_meter_stats) {
        meter_stat.second->InstallEventFilter(shared_from_this());
        AttachChild(meter_stat.second);
        meters.push_back({meter_stat.first, AssociatedMeterType(meter_stat.first)});
    }

    // attach and show meter bars and large resource indicators
    m_multi_icon_value_indicator =  GG::Wnd::Create<MultiIconValueIndicator>(Width() - 2*EDGE_PAD,   m_popcenter_id, meters);
    m_multi_meter_status_bar =      GG::Wnd::Create<MultiMeterStatusBar>(Width() - 2*EDGE_PAD,       m_popcenter_id, meters);

    // determine if this panel has been created yet.
    std::map<int, bool>::iterator it = s_expanded_map.find(m_popcenter_id);
    if (it == s_expanded_map.end())
        s_expanded_map[m_popcenter_id] = false; // if not, default to collapsed state

    Refresh();
}
Ejemplo n.º 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();
}
Ejemplo n.º 6
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 colonies without positive population, and change to outposts
    if (!SpeciesName().empty() && GetMeter(METER_POPULATION)->Current() <= 0.0f) {
        if (Empire* empire = GetEmpire(this->Owner())) {
            empire->AddSitRepEntry(CreatePlanetDepopulatedSitRep(this->ID()));

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

    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();
}
Ejemplo n.º 7
0
bool WantToContinue(creatureADT *creatureP,int num,double *time)
{
	int i;
	int *k;
	string str;
	symtabADT symtab=NewSymbolTable();

	
	for (i=0;i<=num-1;i++)
	{
		if ( Lookup ( symtab  ,SpeciesName ( GetSpecies (creatureP[i]) ) )==UNDEFINED )
		{
			k=GetBlock(sizeof (int) );
			*k=1;
			Enter( symtab , SpeciesName ( GetSpecies (creatureP[i]) ) , k);
		}
		else 
		{
			k=(int*)Lookup(symtab,SpeciesName ( GetSpecies (creatureP[i]) ));
			*k=*k+1;
		}
	}
	printf("\nInventory:\n");
	MapSymbolTable(PrintInventory,symtab,NULL);
	FreeSymbolTable(symtab);

	ChangeTimeInterval(time);
	
	while(TRUE)
	{
		printf("\npress s+Enter to stop and c+Enter to continue :");
		str=GetLine();
		if (StringEqual(str,"s"))  {return FALSE;}
		if (StringEqual(str,"c")) 
		{
			printf("\nTo pause,click mouse on the graph.\n");
			return TRUE;
		}
	}
}
Ejemplo n.º 8
0
std::vector<std::string> Planet::AvailableFoci() const {
    std::vector<std::string> retval;
    auto this_planet = std::dynamic_pointer_cast<const Planet>(UniverseObject::shared_from_this());
    if (!this_planet)
        return retval;
    ScriptingContext context(this_planet);
    if (const auto* species = GetSpecies(this_planet->SpeciesName())) {
        for (const auto& focus_type : species->Foci()) {
            if (const auto* location = focus_type.Location()) {
                if (location->Eval(context, this_planet))
                    retval.push_back(focus_type.Name());
            }
        }
    }

    return retval;
}
Ejemplo n.º 9
0
bool PopulationPanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    MeterType meter_type = INVALID_METER_TYPE;
    for (const auto& meter_stat : m_meter_stats) {
        if (meter_stat.second.get() == w) {
            meter_type = meter_stat.first;
            break;
        }
    }
    if (meter_type == INVALID_METER_TYPE)
        return false;

    std::string meter_string = boost::lexical_cast<std::string>(meter_type);
    std::string meter_title;
    if (UserStringExists(meter_string))
        meter_title = UserString(meter_string);

    std::string species_name;
    bool retval = false;

    auto popup = GG::Wnd::Create<CUIPopupMenu>(pt.x, pt.y);
    auto pc = GetPopCenter();
    if (meter_type == METER_POPULATION && pc) {
        species_name = pc->SpeciesName();
        if (!species_name.empty()) {
            auto zoom_species_action = [&retval, &species_name]() { retval = ClientUI::GetClientUI()->ZoomToSpecies(species_name); };
            std::string species_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(species_name));
            popup->AddMenuItem(GG::MenuItem(species_label, false, false, zoom_species_action));
        }
    }

    if (!meter_title.empty()) {
        auto pedia_meter_type_action = [&retval, &meter_string]() { retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string); };
        std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % meter_title);
        popup->AddMenuItem(GG::MenuItem(popup_label, false, false, pedia_meter_type_action));
    }

    popup->Run();
    return retval;
}
Ejemplo n.º 10
0
bool Ship::HasTag(const std::string& name) const {
    const ShipDesign* design = GetShipDesign(m_design_id);
    if (design) {
        // check hull for tag
        const HullType* hull = ::GetHullType(design->Hull());
        if (hull && hull->Tags().count(name))
            return true;

        // check parts for tag
        const std::vector<std::string>& parts = design->Parts();
        for (std::vector<std::string>::const_iterator part_it = parts.begin(); part_it != parts.end(); ++part_it) {
            const PartType* part = GetPartType(*part_it);
            if (part && part->Tags().count(name))
                return true;
        }
    }
    // check species for tag
    const Species* species = GetSpecies(SpeciesName());
    if (species && species->Tags().count(name))
        return true;

    return false;
}
Ejemplo n.º 11
0
void SpeciesManager::UpdatePopulationCounter() {
    // ships of each species and design
    m_species_object_populations.clear();
    for (const auto& entry : Objects().ExistingObjects()) {
        auto obj = entry.second;
        if (obj->ObjectType() != OBJ_PLANET && obj->ObjectType() != OBJ_POP_CENTER)
            continue;

        auto pop_center = std::dynamic_pointer_cast<PopCenter>(obj);
        if (!pop_center)
            continue;

        const std::string& species = pop_center->SpeciesName();
        if (species.empty())
            continue;

        try {
            m_species_object_populations[species][obj->ID()] += obj->CurrentMeterValue(METER_POPULATION);
        } catch (...) {
            continue;
        }
    }
}
Ejemplo n.º 12
0
bool Planet::HasTag(const std::string& name) const {
    const Species* species = GetSpecies(SpeciesName());

    return species && species->Tags().count(name);
}
Ejemplo n.º 13
0
std::set<std::string> Planet::Tags() const {
    const Species* species = GetSpecies(SpeciesName());
    if (!species)
        return std::set<std::string>();
    return species->Tags();
}