Exemplo n.º 1
0
DFhackCExport command_result bflags (Core * c, vector <string> & parameters)
{
    c->Suspend();
    Gui * g = c-> getGui();
    Maps* m = c->getMaps();
    if(!m->Start())
    {
        c->con.printerr("No map to probe\n");
        return CR_FAILURE;
    }
    int32_t cx,cy,cz;
    g->getCursorCoords(cx,cy,cz);
    if(cx == -30000)
    {
        // get map size in blocks
        uint32_t sx,sy,sz;
        m->getSize(sx,sy,sz);
        std::map <uint8_t, df_block *> counts;
        // for each block
        for(size_t x = 0; x < sx; x++)
            for(size_t y = 0; y < sx; y++)
                for(size_t z = 0; z < sx; z++)
                {
                    df_block * b = m->getBlock(x,y,z);
                    if(!b) continue;
                    auto iter = counts.find(b->flags.size);
                    if(iter == counts.end())
                    {
                        counts[b->flags.bits[0]] = b;
                    }
                }
        for(auto iter = counts.begin(); iter != counts.end(); iter++)
        {
            c->con.print("%2x : 0x%x\n",iter->first, iter->second);
        }
    }
    else
    {
        df_block * b = m->getBlock(cx/16,cy/16,cz);
        if(b)
        {
            c->con << "Block flags:" << b->flags << std::endl;
        }
        else
        {
            c->con.printerr("No block here\n");
            return CR_FAILURE;
        }
    }
    c->Resume();
    return CR_OK;
}
Exemplo n.º 2
0
DFhackCExport command_result mapitems (Core * c, vector <string> & parameters)
{
    c->Suspend();
    vector <df_item *> vec_items;
    Gui * g = c-> getGui();
    Maps* m = c->getMaps();
    Items* it = c->getItems();
    if(!m->Start())
    {
        c->con.printerr("No map to probe\n");
        return CR_FAILURE;
    }
    if(!it->Start() || !it->readItemVector(vec_items))
    {
        c->con.printerr("Failed to get items\n");
        return CR_FAILURE;
    }
    int32_t cx,cy,cz;
    g->getCursorCoords(cx,cy,cz);
    if(cx != -30000)
    {
        df_block * b = m->getBlock(cx/16,cy/16,cz);
        if(b)
        {
            c->con.print("Item IDs present in block:\n");
            auto iter_b = b->items.begin();
            while (iter_b != b->items.end())
            {
                df_item * itmz = it->findItemByID(*iter_b);
                string s;
                itmz->getItemDescription(&s);
                c->con.print("%d = %s\n",*iter_b, s.c_str());
                iter_b++;
            }
            c->con.print("Items under cursor:\n");
            auto iter_it = vec_items.begin();
            while (iter_it != vec_items.end())
            {
                df_item * itm = *iter_it;
                if(itm->x == cx && itm->y == cy && itm->z == cz)
                {
                    string s;
                    itm->getItemDescription(&s,0);
                    c->con.print("%d = %s\n",itm->id, s.c_str());
                }
                iter_it ++;
            }
        }
    }
    c->Resume();
    return CR_OK;
}
Exemplo n.º 3
0
void ChooseMap<al_b,al_f>::showSection(InputManager<ALLEGRO_EVENT,ALLEGRO_KEYBOARD_STATE> &input,Maps<al_b> &m,Player<al_b> &p,bool st){
	m.showBackground();

	al_draw_text(this->_font30, al_map_rgb(0,0,0), 335, 130, 0, "Escoge un mapa");
	for(int i = 0;i < 3;i++){
		m.loadMap(3,i);
		for(int y = 0; y<m.getHeight();y++){
			for(int x = 0;x<m.getWidth();x++){
		//al_draw_filled_rectangle(80+(250*i)+(12*x), 200+(12*y), 80+(250*i)+((12*x) +12), 200+((12*y )+12), al_map_rgb(255,255,255));

				switch(m.getPositionMap(x,y)){
					case 'p': al_draw_scaled_bitmap(this->_block, 145, 171, 58, 58, 80+(250*i)+(12*x), 200+(12*y), 12, 12, 0);  break;
					case 'j':
					case 'g':
					case 'e': al_draw_filled_rectangle(80+(250*i)+(12*x), 200+(12*y), 80+(250*i)+((12*x) +12), 200+((12*y )+12), al_map_rgb(255,255,255)); break;
					case 'c': al_draw_scaled_bitmap(this->_block, 258, 20, 58, 58, 80+(250*i)+(12*x), 200+(12*y), 12, 12, 0); 	 break;
					case 'd': al_draw_scaled_bitmap(this->_block, 37, 20, 58, 58, 80+(250*i)+(12*x), 200+(12*y), 12, 12, 0); 	 break;
					case 's': al_draw_filled_rectangle(80+(250*i)+(12*x), 200+(12*y), 80+(250*i)+((12*x) +12), 200+((12*y )+12), al_map_rgb(236,236,236)); break;
				}
			}
		}
	}
	m.setLevel(input.getX(0));
	
	al_draw_rectangle(80+(250*input.getX(0)), 200, 320+(250*input.getX(0)), 370, al_map_rgb(140,40,40),5);	
	al_draw_filled_rectangle(360, 385, 540, 430, al_map_rgb(20,20,20));
	al_draw_text(this->_font20, al_map_rgb(255,255,255), 395, 390, 0, "Seleccionar");
}
Exemplo n.º 4
0
DFhackCExport command_result digcircle (Core * c, vector <string> & parameters)
{
    static bool filled = false;
    static circle_what what = circle_set;
    static e_designation type = designation_default;
    static int diameter = 0;
    auto saved_d = diameter;
    bool force_help = false;
    for(int i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            force_help = true;
        }
        else if(parameters[i] == "hollow")
        {
            filled = false;
        }
        else if(parameters[i] == "filled")
        {
            filled = true;
        }
        else if(parameters[i] == "set")
        {
            what = circle_set;
        }
        else if(parameters[i] == "unset")
        {
            what = circle_unset;
        }
        else if(parameters[i] == "invert")
        {
            what = circle_invert;
        }
        else if(parameters[i] == "dig")
        {
            type = designation_default;
        }
        else if(parameters[i] == "ramp")
        {
            type = designation_ramp;
        }
        else if(parameters[i] == "dstair")
        {
            type = designation_d_stair;
        }
        else if(parameters[i] == "ustair")
        {
            type = designation_u_stair;
        }
        else if(parameters[i] == "xstair")
        {
            type = designation_ud_stair;
        }
        else if(parameters[i] == "chan")
        {
            type = designation_channel;
        }
        else if (!from_string(diameter,parameters[i], std::dec))
        {
            diameter = saved_d;
        }
    }
    if(diameter < 0)
        diameter = -diameter;
    if(force_help || diameter == 0)
    {
        c->con.print(   "A command for easy designation of filled and hollow circles.\n"
                        "\n"
                        "Options:\n"
                        " hollow = Set the circle to hollow (default)\n"
                        " filled = Set the circle to filled\n"
                        "\n"
                        "    set = set designation\n"
                        "  unset = unset current designation\n"
                        " invert = invert current designation\n"
                        "\n"
                        "    dig = normal digging\n"
                        "   ramp = ramp digging\n"
                        " ustair = staircase up\n"
                        " dstair = staircase down\n"
                        " xstair = staircase up/down\n"
                        "   chan = dig channel\n"
                        "\n"
                        "      # = diameter in tiles (default = 0)\n"
                        "\n"
                        "After you have set the options, the command called with no options\n"
                        "repeats with the last selected parameters:\n"
                        "'digcircle filled 3' = Dig a filled circle with radius = 3.\n"
                        "'digcircle' = Do it again.\n"
        );
        return CR_OK;
    }
    int32_t cx, cy, cz;
    c->Suspend();
    Gui * gui = c->getGui();
    Maps * maps = c->getMaps();
    if(!maps->Start())
    {
        c->Resume();
        c->con.printerr("Can't init the map...\n");
        return CR_FAILURE;
    }

    uint32_t x_max, y_max, z_max;
    maps->getSize(x_max,y_max,z_max);

    MapExtras::MapCache MCache (maps);
    if(!gui->getCursorCoords(cx,cy,cz) || cx == -30000)
    {
        c->Resume();
        c->con.printerr("Can't get the cursor coords...\n");
        return CR_FAILURE;
    }
    auto dig = [&](int32_t x, int32_t y, int32_t z) -> bool
    {
        DFCoord at (x,y,z);
        auto b = MCache.BlockAt(at/16);
        if(!b || !b->valid)
            return false;
        if(x == 0 || x == x_max * 16 - 1)
        {
            //c->con.print("not digging map border\n");
            return false;
        }
        if(y == 0 || y == y_max * 16 - 1)
        {
            //c->con.print("not digging map border\n");
            return false;
        }
        uint16_t tt = MCache.tiletypeAt(at);
        t_designation des = MCache.designationAt(at);
        // could be potentially used to locate hidden constructions?
        if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
            return false;
        TileShape ts = tileShape(tt);
        if(ts == EMPTY)
            return false;
        if(!des.bits.hidden)
        {
            do
            {
                if(isWallTerrain(tt))
                {
                    std::cerr << "allowing tt" << tt << ", is wall\n";
                    break;
                }
                if(isFloorTerrain(tt)
                   && (type == designation_d_stair || type == designation_channel)
                   && ts != TREE_OK
                   && ts != TREE_DEAD
                )
                {
                    std::cerr << "allowing tt" << tt << ", is floor\n";
                    break;
                }
                if(isStairTerrain(tt) && type == designation_channel )
                    break;
                return false;
            }
            while(0);
        }
        switch(what)
        {
            case circle_set:
                if(des.bits.dig == designation_no)
                {
                    des.bits.dig = type;
                }
                break;
            case circle_unset:
                if (des.bits.dig != designation_no)
                {
                    des.bits.dig = designation_no;
                }
            case circle_invert:
                if(des.bits.dig == designation_no)
                {
                    des.bits.dig = type;
                }
                else
                {
                    des.bits.dig = designation_no;
                }
                break;
        }
        std::cerr << "allowing tt" << tt << "\n";
        MCache.setDesignationAt(at,des);
        return true;
    };
    auto lineX = [&](int32_t y1, int32_t y2, int32_t x, int32_t z) -> bool
    {
        for(int32_t y = y1; y <= y2; y++)
        {
            dig(x,y,z);
        }
        return true;
    };
    auto lineY = [&](int32_t x1, int32_t x2, int32_t y, int32_t z) -> bool
    {
        for(int32_t x = x1; x <= x2; x++)
        {
            dig(x,y,z);
        }
        return true;
    };
    int r = diameter / 2;
    int iter;
    bool adjust;
    if(diameter % 2)
    {
        // paint center
        if(filled)
        {
            lineY(cx - r, cx + r, cy, cz);
        }
        else
        {
            dig(cx - r, cy, cz);
            dig(cx + r, cy, cz);
        }
        adjust = false;
        iter = 2;
    }
    else
    {
        adjust = true;
        iter = 1;
    }
    int lastwhole = r;
    for(; iter <= diameter - 1; iter +=2)
    {
        // top, bottom coords
        int top = cy - ((iter + 1) / 2) + adjust;
        int bottom = cy + ((iter + 1) / 2);
        // see where the current 'line' intersects the circle
        double val = std::sqrt(double(diameter*diameter - iter*iter));
        // adjust for circles with odd diameter
        if(!adjust)
            val -= 1;
        // map the found value to the DF grid
        double whole;
        double fraction = std::modf(val / 2.0, & whole);
        if (fraction > 0.5)
            whole += 1.0;
        int right = cx + whole;
        int left = cx - whole + adjust;
        int diff = lastwhole - whole;
        // paint
        if(filled || iter == diameter - 1)
        {
            lineY(left, right, top , cz);
            lineY(left, right, bottom , cz);
        }
        else
        {
            dig(left, top, cz);
            dig(left, bottom, cz);
            dig(right, top, cz);
            dig(right, bottom, cz);
        }
        if(!filled && diff > 1)
        {
            int lright = cx + lastwhole;
            int lleft = cx - lastwhole + adjust;
            lineY(lleft + 1, left - 1, top + 1 , cz);
            lineY(right + 1, lright - 1, top + 1 , cz);
            lineY(lleft + 1, left - 1, bottom - 1 , cz);
            lineY(right + 1, lright - 1, bottom - 1 , cz);
        }
        lastwhole = whole;
    }
    MCache.WriteAll();
    c->Resume();
    return CR_OK;
}
Exemplo n.º 5
0
DFhackCExport command_result expdig (Core * c, vector <string> & parameters)
{
    bool force_help = false;
    static explo_how how = EXPLO_NOTHING;
    static explo_what what = EXPLO_HIDDEN;
    for(int i = 0; i < parameters.size();i++)
    {
        if(parameters[i] == "help" || parameters[i] == "?")
        {
            force_help = true;
        }
        else if(parameters[i] == "all")
        {
            what = EXPLO_ALL;
        }
        else if(parameters[i] == "hidden")
        {
            what = EXPLO_HIDDEN;
        }
        else if(parameters[i] == "designated")
        {
            what = EXPLO_DESIGNATED;
        }
        else if(parameters[i] == "diag5")
        {
            how = EXPLO_DIAG5;
        }
        else if(parameters[i] == "clear")
        {
            how = EXPLO_CLEAR;
        }
        else if(parameters[i] == "ladder")
        {
            how = EXPLO_LADDER;
        }
        else if(parameters[i] == "cross")
        {
            how = EXPLO_CROSS;
        }
    }
    if(force_help || how == EXPLO_NOTHING)
    {
        c->con.print("This command can be used for exploratory mining.\n"
                     "http://df.magmawiki.com/index.php/DF2010:Exploratory_mining\n"
                     "\n"
                     "There are two variables that can be set: pattern and filter.\n"
                     "Patterns:\n"
                     "  diag5 = diagonals separated by 5 tiles\n"
                     " ladder = A 'ladder' pattern\n"
                     "  clear = Just remove all dig designations\n"
                     "  cross = A cross, exactly in the middle of the map.\n"
                     "Filters:\n"
                     " all        = designate whole z-level\n"
                     " hidden     = designate only hidden tiles of z-level (default)\n"
                     " designated = Take current designation and apply pattern to it.\n"
                     "\n"
                     "After you have a pattern set, you can use 'expdig' to apply it:\n"
                     "'expdig diag5 hidden' = set filter to hidden, pattern to diag5.\n"
                     "'expdig' = apply the pattern with filter.\n"
        );
        return CR_OK;
    }
    c->Suspend();
    Gui * gui = c->getGui();
    Maps * maps = c->getMaps();
    uint32_t x_max, y_max, z_max;
    if(!maps->Start())
    {
        c->Resume();
        c->con.printerr("Can't init the map...\n");
        return CR_FAILURE;
    }
    maps->getSize(x_max,y_max,z_max);
    int32_t xzzz,yzzz,z_level;
    if(!gui->getViewCoords(xzzz,yzzz,z_level))
    {
        c->Resume();
        c->con.printerr("Can't get view coords...\n");
        return CR_FAILURE;
    }
    auto apply = [&](uint32_t bx, uint32_t by, digmask & dm) -> bool
    {
        df_block * bl = maps->getBlock(bx,by,z_level);
        if(!bl)
            return false;
        int x = 0,mx = 16;
        if(bx == 0)
            x = 1;
        if(bx == x_max - 1)
            mx = 15;
        for(; x < mx; x++)
        {
            int y = 0,my = 16;
            if(by == 0)
                y = 1;
            if(by == y_max - 1)
                my = 15;
            for(; y < my; y++)
            {
                naked_designation & des = bl->designation[x][y].bits;
                short unsigned int tt = bl->tiletype[x][y];
                // could be potentially used to locate hidden constructions?
                if(tileMaterial(tt) == CONSTRUCTED && !des.hidden)
                    continue;
                if(!isWallTerrain(tt) && !des.hidden)
                    continue;
                if(how == EXPLO_CLEAR)
                {
                    des.dig = designation_no;
                    continue;
                }
                if(dm[y][x])
                {
                    if(what == EXPLO_ALL
                        || des.dig == designation_default && what == EXPLO_DESIGNATED
                        || des.hidden && what == EXPLO_HIDDEN)
                    {
                        des.dig = designation_default;
                    }
                }
                else if(what == EXPLO_DESIGNATED)
                {
                    des.dig = designation_no;
                }
            }
        }
        bl->flags.set(BLOCK_DESIGNATED);
        return true;
    };
    if(how == EXPLO_DIAG5)
    {
        int which;
        for(uint32_t x = 0; x < x_max; x++)
        {
            for(int32_t y = 0 ; y < y_max; y++)
            {
                which = (4*x + y) % 5;
                apply(x,y_max - 1 - y,diag5[which]);
            }
        }
    }
    else if(how == EXPLO_LADDER)
    {
        int which;
        for(uint32_t x = 0; x < x_max; x++)
        {
            which = x % 3;
            for(int32_t y = 0 ; y < y_max; y++)
            {
                apply(x,y,ladder[which]);
            }
        }
    }
    else if(how == EXPLO_CROSS)
    {
        // middle + recentering for the image
        int xmid = x_max * 8 - 8;
        int ymid = y_max * 8 - 8;
        MapExtras::MapCache mx (maps);
        for(int x = 0; x < 16; x++)
            for(int y = 0; y < 16; y++)
            {
                DFCoord pos(xmid+x,ymid+y,z_level);
                short unsigned int tt = mx.tiletypeAt(pos);
                if(tt == 0)
                    continue;
                t_designation des = mx.designationAt(pos);
                if(tileMaterial(tt) == CONSTRUCTED && !des.bits.hidden)
                    continue;
                if(!isWallTerrain(tt) && !des.bits.hidden)
                    continue;
                if(cross[y][x])
                {
                    des.bits.dig = designation_default;
                    mx.setDesignationAt(pos,des);
                }
            }
        mx.WriteAll();
    }
    else for(uint32_t x = 0; x < x_max; x++)
        for(int32_t y = 0 ; y < y_max; y++)
            apply(x,y,all_tiles);
    c->Resume();
    return CR_OK;
}
Exemplo n.º 6
0
/*
void do_features(Process* p, uint32_t blockaddr, uint32_t blockX, uint32_t blockY, int printX, int printY, vector<DFHack::t_matgloss> &stonetypes)
{
    memory_info* mem = p->getDescriptor();
    uint32_t block_feature1 = mem->getOffset("map_data_feature_local");
    uint32_t block_feature2 = mem->getOffset("map_data_feature_global");
    uint32_t region_x_offset = mem->getAddress("region_x");
    uint32_t region_y_offset = mem->getAddress("region_y");
    uint32_t region_z_offset = mem->getAddress("region_z");
    uint32_t feature1_start_ptr = mem->getAddress("local_feature_start_ptr");
    int32_t regionX, regionY, regionZ;
    
    // read position of the region inside DF world
    p->readDWord (region_x_offset, (uint32_t &)regionX);
    p->readDWord (region_y_offset, (uint32_t &)regionY);
    p->readDWord (region_z_offset, (uint32_t &)regionZ);
    // local feature present ?
    int16_t idx = p->readWord(blockaddr + block_feature1);
    if(idx != -1)
    {
        gotoxy(printX,printY);
        cprintf("local feature present: %d", idx);
        
        uint64_t block48_x = blockX / 3 + regionX;
        gotoxy(printX,printY+1);
        cprintf("blockX: %d, regionX: %d\nbigblock_x: %d\n", blockX, regionX, block48_x);
        
        // region X coord offset by 8 big blocks (48x48 tiles)
        uint16_t region_x_plus8 = ( block48_x + 8 ) / 16;
        //uint16_t v12b = block48_x / 16;
        //cout << "v12: " << v12 << " : " << v12b <<  endl;
        // plain region Y coord
        uint64_t region_y_local = (blockY / 3 + regionY) / 16;
        gotoxy(printX,printY+2);
        cprintf("region_y_local: %d\n", region_y_local);
        
        // deref pointer to the humongo-structure
        uint32_t base = p->readDWord(feature1_start_ptr);
        gotoxy(printX,printY+3);
        cprintf("region_y_local: 0x%x\n", base);
        
        // this is just a few pointers to arrays of 16B (4 DWORD) structs
        uint32_t array_elem = p->readDWord(base + (region_x_plus8 / 16) * 4);
        gotoxy(printX,printY+4);
        cprintf("array_elem: 0x%x\n", array_elem);
        
        // second element of the struct is a pointer
        uint32_t wtf = p->readDWord(array_elem + (16*(region_y_local/16)) + 4); // rounding!
        gotoxy(printX,printY+5);
        cprintf("wtf : 0x%x @ 0x%x\n", wtf, array_elem + (16*(region_y_local/16)) );
        if(wtf)
        {
            //v14 = v10 + 24 * ((signed __int16)_tX + 16 * v9 % 16);
            uint32_t feat_vector = wtf + 24 * (16 * (region_x_plus8 % 16) + (region_y_local % 16));
            gotoxy(printX,printY+6);
            cprintf("local feature vector: 0x%x\n", feat_vector);
            DfVector<uint32_t> p_features(p, feat_vector);
            gotoxy(printX,printY + 7);
            cprintf("feature %d addr: 0x%x\n", idx, p_features[idx]);
            if(idx >= p_features.size())
            {
                gotoxy(printX,printY + 8);
                cprintf("ERROR, out of vector bounds.");
            }
            else
            {
                string name = p->readClassName(p->readDWord( p_features[idx] ));
                bool discovered = p->readDWord( p_features[idx] + 4 );
                gotoxy(printX,printY+8);
                cprintf("%s", name.c_str());
                if(discovered)
                {
                    gotoxy(printX,printY+9);
                    cprintf("You've discovered it already!");
                }
                
                if(name == "feature_init_deep_special_tubest")
                {
                    int32_t master_type = p->readWord( p_features[idx] + 0x30 );
                    int32_t slave_type = p->readDWord( p_features[idx] + 0x34 );
                    char * matname = "unknown";
                    // is stone?
                    if(master_type == 0)
                    {
                        matname = stonetypes[slave_type].id;
                    }
                    gotoxy(printX,printY+10);
                    cprintf("material %d/%d : %s", master_type, slave_type, matname);
                    
                }
            }
        }
    }
    // global feature present
    idx = p->readWord(blockaddr + block_feature2);
    if(idx != -1)
    {
        gotoxy(printX,printY+11);
        cprintf( "global feature present: %d\n", idx);
        DfVector<uint32_t> p_features (p,mem->getAddress("global_feature_vector"));
        if(idx < p_features.size())
        {
            uint32_t feat_ptr = p->readDWord(p_features[idx] + mem->getOffset("global_feature_funcptr_"));
            gotoxy(printX,printY+12);
            cprintf("feature descriptor?: 0x%x\n", feat_ptr);
            string name = p->readClassName(p->readDWord( feat_ptr));
            bool discovered = p->readDWord( feat_ptr + 4 );
            gotoxy(printX,printY+13);
            cprintf("%s", name.c_str());
            if(discovered)
            {
                gotoxy(printX,printY+14);
                cout << "You've discovered it already!" << endl;
            }
            if(name == "feature_init_underworld_from_layerst")
            {
                int16_t master_type = p->readWord( feat_ptr + 0x34 );
                int32_t slave_type = p->readDWord( feat_ptr + 0x38 );
                char * matname = "unknown";
                // is stone?
                if(master_type == 0)
                {
                    matname = stonetypes[slave_type].id;
                }
                gotoxy(printX,printY+15);
                cprintf("material %d/%d : %s", master_type, slave_type, matname);
            }
        }
    }
}
*/
void do_features(Context* DF, mapblock40d * block, uint32_t blockX, uint32_t blockY, int printX, int printY, vector<DFHack::t_matgloss> &stonetypes)
{
    Maps * Maps = DF->getMaps();
    Process * p = DF->getProcess();
    if(!Maps)
        return;
    vector<DFHack::t_feature> global_features;
    std::map <DFHack::DFCoord, std::vector<DFHack::t_feature *> > local_features;
    if(!Maps->ReadGlobalFeatures(global_features))
        return;
    if(!Maps->ReadLocalFeatures(local_features))
        return;
    
    DFCoord pc(blockX, blockY);
    int16_t idx =block->global_feature;
    if(idx != -1)
    {
        t_feature &ftr =global_features[idx];
        gotoxy(printX,printY);
        cprintf( "global feature present: %d @ 0x%x\n", idx, ftr.origin);
        if(ftr.discovered )
        {
            gotoxy(printX,printY+1);
            cprintf("You've discovered it already!");
        }
        
        char * matname = (char *) "unknown";
        // is stone?
        if(ftr.main_material == 0)
        {
            matname = stonetypes[ftr.sub_material].id;
        }
        gotoxy(printX,printY+2);
        cprintf("%d:%s, material %d/%d : %s", ftr.type, sa_feature(ftr.type), ftr.main_material, ftr.sub_material, matname);
        {
            gotoxy(printX,printY+3);
            string name = p->readClassName(p->readDWord( ftr.origin ));
            cprintf("%s", name.c_str());
        }
    }
    idx =block->local_feature;
    if(idx != -1)
    {
        vector <t_feature *> &ftrv = local_features[pc];
        if(idx < ftrv.size())
        {
            t_feature & ftr = *ftrv[idx];
            gotoxy(printX,printY + 4);
            cprintf( "local feature present: %d @ 0x%x\n", idx, ftr.origin);
            if(ftr.discovered )
            {
                gotoxy(printX,printY+ 5);
                cprintf("You've discovered it already!");
            }
            char * matname = (char *) "unknown";
            // is stone?
            if(ftr.main_material == 0)
            {
                matname = stonetypes[ftr.sub_material].id;
            }
            gotoxy(printX,printY+6);
            cprintf("%d:%s, material %d/%d : %s", ftr.type, sa_feature(ftr.type), ftr.main_material, ftr.sub_material, matname);
            
            gotoxy(printX,printY+7);
            string name = p->readClassName(p->readDWord( ftr.origin ));
            cprintf("%s", name.c_str());
        }
        else
        {
            gotoxy(printX,printY + 4);
            cprintf( "local feature vector overflow: %d", idx);
        }
    }
}
Exemplo n.º 7
0
void main()
{
	//Calling the classes
	Config ApplyConfig;
	Menus DisplayMenus;
	ErrorHandling Check;
	Maps DisplayMaps;
	Turn TurnChoice;
	ofstream fout;
	ifstream fin;

	//Creating the countries
	Countries Domed("Domed", 0, 0, 0, 0, 0, 10);
	Countries Tane("Tane", 0, 0, 0, 0, 0, 20);
	Countries Joha("Joha", 0, 0, 0, 0, 0, 15);
	Countries Odori("Odori", 0, 0, 0, 0, 0, 20);
	Countries Antemie("Antemie", 0, 0, 0, 0, 0, 25);

	//Creating the players
	Players Player(" ", 0, 0, 0, 100);
	Players Artheon("Artheon", 15, 7, 5, 0);

	//Declaring the variables
	int Answer;
	string Name;
	int AnswerTurn;
	int AnswerInfos;
	int AnswerAttack;
	int AnswerDefense;
	int AnswerBuildU;
	char AnswerUnit;
	int AnswerTroops;
	bool Ended = false;
	bool GameOver = false;
	string line[5];
	string endline;
	int x;

	//Apply the config for the screen and the buffer
	ApplyConfig.ConsoleConfig();
	ApplyConfig.ColorChanger(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

	do
	{
		//Display the menu
		DisplayMenus.MainMenu();
		cin >> Answer;
		//Checks if the user has entered a correct input
		Answer = Check.Menu3(Answer);
		ApplyConfig.ClearScreen();
		switch(Answer)
		{
		case 1: //Play
			//Reset values of countries and players to zero
			Player.Name = " ";
			Player.Knights = 0;
			Player.Wizards = 0;
			Player.Demons = 0;
			Player.Ressources = 100;
			Artheon.Knights = 0;
			Artheon.Wizards = 0;
			Artheon.Demons = 0;
			Artheon.Ressources = 100;
			Domed.Ownership = 0;
			Domed.Defense = 0;
			Domed.Knights = 0;
			Domed.Wizards = 0;
			Domed.Demons = 0;
			Tane.Ownership = 0;
			Tane.Defense = 0;
			Tane.Knights = 0;
			Tane.Wizards = 0;
			Tane.Demons = 0;
			Joha.Ownership = 0;
			Joha.Defense = 0;
			Joha.Knights = 0;
			Joha.Wizards = 0;
			Joha.Demons = 0;
			Odori.Ownership = 0;
			Odori.Defense = 0;
			Odori.Knights = 0;
			Odori.Wizards = 0;
			Odori.Demons = 0;
			Antemie.Ownership = 0;
			Antemie.Defense = 0;
			Antemie.Knights = 0;
			Antemie.Wizards = 0;
			Antemie.Demons = 0;
			
			DisplayMenus.Start();
			cin >> Player.Name;
			//You can't make a good game without cheat codes in it xD
			if(Player.Name == "Artheon")
			{
				Player.Ressources = 200;
				Player.Knights = 25;
				Player.Wizards = 25;
				Player.Demons = 25;
				cout << "\n Artheon is a cool name! Here get some free ressources \n";
			}
			cout << "\n";
			do
			{
				DisplayMenus.AllocateRessources(Player.Ressources, Player.Knights, Player.Wizards, Player.Demons);
				cin >> AnswerBuildU;
				//Checks if the user has entered a correct input
				AnswerBuildU = Check.Menu4(AnswerBuildU);
				ApplyConfig.ClearScreen();
				switch(AnswerBuildU)
				{
				case 1: //Knight
					if(Player.Ressources < 1)
					{
						cout << " You don't have enough ressources to build this unit.";
						cin.ignore();
						cout << endl << " Press ENTER to return to the previous menu...\n";
						cin.get();
						ApplyConfig.ClearScreen();
					}
					else
					{
						DisplayMenus.Knight(Player.Ressources);
						cin >> AnswerUnit;
						//Checks if the user has entered a correct input
						AnswerUnit = Check.MenuYN(AnswerUnit);
						ApplyConfig.ClearScreen();
						if(AnswerUnit == 'y')
						{
							Player.Knights = Player.Knights + 1;
							Player.Ressources = Player.Ressources - 1;
						}
					}
					break;
				case 2: //Wizard
					if(Player.Ressources < 5)
					{
						cout << " You don't have enough ressources to build this unit.";
						cin.ignore();
						cout << endl << " Press ENTER to return to the previous menu...\n";
						cin.get();
						ApplyConfig.ClearScreen();
					}
					else
					{
						DisplayMenus.Wizard(Player.Ressources);
						cin >> AnswerUnit;
						//Checks if the user has entered a correct input
						AnswerUnit = Check.MenuYN(AnswerUnit);
						ApplyConfig.ClearScreen();
						if(AnswerUnit == 'y')
						{
							Player.Wizards = Player.Wizards + 1;
							Player.Ressources = Player.Ressources - 5;
						}
					}
					break;
				case 3: //Demon
					if(Player.Ressources < 10)
					{
						cout << " You don't have enough ressources to build this unit.";
						cin.ignore();
						cout << endl << " Press ENTER to return to the previous menu...\n";
						cin.get();
						ApplyConfig.ClearScreen();
					}
					else
					{
						DisplayMenus.Demon(Player.Ressources);
						cin >> AnswerUnit;
						//Checks if the user has entered a correct input
						AnswerUnit = Check.MenuYN(AnswerUnit);
						ApplyConfig.ClearScreen();
						if(AnswerUnit == 'y')
						{
							Player.Demons = Player.Demons + 1;
							Player.Ressources = Player.Ressources - 10;
						}
					}
					break;
				}
			} while(AnswerBuildU != 4);
			cin.ignore();
			cout << "\n Alright " << Player.Name << ", press ENTER to begin your journey!";
			cin.get();			
			do
			{
				do
				{
					ApplyConfig.ClearScreen();
					DisplayMenus.Turn();
					cin >> AnswerTurn;
					//Checks if the user has entered a correct input
					AnswerTurn = Check.Menu6(AnswerTurn);
					ApplyConfig.ClearScreen();
					switch(AnswerTurn)
					{
					case 1: //Show Map
						do
						{
							DisplayMaps.MainMap(Domed.Ownership, Tane.Ownership, Joha.Ownership, Odori.Ownership, Antemie.Ownership);
							DisplayMenus.Infos();
							cin >> AnswerInfos;
							//Checks if the user has entered a correct input
							AnswerInfos = Check.Menu6(AnswerInfos);
							ApplyConfig.ClearScreen();
							switch(AnswerInfos)
							{
							case 1: //Domed
								cout << "\n"
										" Domed\n"
										" \xC4\xC4\xC4\xC4\xC4";
								switch(Domed.Ownership)
								{
								case 0:
									cout << "\n"
											" This country belongs to no one, it has no defenses and give " << Domed.Ressources << " ressources per turn.\n";
									break;
								case 1:
									cout << "\n"
										" This country belongs to you, you have " << Domed.Knights << " knights, " << Domed.Wizards << " wizards and " << Domed.Demons << " demons stationed here,\n"
										" there is " << Domed.Defense << " defenses and this country gives you " << Domed.Ressources << " ressources per turn.\n";
									break;
								case 2:
									cout << "\n"
											" This counrty belongs to your enemy so you cannot get any informations from it.\n";
									break;
								}
								cin.ignore();
								cout << endl << " Press ENTER to return to the map...\n";
								cin.get();							
								ApplyConfig.ClearScreen();
								break;
							case 2: //Tane
								cout << "\n"
										" Tane\n"
										" \xC4\xC4\xC4\xC4";
								switch(Tane.Ownership)
								{
								case 0:
									cout << "\n"
											" This country belongs to no one, it has no defenses and give " << Tane.Ressources << " ressources per turn.\n";
									break;
								case 1:
									cout << "\n"
										" This country belongs to you, you have " << Tane.Knights << " knights, " << Tane.Wizards << " wizards and " << Tane.Demons << " demons stationed here,\n"
										" there is " << Tane.Defense << " defenses and this country gives you " << Tane.Ressources << " ressources per turn.\n";
									break;
								case 2:
									cout << "\n"
											" This counrty belongs to your enemy so you cannot get any informations from it.\n";
									break;
								}
								cin.ignore();
								cout << endl << " Press ENTER to return to the map...\n";
								cin.get();							
								ApplyConfig.ClearScreen();
								break;
							case 3: //Joha
								cout << "\n"
										" Joha\n"
										" \xC4\xC4\xC4\xC4";
								switch(Joha.Ownership)
								{
								case 0:
									cout << "\n"
											" This country belongs to no one, it has no defenses and give " << Joha.Ressources << " ressources per turn.\n";
									break;
								case 1:
									cout << "\n"
										" This country belongs to you, you have " << Joha.Knights << " knights, " << Joha.Wizards << " wizards and " << Joha.Demons << " demons stationed here,\n"
										" there is " << Joha.Defense << " defenses and this country gives you " << Joha.Ressources << " ressources per turn.\n";
									break;
								case 2:
									cout << "\n"
											" This counrty belongs to your enemy so you cannot get any informations from it.\n";
									break;
								}
								cin.ignore();
								cout << endl << " Press ENTER to return to the map...\n";
								cin.get();							
								ApplyConfig.ClearScreen();
								break;
							case 4: //Odori
								cout << "\n"
										" Odori\n"
										" \xC4\xC4\xC4\xC4\xC4";
								switch(Odori.Ownership)
								{
								case 0:
									cout << "\n"
											" This country belongs to no one, it has no defenses and give " << Odori.Ressources << " ressources per turn.\n";
									break;
								case 1:
									cout << "\n"
										" This country belongs to you, you have " << Odori.Knights << " knights, " << Odori.Wizards << " wizards and " << Odori.Demons << " demons stationed here,\n"
										" there is " << Odori.Defense << " defenses and this country gives you " << Odori.Ressources << " ressources per turn.\n";
									break;
								case 2:
									cout << "\n"
											" This counrty belongs to your enemy so you cannot get any informations from it.\n";
									break;
								}
								cin.ignore();
								cout << endl << " Press ENTER to return to the map...\n";
								cin.get();							
								ApplyConfig.ClearScreen();
								break;
							case 5: //Antemie
								cout << "\n"
										" Antemie\n"
										" \xC4\xC4\xC4\xC4\xC4\xC4\xC4";
								switch(Antemie.Ownership)
								{
								case 0:
									cout << "\n"
											" This country belongs to no one, it has no defenses and give " << Antemie.Ressources << " ressources per turn.\n";
									break;
								case 1:
									cout << "\n"
										" This country belongs to you, you have " << Antemie.Knights << " knights, " << Antemie.Wizards << " wizards and " << Antemie.Demons << " demons stationed here,\n"
										" there is " << Antemie.Defense << " defenses and this country gives you " << Antemie.Ressources << " ressources per turn.\n";
									break;
								case 2:
									cout << "\n"
											" This counrty belongs to your enemy so you cannot get any informations from it.\n";
									break;
								}
								cin.ignore();
								cout << endl << " Press ENTER to return to the map...\n";
								cin.get();							
								ApplyConfig.ClearScreen();
								break;
							}
						} while(AnswerInfos != 6);
						Ended = false;
						break;				
					case 2: //Build Units
						do
						{
							DisplayMenus.UnitSelection(Player.Ressources, Player.Knights, Player.Wizards, Player.Demons);
							cin >> AnswerBuildU;
							//Checks if the user has entered a correct input
							AnswerBuildU = Check.Menu4(AnswerBuildU);
							ApplyConfig.ClearScreen();
							switch(AnswerBuildU)
							{
							case 1: //Knight
								if(Player.Ressources < 1)
								{
									cout << " You don't have enough ressources to build this unit.";
									cin.ignore();
									cout << endl << " Press ENTER to return to the previous menu...\n";
									cin.get();
									ApplyConfig.ClearScreen();
								}
								else
								{
									DisplayMenus.Knight(Player.Ressources);
									cin >> AnswerUnit;
									//Checks if the user has entered a correct input
									AnswerUnit = Check.MenuYN(AnswerUnit);
									ApplyConfig.ClearScreen();
									if(AnswerUnit == 'y')
									{
										Player.Knights = Player.Knights + 1;
										Player.Ressources = Player.Ressources - 1;
									}
								}
								break;
							case 2: //Wizard
								if(Player.Ressources < 5)
								{
									cout << " You don't have enough ressources to build this unit.";
									cin.ignore();
									cout << endl << " Press ENTER to return to the previous menu...\n";
									cin.get();
									ApplyConfig.ClearScreen();
								}
								else
								{
									DisplayMenus.Wizard(Player.Ressources);
									cin >> AnswerUnit;
									//Checks if the user has entered a correct input
									AnswerUnit = Check.MenuYN(AnswerUnit);
									ApplyConfig.ClearScreen();
									if(AnswerUnit == 'y')
									{
										Player.Wizards = Player.Wizards + 1;
										Player.Ressources = Player.Ressources - 5;
									}
								}
								break;
							case 3: //Demon
								if(Player.Ressources < 10)
								{
									cout << " You don't have enough ressources to build this unit.";
									cin.ignore();
									cout << endl << " Press ENTER to return to the previous menu...\n";
									cin.get();
									ApplyConfig.ClearScreen();
								}
								else
								{
									DisplayMenus.Demon(Player.Ressources);
									cin >> AnswerUnit;
									//Checks if the user has entered a correct input
									AnswerUnit = Check.MenuYN(AnswerUnit);
									ApplyConfig.ClearScreen();
									if(AnswerUnit == 'y')
									{
										Player.Demons = Player.Demons + 1;
										Player.Ressources = Player.Ressources - 10;
									}
								}
								break;
							}						
						} while(AnswerBuildU != 4);
						break;
					case 3: //Build Defenses
						do
						{
							DisplayMaps.MainMap(Domed.Ownership, Tane.Ownership, Joha.Ownership, Odori.Ownership, Antemie.Ownership);
							DisplayMenus.BuildDefenses();
							cin >> AnswerDefense;
							//Checks if the user has entered a correct input
							AnswerAttack = Check.Menu6(AnswerDefense);
							ApplyConfig.ClearScreen();
							switch(AnswerDefense)
								{
								case 1: //Domed
									if(Domed.Ownership != 1)
									{
										Check.NotOwnedCountry();
									}
									else
									{
										Domed.Defense = TurnChoice.BuildDefenses(Domed.Defense, Player.Ressources);
									}
									ApplyConfig.ClearScreen();
									break;
								case 2: //Tane
									if(Tane.Ownership != 1)
									{
										Check.NotOwnedCountry();
									}
									else
									{
										Tane.Defense = TurnChoice.BuildDefenses(Domed.Defense, Player.Ressources);
									}
									ApplyConfig.ClearScreen();
									break;
								case 3: //Joha
									if(Joha.Ownership != 1)
									{
										Check.NotOwnedCountry();
									}
									else
									{
										Joha.Defense = TurnChoice.BuildDefenses(Domed.Defense, Player.Ressources);
									}
									ApplyConfig.ClearScreen();
									break;
								case 4: //Odori
									if(Odori.Ownership != 1)
									{
										Check.NotOwnedCountry();
									}
									else
									{
										Odori.Defense = TurnChoice.BuildDefenses(Domed.Defense, Player.Ressources);
									}
									ApplyConfig.ClearScreen();
									break;
								case 5: //Antemie
									if(Antemie.Ownership != 1)
									{
										Check.NotOwnedCountry();
									}
									else
									{
										Antemie.Defense = TurnChoice.BuildDefenses(Domed.Defense, Player.Ressources);
									}
									ApplyConfig.ClearScreen();
									break;
								}
						} while(AnswerDefense != 6);
						break;				
					case 4: //Station Troops
						do
						{
							DisplayMaps.MainMap(Domed.Ownership, Tane.Ownership, Joha.Ownership, Odori.Ownership, Antemie.Ownership);
							DisplayMenus.Troops();
							cin >> AnswerTroops;
							//Checks if the user has entered a correct input
							AnswerTroops = Check.Menu6(AnswerTroops);
							ApplyConfig.ClearScreen();
							switch(AnswerTroops)
							{
							case 1: //Domed
								if(Domed.Ownership != 1)
								{
									Check.NotOwnedCountry();
								}
								else
								{
									TurnChoice.StationTroops(Player.Knights, Player.Wizards, Player.Demons, Domed.Knights, Domed.Wizards, Domed.Demons);
								}
								ApplyConfig.ClearScreen();
								break;
							case 2: //Tane
								if(Tane.Ownership != 1)
								{
									Check.NotOwnedCountry();
								}
								else
								{
									TurnChoice.StationTroops(Player.Knights, Player.Wizards, Player.Demons, Tane.Knights, Tane.Wizards, Tane.Demons);
								}
								ApplyConfig.ClearScreen();
								break;
							case 3: //Joha
								if(Joha.Ownership != 1)
								{
									Check.NotOwnedCountry();
								}
								else
								{
									TurnChoice.StationTroops(Player.Knights, Player.Wizards, Player.Demons, Joha.Knights, Joha.Wizards, Joha.Demons);
								}
								ApplyConfig.ClearScreen();
								break;
							case 4: //Odori
								if(Odori.Ownership != 1)
								{
									Check.NotOwnedCountry();
								}
								else
								{
									TurnChoice.StationTroops(Player.Knights, Player.Wizards, Player.Demons, Odori.Knights, Odori.Wizards, Odori.Demons);
								}
								ApplyConfig.ClearScreen();
								break;
							case 5: //Antemie
								if(Antemie.Ownership != 1)
								{
									Check.NotOwnedCountry();
								}
								else
								{
									TurnChoice.StationTroops(Player.Knights, Player.Wizards, Player.Demons, Antemie.Knights, Antemie.Wizards, Antemie.Demons);
								}
								ApplyConfig.ClearScreen();
								break;
							}
						} while(AnswerTroops != 6);
						break;
					case 5: //Attack
						do
						{
							DisplayMaps.MainMap(Domed.Ownership, Tane.Ownership, Joha.Ownership, Odori.Ownership, Antemie.Ownership);
							DisplayMenus.Attack();
							cin >> AnswerAttack;
							//Checks if the user has entered a correct input
							AnswerAttack = Check.Menu5(AnswerAttack);
							ApplyConfig.ClearScreen();
							switch(AnswerAttack)
							{
							case 1: //Domed
								if(Domed.Ownership == 1)
								{
									Check.OwnedCountry();
								}
								else
								{
									Domed.Ownership = TurnChoice.Attack(Domed, Player.Knights, Player.Wizards, Player.Demons);
									Ended = true;
								}
								ApplyConfig.ClearScreen();
								break;
							case 2: //Tane
								if(Tane.Ownership == 1)
								{
									Check.OwnedCountry();
								}
								else
								{
									Tane.Ownership = TurnChoice.Attack(Tane, Player.Knights, Player.Wizards, Player.Demons);
									Ended = true;
								}
								ApplyConfig.ClearScreen();
								break;
							case 3: //Joha
								if(Joha.Ownership == 1)
								{
									Check.OwnedCountry();
								}
								else
								{
									Joha.Ownership = TurnChoice.Attack(Joha, Player.Knights, Player.Wizards, Player.Demons);
									Ended = true;
								}
								ApplyConfig.ClearScreen();
								break;
							case 4: //Odori
								if(Odori.Ownership == 1)
								{
									Check.OwnedCountry();
								}
								else
								{
									Odori.Ownership = TurnChoice.Attack(Odori, Player.Knights, Player.Wizards, Player.Demons);
									Ended = true;
								}
								ApplyConfig.ClearScreen();
								break;
							case 5: //Antemie
								if(Antemie.Ownership == 1)
								{
									Check.OwnedCountry();
								}
								else
								{
									Antemie.Ownership = TurnChoice.Attack(Antemie, Player.Knights, Player.Wizards, Player.Demons);
									Ended = true;
								}
								ApplyConfig.ClearScreen();
								break;
							}
						} while(Ended == false);					
						break;
					case 6: //Exit
						Ended = true;
						break;
					}				
				} while(Ended == false);
				Ended = false;
				ApplyConfig.ClearScreen();
				//Adding the ressources to the player
				if(Domed.Ownership == 1) {
					Player.Ressources = Player.Ressources + Domed.Ressources; }
				if(Tane.Ownership == 1) {
					Player.Ressources = Player.Ressources + Tane.Ressources; }
				if(Joha.Ownership == 1) {
					Player.Ressources = Player.Ressources + Joha.Ressources; }
				if(Odori.Ownership == 1) {
					Player.Ressources = Player.Ressources + Odori.Ressources; }
				if(Antemie.Ownership == 1) {
					Player.Ressources = Player.Ressources + Antemie.Ressources; }

				//Artheon's turn
				TurnChoice.ArtheonTurn(Artheon, Domed, Tane, Joha, Odori, Antemie);

				cin.ignore();
				cout << endl << " Press ENTER to continue.\n";
				cin.get();
				
				//Checks if Artheon or the player owns every continents
				//Checks if Artheon owns all the continents
				if(Domed.Ownership == 2 && Tane.Ownership == 2 && Joha.Ownership == 2 && Odori.Ownership == 2 && Antemie.Ownership == 2)
				{					
					cout << "\n"
							" Artheon has defeated you, he conquered Ameria!\n"
							" Press ENTER to return to the main menu.\n";
					GameOver = true;
				}
				//Checks if player owns all the continents
				else if(Domed.Ownership == 1 && Tane.Ownership == 1 && Joha.Ownership == 1 && Odori.Ownership == 1 && Antemie.Ownership == 1)
				{
					cout << "\n"
							" Congratulation you conquered Ameria!\n"
							" Press ENTER to return to the main menu.\n";
					GameOver = true;
				}				
			} while(GameOver == false);

			//Writing infos for High Score
			fout.open("highscores.txt", ios::out | ios::app);
			if(fout.is_open()) {
				fout << "\n" << Player.Name << "," << Player.Ressources << "," << Player.Knights << "," << Player.Wizards << "," << Player.Demons << ",";	}
			else
			{
				cout << "\n"
						" Unable to open the the file containing the High Scores.";
			}
			fout.close();

			cin.ignore();
			cin.get();
			ApplyConfig.ClearScreen();
			break;
		case 2: //High scores
			fin.open("highscores.txt");
			if(fin.is_open()) 
			{
				cout << "                                                                         \xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n"
						"                                                                         \xBA HIGH SCORES \xBA\n"
						"                                                                         \xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n"
						"\n"
						"                                                         Ressources and Units left at the end of the game\n"
						" Player Name                     Ressources                        Knights                           Wizards                           Demons\n"
						" \xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\n";
				while (fin.good())
				{
					while(getline(fin, endline))
					{
						for(x = 0; x < 5; x++)
						{
							getline(fin, line[x], ',');
						}
						cout << " " << line[0] << setw(35 - line[0].size()) << line[1] << setw(35 - line[1].size()) << line[2] << setw(35 - line[2].size()) << line[3] << setw(35 - line[3].size()) << line[4] << endl;
					}
				}				
			}
			else
			{
				cout << "\n"
						" Unable to open the the file containing the High Scores.";
			}
			fin.close();

			cin.ignore();
			cout << endl << " Press ENTER to return to the main menu.\n";
			cin.get();
			ApplyConfig.ClearScreen();
			break;
		}
	} while(Answer != 3);
}
Exemplo n.º 8
0
//MAIN |
//======
int main(int argc, char *argv[]){

//Command Line Options |
//======================
     for(int i = 0; i < argc; i++){
         string str = argv[i];
         if(str=="-dev") DEVELOPER = !DEVELOPER;
         if(str=="-delay") DELAY = atoi(argv[i+1]);
     }

//STARTUP MESSAGE |
//=================
    cout << TITLE << " version " << VERSION << endl
         << COPYMSG << endl << WEBSITE << endl;


//INITALIZE SDL |
//===============
    Camera screen(ResX, ResY);
    SDL_WM_SetCaption( WINDOWTITLE.c_str(), NULL ); 
    atexit(SDL_Quit);
    TTF_Init(); atexit(TTF_Quit);
    //SDL_EnableUNICODE( SDL_ENABLE ); ////get unicode from key events: (event.key.keysym.unicode)


//OBJECTS |
//=========
    //Setup
    Mouse mouse;
    Keys keyboard;
    Tiles mapTiles(106, 32); //mapTiles (tiles#, widthPix)
    //Maps
    Maps map = world;
    //Sprites
    Sprite player("characters/player.png", screen.getResX()/2, (screen.getResY()/2)-(mapTiles.getPix()/4));
    //Inventories
    Inventory playerInven(400, 0, 8, 8, "gui/inventory.png");
    Inventory testInven(0,0, 8, 8, "gui/inventory.png");
    //Items
    Item test("Test Item", "items/test.png", 0, 0, 500, 100, 100);
    Item sword1("Sword #1", "items/sword1.png", 0, 0, 500, 100, 100);
    Item sword2("Sword #2", "items/sword1.png", 0, 0, 500, 100, 100);
    playerInven.add(sword1, 1);
    playerInven.add(sword2, 2);
    playerInven.add(test, 5);
    testInven.add(sword1, 1);


//VARIABLES |
//===========
    bool run = true;
    int gameMode = 1;
    int location = 0;

    //Dev Variables
    bool dMouseXY = DEVELOPER;
    bool dCamXY = DEVELOPER;
    bool dMiniM = DEVELOPER;
    bool devKeys = DEVELOPER;
    bool dMouseTile = DEVELOPER;
    int drawTile = 1;
    bool editMap = false;

//MAIN LOOP |
//===========
    while(run){


//SDL EVENTS |
//============
        SDL_Event event; 
        while (SDL_PollEvent(&event)){
            //Quit
            if (  (event.type==SDL_QUIT)      //Quit if you press X button
               || (  (event.type==SDL_KEYDOWN)//or escape key
                  && (event.key.keysym.sym==SDLK_ESCAPE) )){
               run = false;
            }
            //Mouse Motion
            if(event.type==SDL_MOUSEMOTION){
                mouse.putX(event.motion.x);
                mouse.putY(event.motion.y);
            }
            //Mouse Buttons
            if(event.type==SDL_MOUSEBUTTONDOWN){ //Down
                //Left Button
                if(event.button.button==SDL_BUTTON_LEFT){
                    mouse.putLB(true);
                }
                //Right Button
                if(event.button.button==SDL_BUTTON_RIGHT){
                    mouse.putRB(true);
                }
            }
            if(event.type==SDL_MOUSEBUTTONUP){ //UP
                //Left Button
                if(event.button.button==SDL_BUTTON_LEFT){
                     mouse.putLB(false);
                }
                //Right Button
                if(event.button.button==SDL_BUTTON_RIGHT){
                     mouse.putRB(false);
                }
            }
            ////Mouse Wheel Up
            //if(event.type==SDL_BUTTON_WHEELUP){
            //    cout << "wheel up\n";
            //}
            ////Mouse Wheel Down
            //if(event.type==SDL_BUTTON_WHEELDOWN){
            //    cout << "wheel down\n";
            //}
            //Key Down
            if(event.type==SDL_KEYDOWN){
                if(event.key.keysym.sym==SDLK_UP)screen.setUp(true);
                if(event.key.keysym.sym==SDLK_DOWN)screen.setDown(true);
                if(event.key.keysym.sym==SDLK_LEFT)screen.setLeft(true);
                if(event.key.keysym.sym==SDLK_RIGHT)screen.setRight(true);
                if(event.key.keysym.sym==SDLK_LCTRL)keyboard.setCtrl(true);
                if(event.key.keysym.sym==SDLK_SPACE)keyboard.setSpace(true);
                //dev-keys
                if(devKeys){
                    if(event.key.keysym.sym==SDLK_w)(map).changeY((map).getY()-1);
                    if(event.key.keysym.sym==SDLK_s)(map).changeY((map).getY()+1);
                    if(event.key.keysym.sym==SDLK_a)(map).changeX((map).getX()-1);
                    if(event.key.keysym.sym==SDLK_d)(map).changeX((map).getX()+1);
                    if(event.key.keysym.sym==SDLK_0)gameMode = 0;
                    if(event.key.keysym.sym==SDLK_1)gameMode = 1;
                    if(event.key.keysym.sym==SDLK_2)gameMode = 2;
                }
            }
            if(event.type==SDL_KEYUP){
                if(event.key.keysym.sym==SDLK_UP)screen.setUp(false);
                if(event.key.keysym.sym==SDLK_DOWN)screen.setDown(false);
                if(event.key.keysym.sym==SDLK_LEFT)screen.setLeft(false);
                if(event.key.keysym.sym==SDLK_RIGHT)screen.setRight(false);
                if(event.key.keysym.sym==SDLK_LCTRL)keyboard.setCtrl(false);
                if(event.key.keysym.sym==SDLK_SPACE)keyboard.setSpace(false);
            }
        }


//Tasks! |
//========
        //Mouse
        if(mouse.getLB()){
           switch(mouse.clickGet()){
               case 0: mouse.clickPut(1); break;
               case 1: mouse.clickPut(2); break;
               default: break;
            }
        }else{ mouse.clickPut(0); }
        //Input mode:
        if(gameMode == 0){
            SDL_FillRect(screen.display(), NULL, SDL_MapRGB(screen.display()->format, 120, 120, 120));
            drawText("COMMAND LINE", 0, 200, 225, 0, 0, 90, screen);
            SDL_Flip(screen.display());
            string s;
            cout << "Enter a Command:\n>> ";
            cin >> s;
            if(s=="invendump") playerInven.dump();
            if(s=="mousetest") mouse.setMouseItem(sword1, 1);
            if(s=="dMouseXY") dMouseXY = !dMouseXY;
            if(s=="dCamXY") dCamXY = !dCamXY;
            if(s=="dMiniM") dMiniM = !dMiniM;
            if(s=="devKeys") devKeys = !devKeys;
            if(s=="changeTile") {cout << ">> "; cin >> drawTile;}
            if(s=="editMap") editMap = !editMap;
            if(s=="saveMap") map.saveMap();
            if(s=="dMouseTile") dMouseTile = !dMouseTile;
            cout << "Back to Game\n===============\n";
            gameMode = 1;
        }