示例#1
0
文件: follow.cpp 项目: xaldin/dfhack
DFhackCExport command_result plugin_onupdate ( Core * c )
{
    if (!followedUnit) return CR_OK; //Don't do anything if we're not following a unit

    DFHack::World *world =c->getWorld();
    if (world->ReadPauseState() && prevX==-1) return CR_OK; //Wait until the game is unpaused after first running "follow" to begin following

    df::coord &unitPos = followedUnit->pos;

    Gui *gui = c->getGui();  //Get all of the relevant data for determining the size of the map on the window
    int32_t x,y,z,w,h,c_x,c_y,c_z;
    uint8_t menu_width, area_map_width;
    gui->getViewCoords(x,y,z);
    gui->getWindowSize(w,h);
    gui->getMenuWidth(menu_width, area_map_width);
    gui->getCursorCoords(c_x,c_y,c_z);

    if (c_z == -3000 && menu_width == 3) menu_width = 2; //Presence of the cursor means that there's actually a width-2 menu open

    h -= 2; //account for vertical borders

    if (menu_width == 1) w -= 57; //Menu is open doubly wide
    else if (menu_width == 2 && area_map_width == 3) w -= 33; //Just the menu is open
    else if (menu_width == 2 && area_map_width == 2) w -= 26; //Just the area map is open
    else w -= 2; //No menu or area map, just account for borders

    if (prevMenuWidth == 0) prevMenuWidth = menu_width; //have we already had a menu width?

    if (prevX==-1) //have we already had previous values for the window location?
    {
        prevX = x;
        prevY = y;
        prevZ = z;
    }
    else if((prevX != x || prevY != y || prevZ != z) && prevMenuWidth == menu_width) //User has manually moved the window, stop following the unit
    {
        followedUnit = 0;
        prevX=prevY=prevZ = -1;
        prevMenuWidth = 0;
        c->con.print("No longer following anything.\n");
        return CR_OK;
    }

    uint32_t x_max, y_max, z_max;
    Simple::Maps::getSize(x_max, y_max, z_max); //Get map size in tiles so we can prevent the camera from going off the edge
    x_max *= 16;
    y_max *= 16;

    x = unitPos.x + w/2 >= x_max ? x_max-w : (unitPos.x >= w/2 ? unitPos.x - w/2 : 0); //Calculate a new screen position centered on the selected unit
    y = unitPos.y + h/2 >= y_max ? y_max-h : (unitPos.y >= h/2 ? unitPos.y - h/2 : 0);
    z = unitPos.z;

    gui->setViewCoords(x, y, z); //Set the new screen position!

    if (c_x != 3000 && !world->ReadPauseState()) gui->setCursorCoords(c_x - (prevX-x), c_y - (prevY-y), z); //If, for some reason, the cursor is active and the screen is still moving, move the cursor along with the screen

    prevX = x; //Save this round's stuff for next time so we can monitor for changes made by the user
    prevY = y;
    prevZ = z;
    prevMenuWidth = menu_width;

    return CR_OK;
}
示例#2
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;
}
示例#3
0
int main (int numargs, char ** args)
{
    DFHack::World * World;
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context* DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    string check = "";
    if(numargs == 2)
        check = args[1];
    
    Creatures = DF->getCreatures();
    Materials = DF->getMaterials();
    World = DF->getWorld();
    current_year = World->ReadCurrentYear();
    current_tick = World->ReadCurrentTick();
    DFHack::Translation * Tran = DF->getTranslation();
    
    uint32_t numCreatures;
    if(!Creatures->Start(numCreatures))
    {
        cerr << "Can't get creatures" << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    if(!numCreatures)
    {
        cerr << "No creatures to print" << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }

    mem = DF->getMemoryInfo();
    Materials->ReadInorganicMaterials();
    Materials->ReadOrganicMaterials();
    Materials->ReadWoodMaterials();
    Materials->ReadPlantMaterials();
    Materials->ReadCreatureTypes();
    Materials->ReadCreatureTypesEx();
    Materials->ReadDescriptorColors();

    if(!Tran->Start())
    {
        cerr << "Can't get name tables" << endl;
        return 1;
    }
    vector<uint32_t> addrs;
    //DF.InitViewAndCursor();
    for(uint32_t i = 0; i < numCreatures; i++)
    {
		printf("%d/%d\n", i, numCreatures);
        DFHack::t_creature temp;
        Creatures->ReadCreature(i,temp);
        if(check.empty() || string(Materials->raceEx[temp.race].rawname) == check)
        {
            cout << "index " << i << " ";
            
            printCreature(DF,temp);
            addrs.push_back(temp.origin);
        }
		printf("!\n");
    }
    if(addrs.size() <= 10)
    {
        interleave_hex(DF,addrs,200);
    }
    /*
    uint32_t currentIdx;
    DFHack::t_creature currentCreature;
    DF.getCurrentCursorCreature(currentIdx);
    cout << "current creature at index " << currentIdx << endl;

    DF.ReadCreature(currentIdx, currentCreature);
    printCreature(DF,currentCreature);
    */
	
    Creatures->Finish();
    DF->Detach();
    #ifndef LINUX_BUILD
    cout << "Done. Press any key to continue" << endl;
    cin.ignore();
    #endif
    return 0;
}
示例#4
0
int main (void)
{
    bool temporary_terminal = TemporaryTerminal();
    uint32_t x_max,y_max,z_max;
    DFHack::designations40d designations;
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context *DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }
    DFHack::Maps *Maps =DF->getMaps();
    DFHack::World *World =DF->getWorld();
    // walk the map, save the hide bits, reveal.
    cout << "Pausing..." << endl;

    // horrible hack to make sure the pause is really set
    // preblem here is that we could be 'arriving' at the wrong time and DF could be in the middle of a frame.
    // that could mean that revealing, even with suspending DF's thread, would mean unleashing hell *in the same frame* 
    // this here hack sets the pause state, resumes DF, waits a second for it to enter the pause (I know, BS value.) and suspends.
    World->SetPauseState(true);
    DF->Resume();
    waitmsec(1000);
    DF->Suspend();

    // init the map
    if(!Maps->Start())
    {
        cerr << "Can't init map." << endl;
        if(temporary_terminal)
            cin.ignore();
        return 1;
    }

    cout << "Revealing, please wait..." << endl;

    Maps->getSize(x_max,y_max,z_max);
    vector <hideblock> hidesaved;

    for(uint32_t x = 0; x< x_max;x++)
    {
        for(uint32_t y = 0; y< y_max;y++)
        {
            for(uint32_t z = 0; z< z_max;z++)
            {
                if(Maps->isValidBlock(x,y,z))
                {
                    hideblock hb;
                    hb.x = x;
                    hb.y = y;
                    hb.z = z;
                    // read block designations
                    Maps->ReadDesignations(x,y,z, &designations);
                    // change the hidden flag to 0
                    for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
                    {
                        hb.hiddens[i][j] = designations[i][j].bits.hidden;
                        designations[i][j].bits.hidden = 0;
                    }
                    hidesaved.push_back(hb);
                    // write the designations back
                    Maps->WriteDesignations(x,y,z, &designations);
                }
            }
        }
    }
    // FIXME: force game pause here!
    DF->Detach();
    cout << "Map revealed. The game has been paused for you." << endl;
    cout << "Unpausing can unleash the forces of hell!" << endl << endl;
    cout << "Press any key to unreveal." << endl;
    cout << "Close to keep the map revealed !!FOREVER!!" << endl;
    cin.ignore();
    cout << "Unrevealing... please wait." << endl;
    // FIXME: do some consistency checks here!
    DF->Attach();
    Maps = DF->getMaps();
    Maps->Start();
    for(size_t i = 0; i < hidesaved.size();i++)
    {
        hideblock & hb = hidesaved[i];
        Maps->ReadDesignations(hb.x,hb.y,hb.z, &designations);
        for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
        {
            designations[i][j].bits.hidden = hb.hiddens[i][j];
        }
        Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations);
    }
    if(temporary_terminal)
    {
        cout << "Done. Press any key to continue" << endl;
        cin.ignore();
    }
    return 0;
}
示例#5
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;
}