示例#1
0
文件: weather.cpp 项目: M-funk/dfhack
command_result weather (color_ostream &con, vector <string> & parameters)
{
    int val_override = -1;
    bool lock = false;
    bool unlock = false;
    bool snow = false;
    bool rain = false;
    bool clear = false;
    for(size_t i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "rain")
            rain = true;
        else if(parameters[i] == "snow")
            snow = true;
        else if(parameters[i] == "clear")
            clear = true;
        else if(parameters[i] == "lock")
            lock = true;
        else if(parameters[i] == "unlock")
            unlock = true;
        else
        {
            val_override = atoi(parameters[i].c_str());
            if(val_override == 0)
                return CR_WRONG_USAGE;
        }
    }
    if(lock && unlock)
    {
        con << "Lock or unlock? DECIDE!" << std::endl;
        return CR_FAILURE;
    }
    int cnt = 0;
    cnt += rain;
    cnt += snow;
    cnt += clear;
    if(cnt > 1)
    {
        con << "Rain, snow or clear sky? DECIDE!" << std::endl;
        return CR_FAILURE;
    }
    bool something = lock || unlock || rain || snow || clear || val_override != -1;

    CoreSuspender suspend;

    DFHack::World * w = Core::getInstance().getWorld();
    if(!w->wmap)
    {
        con << "Weather support seems broken :(" << std::endl;
        return CR_FAILURE;
    }
    if(!something)
    {
        // paint weather map
        con << "Weather map (C = clear, R = rain, S = snow):" << std::endl;
        for(int y = 0; y<5;y++)
        {
            for(int x = 0; x<5;x++)
            {
                switch((*w->wmap)[x][y])
                {
                case CLEAR:
                    con << "C ";
                    break;
                case RAINING:
                    con << "R ";
                    break;
                case SNOWING:
                    con << "S ";
                    break;
                default:
                    con << (int) (*w->wmap)[x][y] << " ";
                    break;
                }
            }
            con << std::endl;
        }
    }
    else
    {
        // weather changing action!
        if(rain)
        {
            con << "Here comes the rain." << std::endl;
            w->SetCurrentWeather(RAINING);
        }
        if(snow)
        {
            con << "Snow everywhere!" << std::endl;
            w->SetCurrentWeather(SNOWING);
        }
        if(clear)
        {
            con << "Suddenly, sunny weather!" << std::endl;
            w->SetCurrentWeather(CLEAR);
        }
        if(val_override != -1)
        {
            con << "I have no damn idea what this is... " << val_override << std::endl;
            w->SetCurrentWeather(val_override);
        }
        // FIXME: weather lock needs map ID to work reliably... needs to be implemented.
    }
    return CR_OK;
}
示例#2
0
文件: weather.cpp 项目: kaypy/dfhack
DFhackCExport command_result weather (Core * c, vector <string> & parameters)
{
    Console & con = c->con;
    bool lock = false;
    bool unlock = false;
    bool snow = false;
    bool rain = false;
    bool clear = false;
    bool help = false;
    for(int i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "rain")
            rain = true;
        else if(parameters[i] == "snow")
            snow = true;
        else if(parameters[i] == "clear")
            clear = true;
        else if(parameters[i] == "lock")
            lock = true;
        else if(parameters[i] == "unlock")
            unlock = true;
        else if(parameters[i] == "help" || parameters[i] == "?")
            help = true;
    }
    if(help)
    {
        c->con.print("Prints the current weather map by default.\n"
                     "Options:\n"
                     "snow   - make it snow everywhere.\n"
                     "rain   - make it rain.\n"
                     "clear  - clear the sky.\n"
        );
        return CR_OK;
    }
    if(lock && unlock)
    {
        con << "Lock or unlock? DECIDE!" << std::endl;
        return CR_FAILURE;
    }
    int cnt = 0;
    cnt += rain;
    cnt += snow;
    cnt += clear;
    if(cnt > 1)
    {
        con << "Rain, snow or clear sky? DECIDE!" << std::endl;
        return CR_FAILURE;
    }
    bool something = lock || unlock || rain || snow || clear;
    c->Suspend();
    DFHack::World * w = c->getWorld();
    if(!w->wmap)
    {
        con << "Weather support seems broken :(" << std::endl;
        c->Resume();
        return CR_FAILURE;
    }
    if(!something)
    {
        // paint weather map
        con << "Weather map (C = clear, R = rain, S = snow):" << std::endl;
        for(int y = 0; y<5;y++)
        {
            for(int x = 0; x<5;x++)
            {
                switch((*w->wmap)[x][y])
                {
                    case DFHack::CLEAR:
                        con << "C ";
                        break;
                    case DFHack::RAINING:
                        con << "R ";
                        break;
                    case DFHack::SNOWING:
                        con << "S ";
                        break;
                    default:
                        con << (int) (*w->wmap)[x][y] << " ";
                        break;
                }
            }
            con << std::endl;
        }
    }
    else
    {
        // weather changing action!
        if(rain)
        {
            con << "Here comes the rain." << std::endl;
            w->SetCurrentWeather(RAINING);
        }
        if(snow)
        {
            con << "Snow everywhere!" << std::endl;
            w->SetCurrentWeather(SNOWING);
        }
        if(clear)
        {
            con << "Suddenly, sunny weather!" << std::endl;
            w->SetCurrentWeather(CLEAR);
        }
        // FIXME: weather lock needs map ID to work reliably... needs to be implemented.
    }
    c->Resume();
    return CR_OK;
}