Beispiel #1
0
void PopCenter::Init() {
    //Logger().debugStream() << "PopCenter::Init";
    AddMeter(METER_POPULATION);
    AddMeter(METER_TARGET_POPULATION);
    AddMeter(METER_HAPPINESS);
    AddMeter(METER_TARGET_HAPPINESS);
}
Beispiel #2
0
void Planet::Init() {
    AddMeter(METER_SUPPLY);
    AddMeter(METER_MAX_SUPPLY);
    AddMeter(METER_SHIELD);
    AddMeter(METER_MAX_SHIELD);
    AddMeter(METER_DEFENSE);
    AddMeter(METER_MAX_DEFENSE);
    AddMeter(METER_TROOPS);
    AddMeter(METER_MAX_TROOPS);
    AddMeter(METER_DETECTION);
    AddMeter(METER_REBEL_TROOPS);
}
Beispiel #3
0
void NetworkTemporal3::NetworkSetupMeters()
{
    m_structureInput->SetupMeters(this->MPIGetNodeId(),this->MPIGetNrProcs());

    m_inputMeter = new Meter("inputLayer.csv", Storage::CSV);
    m_inputMeter->AttachPopulation(m_layerInput);
    AddMeter(m_inputMeter);

    m_layer1Meter = new Meter("layer1.csv", Storage::CSV);
    m_layer1Meter->AttachPopulation(m_layer2);
    AddMeter(m_layer1Meter);
}
void NetworkTemporal3BCPNN::NetworkSetupMeters()
{
	m_structureInput->SetupMeters(this->MPIGetNodeId(),this->MPIGetNrProcs());
	m_activityMeter = new Meter("ClassOutput.csv",Storage::CSV);
	m_activityMeter->AttachPopulation(m_layer3);
	//m_activityMeter->SwitchOnOff(false);
	AddMeter(m_activityMeter);
	m_inputMeter = new Meter("inputLayer.csv", Storage::CSV);
	m_inputMeter->AttachPopulation(m_layerInput);
	AddMeter(m_inputMeter);

	m_layer1Meter = new Meter("layer1.csv", Storage::CSV);
	m_layer1Meter->AttachPopulation(m_layer2);
	AddMeter(m_layer1Meter);
}
Beispiel #5
0
Field::Field(const std::string& field_type, double x, double y, double radius) :
    UniverseObject("", x, y),
    m_type_name(field_type)
{
    const FieldType* type = GetFieldType(m_type_name);
    if (type)
        Rename(UserString(type->Name()));
    else
        Rename(UserString("ENC_FIELD"));

    UniverseObject::Init();

    AddMeter(METER_SPEED);
    AddMeter(METER_SIZE);

    UniverseObject::GetMeter(METER_SIZE)->Set(radius, radius);
}
Beispiel #6
0
void ResourceCenter::Init() {
    //Logger().debugStream() << "ResourceCenter::Init";
    AddMeter(METER_INDUSTRY);
    AddMeter(METER_RESEARCH);
    AddMeter(METER_TRADE);
    AddMeter(METER_CONSTRUCTION);
    AddMeter(METER_TARGET_INDUSTRY);
    AddMeter(METER_TARGET_RESEARCH);
    AddMeter(METER_TARGET_TRADE);
    AddMeter(METER_TARGET_CONSTRUCTION);
    m_focus.clear();
}
Beispiel #7
0
void ResourceCenter::Init() {
    //DebugLogger() << "ResourceCenter::Init";
    AddMeter(METER_INDUSTRY);
    AddMeter(METER_RESEARCH);
    AddMeter(METER_TRADE);
    AddMeter(METER_CONSTRUCTION);
    AddMeter(METER_TARGET_INDUSTRY);
    AddMeter(METER_TARGET_RESEARCH);
    AddMeter(METER_TARGET_TRADE);
    AddMeter(METER_TARGET_CONSTRUCTION);
    m_focus.clear();
    m_last_turn_focus_changed = INVALID_GAME_TURN;
    m_focus_turn_initial.clear();
    m_last_turn_focus_changed_turn_initial = INVALID_GAME_TURN;
}
Beispiel #8
0
void UniverseObject::Init()
{ AddMeter(METER_STEALTH); }
Beispiel #9
0
Ship::Ship(int empire_id, int design_id, const std::string& species_name,
           int produced_by_empire_id/* = ALL_EMPIRES*/) :
    UniverseObject(),
    m_design_id(design_id),
    m_fleet_id(INVALID_OBJECT_ID),
    m_ordered_scrapped(false),
    m_ordered_colonize_planet_id(INVALID_OBJECT_ID),
    m_ordered_invade_planet_id(INVALID_OBJECT_ID),
    m_ordered_bombard_planet_id(INVALID_OBJECT_ID),
    m_last_turn_active_in_combat(INVALID_GAME_TURN),
    m_species_name(species_name),
    m_produced_by_empire_id(produced_by_empire_id),
    m_arrived_on_turn(CurrentTurn())
{
    if (!GetShipDesign(design_id))
        throw std::invalid_argument("Attempted to construct a Ship with an invalid design id");

    if (!m_species_name.empty() && !GetSpecies(m_species_name))
        DebugLogger() << "Ship created with invalid species name: " << m_species_name;

    SetOwner(empire_id);

    UniverseObject::Init();

    AddMeter(METER_FUEL);
    AddMeter(METER_MAX_FUEL);
    AddMeter(METER_SHIELD);
    AddMeter(METER_MAX_SHIELD);
    AddMeter(METER_DETECTION);
    AddMeter(METER_STRUCTURE);
    AddMeter(METER_MAX_STRUCTURE);
    AddMeter(METER_SPEED);
    AddMeter(METER_TARGET_INDUSTRY);
    AddMeter(METER_INDUSTRY);
    AddMeter(METER_TARGET_RESEARCH);
    AddMeter(METER_RESEARCH);
    AddMeter(METER_TARGET_TRADE);
    AddMeter(METER_TRADE);

    const std::vector<std::string>& part_names = Design()->Parts();
    for (std::size_t i = 0; i < part_names.size(); ++i) {
        if (part_names[i] != "") {
            const PartType* part = GetPartType(part_names[i]);
            if (!part) {
                ErrorLogger() << "Ship::Ship couldn't get part with name " << part_names[i];
                continue;
            }

            switch (part->Class()) {
            case PC_COLONY:
            case PC_TROOPS: {
                m_part_meters[std::make_pair(METER_CAPACITY, part->Name())];
                break;
            }
            case PC_DIRECT_WEAPON:      // capacity is damage, secondary stat is shots per attack
            case PC_FIGHTER_HANGAR: {   // capacity is how many fighters contained, secondary stat is damage per fighter attack
                m_part_meters[std::make_pair(METER_SECONDARY_STAT,      part->Name())];
                m_part_meters[std::make_pair(METER_MAX_SECONDARY_STAT,  part->Name())];
                // intentionally no break here
            }
            case PC_FIGHTER_BAY: {      // capacity is how many fighters launched per combat round
                m_part_meters[std::make_pair(METER_CAPACITY,            part->Name())];
                m_part_meters[std::make_pair(METER_MAX_CAPACITY,        part->Name())];
                break;
            }
            default:
                break;
            }
        }
    }
}
Beispiel #10
0
int ReadSearchDefine(const char *filepath, SearchDefine **sd)
{
    int res = 1, i, j;

    char * buf;
    cJSON * root = NULL, * item;

    printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    printf("\n>Reading %s...", filepath);

    if ((buf = get_file_content(filepath)) == NULL)
    {
        perror("\n>Cannot open SearchDefine json file!");
        return -1;
    }

    if ((root = cJSON_Parse(buf)) == NULL)
    {
        perror("\n>Cannot read SearchDefine json file!");
        return -1;
    }

    // check file format
    if ((item = cJSON_GetObjectItem(root, "Type")) == NULL)
    {
        perror("\n>Not SearchDefine json file!");
        return -1;
    }

    if (strcmp("SearchDefine", item->valuestring) != 0)
    {
        perror("\n>Not SearchDefine json file!");
        return -1;
    }

    // read department id
    if ((item = cJSON_GetObjectItem(root, "DepartmentID")) == NULL)
    {
        perror("\n>SearchDefine json file missing 'DepartmentID'!");
        return -1;
    }

    // TODO: 释放所有元素空间
    free(*sd);
    *sd = (SearchDefine *)malloc(sizeof(SearchDefine));
    (*sd)->DepartmentID = (char *)malloc(strlen(item->valuestring));
    strncpy((*sd)->DepartmentID, item->valuestring, strlen(item->valuestring));
    printf("\n>DepartmentID: %s", (*sd)->DepartmentID);

    // read switchgear id
    if ((item = cJSON_GetObjectItem(root, "SwitchgearID")) == NULL)
    {
        perror("\n>SearchDefine json file missing 'SwitchgearID'!");
        return -1;
    }

    (*sd)->SwitchgearID = (char *)malloc(strlen(item->valuestring));
    strncpy((*sd)->SwitchgearID, item->valuestring, strlen(item->valuestring));
    printf("\n>SwitchgearID: %s", (*sd)->SwitchgearID);

    // read meter array
    if ((item = cJSON_GetObjectItem(root, "Meters")) == NULL)
    {
        perror("\n>SearchDefine json file missing 'Meters'!");
        return -1;
    }

    if (item->type != cJSON_Array)
    {
        perror("\n>SearchDefine json file 'Meters' is not an array!");
        return -1;
    }

    int num = cJSON_GetArraySize(item);
    cJSON *meterItem, *meterItemTemp;

    for (i = 0; i < num; i++)
    {
        Meter *mt = (Meter *)malloc(sizeof(Meter));

        meterItem = cJSON_GetArrayItem(item, i);

        // read meter id
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "ID")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'ID'!", i);
            continue;
        }

        mt->ID = (char *)malloc(strlen(meterItemTemp->valuestring));
        strncpy(mt->ID, meterItemTemp->valuestring, strlen(meterItemTemp->valuestring));
        printf("\n>  Meter NO: %d 'ID': %s", i, mt->ID);

        // read meter node address
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "NodeAddress")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'NodeAddress'!", i);
            continue;
        }

        mt->NodeAddress = meterItemTemp->valueint;
        printf("\n>  Meter NO: %d 'NodeAddress': %d", i, mt->NodeAddress);

        // read meter command
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "Command")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'Command'!", i);
            continue;
        }

        mt->Command = meterItemTemp->valueint;
        printf("\n>  Meter NO: %d 'Command': %d", i, mt->Command);

        // read meter start address
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "StartAddress")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'StartAddress'!", i);
            continue;
        }

        mt->StartAddress = strtol(meterItemTemp->valuestring, NULL, 16);
        printf("\n>  Meter NO: %d 'StartAddress': 0x%04X", i, mt->StartAddress);

        // read meter register count
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "RegisterCount")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'RegisterCount'!", i);
            continue;
        }

        mt->RegisterCount = meterItemTemp->valueint;
        printf("\n>  Meter NO: %d 'RegisterCount': %d", i, mt->RegisterCount);

        ///////////////////////////////////////////////////////////////////////////////////////////
        // read meter array
        if ((meterItemTemp = cJSON_GetObjectItem(meterItem, "Samples")) == NULL)
        {
            printf("\n>  SearchDefine json file Meter NO: %d missing 'Samples'!", i);
            continue;
        }

        if (meterItemTemp->type != cJSON_Array)
        {
            printf("\n>  SearchDefine json file Meter NO: %d 'Samples' is not an array!", i);
            continue;
        }

        int sampleNum = cJSON_GetArraySize(meterItemTemp);
        cJSON *sampleItem, *sampleItemTemp;

        for (j = 0; j < sampleNum; j++)
        {
            Sample *sm = (Sample *)malloc(sizeof(Sample));

            // read sample array
            sampleItem = cJSON_GetArrayItem(meterItemTemp, j);

            // read sample name
            if ((sampleItemTemp = cJSON_GetObjectItem(sampleItem, "Name")) == NULL)
            {
                printf("\n>    SearchDefine json file Meter NO: %d Sample NO: %d missing 'Name'!", i, j);
                continue;
            }

            sm->Name = (char *)malloc(strlen(sampleItemTemp->valuestring));
            strncpy(sm->Name, sampleItemTemp->valuestring, strlen(sampleItemTemp->valuestring));
            printf("\n>    Meter NO: %d Sample NO: %d 'Name': %s", i, j, sm->Name);

            // read sample value type
            if ((sampleItemTemp = cJSON_GetObjectItem(sampleItem, "ValueType")) == NULL)
            {
                printf("\n>    SearchDefine json file Meter NO: %d Sample NO: %d missing 'ValueType'!", i, j);
                continue;
            }

            if (strcmp("Float", sampleItemTemp->valuestring) == 0)
            {
                sm->ValueType = SampleValueType_Float;
            } else if (strcmp("Bit", sampleItemTemp->valuestring) == 0)
            {
                sm->ValueType = SampleValueType_Bit;
            } else
            {
                sm->ValueType = SampleValueType_Unknown;
            }
            printf("\n>    Meter NO: %d Sample NO: %d 'ValueType': %d", i, j, sm->ValueType);

            AddSample(mt, sm);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////

        AddMeter((*sd), mt);
    }

    //ShowSearchDefine((*sd));

    free(buf);
    cJSON_Delete(root);

    printf("\n>Reading %s completed!", filepath);
    printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    fflush(stdout);

    return res;
}
Beispiel #11
0
Ship::Ship(int empire_id, int design_id, const std::string& species_name,
           int produced_by_empire_id/* = ALL_EMPIRES*/) :
    m_design_id(design_id),
    m_fleet_id(INVALID_OBJECT_ID),
    m_ordered_scrapped(false),
    m_ordered_colonize_planet_id(INVALID_OBJECT_ID),
    m_ordered_invade_planet_id(INVALID_OBJECT_ID),
    m_ordered_bombard_planet_id(INVALID_OBJECT_ID),
    m_last_turn_active_in_combat(INVALID_GAME_TURN),
    m_species_name(species_name),
    m_produced_by_empire_id(produced_by_empire_id)
{
    if (!GetShipDesign(design_id))
        throw std::invalid_argument("Attempted to construct a Ship with an invalid design id");

    if (!m_species_name.empty() && !GetSpecies(m_species_name))
        Logger().debugStream() << "Ship created with invalid species name: " << m_species_name;

    SetOwner(empire_id);

    UniverseObject::Init();

    AddMeter(METER_FUEL);
    AddMeter(METER_MAX_FUEL);
    AddMeter(METER_SHIELD);
    AddMeter(METER_MAX_SHIELD);
    AddMeter(METER_DETECTION);
    AddMeter(METER_STRUCTURE);
    AddMeter(METER_MAX_STRUCTURE);
    AddMeter(METER_BATTLE_SPEED);
    AddMeter(METER_STARLANE_SPEED);

    const std::vector<std::string>& part_names = Design()->Parts();
    for (std::size_t i = 0; i < part_names.size(); ++i) {
        if (part_names[i] != "") {
            const PartType* part = GetPartType(part_names[i]);
            if (!part) {
                Logger().errorStream() << "Ship::Ship couldn't get part with name " << part_names[i];
                continue;
            }

            switch (part->Class()) {
            case PC_SHORT_RANGE:
            case PC_POINT_DEFENSE: {
                m_part_meters[std::make_pair(METER_DAMAGE,              part->Name())];
                m_part_meters[std::make_pair(METER_ROF,                 part->Name())];
                m_part_meters[std::make_pair(METER_RANGE,               part->Name())];
                break;
            }
            case PC_MISSILES: {
                std::pair<std::size_t, std::size_t>& part_missiles =
                    m_missiles[part_names[i]];
                ++part_missiles.first;
                part_missiles.second += boost::get<LRStats>(part->Stats()).m_capacity;
                m_part_meters[std::make_pair(METER_DAMAGE,              part->Name())];
                m_part_meters[std::make_pair(METER_ROF,                 part->Name())];
                m_part_meters[std::make_pair(METER_RANGE,               part->Name())];
                m_part_meters[std::make_pair(METER_SPEED,               part->Name())];
                m_part_meters[std::make_pair(METER_STEALTH,             part->Name())];
                m_part_meters[std::make_pair(METER_STRUCTURE,           part->Name())];
                m_part_meters[std::make_pair(METER_CAPACITY,            part->Name())];
                break;
            }
            case PC_FIGHTERS: {
                std::pair<std::size_t, std::size_t>& part_fighters =
                    m_fighters[part_names[i]];
                ++part_fighters.first;
                part_fighters.second += boost::get<FighterStats>(part->Stats()).m_capacity;
                m_part_meters[std::make_pair(METER_ANTI_SHIP_DAMAGE,    part->Name())];
                m_part_meters[std::make_pair(METER_ANTI_FIGHTER_DAMAGE, part->Name())];
                m_part_meters[std::make_pair(METER_LAUNCH_RATE,         part->Name())];
                m_part_meters[std::make_pair(METER_FIGHTER_WEAPON_RANGE,part->Name())];
                m_part_meters[std::make_pair(METER_SPEED,               part->Name())];
                m_part_meters[std::make_pair(METER_STEALTH,             part->Name())];
                m_part_meters[std::make_pair(METER_STRUCTURE,           part->Name())];
                m_part_meters[std::make_pair(METER_DETECTION,           part->Name())];
                m_part_meters[std::make_pair(METER_CAPACITY,            part->Name())];
                break;
            }
            default:
                break;
            }
        }
    }
}
Beispiel #12
0
void SliderWnd::Knob(SliderKnob *knob) {
    _knob = knob;
    AddMeter(knob);
}