root/deus/mapread.cpp

Revision 8, 2.6 kB (checked in by pantley2, 4 years ago)

added old DEUS project to SVN

Line 
1 #include <fstream>
2 #include <iostream>
3 #include <string>
4 #include "structures.h"
5 #include <utility>
6 using namespace std;
7
8
9 // Gets the size of the map from "mapfile"
10 // returns a pair.
11 pair<int,int> GetMapSize()
12 {
13         int xs,ys;
14         ifstream imap;
15     imap.open("mapfile", ios::in);
16     if(!imap)
17     {
18         cout << "Error opening input file" << endl;
19         exit(0);
20        
21     }
22         imap>>xs;    //gets x size
23         imap>>ys;    //gets y size
24         imap.close();
25         pair<int,int> Size(xs,ys);
26         return Size;
27 }
28
29
30 // Parses "mapfile" and generates
31 // a vector of location objects.
32 vector<Location> MapGenerator()
33 {
34     ifstream imap;
35     imap.open("mapfile", ios::in);
36     if(!imap)
37     {
38         cout << "Error opening input file" << endl;
39         exit(0);
40        
41     }
42    
43     int numObjects;
44     imap>>numObjects;    //gets x size, discards
45         imap>>numObjects;    //gets y size, discards
46         imap>>numObjects;    //gets number of area's in map
47     
48         cout<<"Numobjects :"<<numObjects<<endl;
49        
50     vector<Location> locarray(numObjects); //vector for locations
51     
52         // All possible types go in this enum.  LOC_LAST must always be the last element
53     //Enum LocType {LOC_TOWN = 0x0, LOC_FARM, LOC_MARKET, LOC_BAR, LOC_GENERIC, LOC_LAST};
54     /*class Location : public GameObject
55     {
56        public:
57        string name;
58            LocType loc_type;
59            Location() {type = GO_LOCATION;}
60            // bounding rectangle
61            int ur_x, ur_y, ll_x, ll_y;
62         };
63     */
64        
65         char tempname[50];
66         int templtype;
67        
68     for(int i=0;i<numObjects;i++)    //fill up the location vector                                     
69     {   
70        
71         imap>>tempname>>locarray[i].ur_x>>locarray[i].ur_y>>locarray[i].ll_x>>locarray[i].ll_y>>templtype;
72                 string temp(tempname);
73                 locarray[i].name=temp;
74         switch(templtype)
75                 {
76                         case 0 : locarray[i].loc_type=LOC_TOWN;
77                                          break;
78                         case 1 : locarray[i].loc_type=LOC_FARM;
79                                          break;
80                         case 2 : locarray[i].loc_type=LOC_MARKET;
81                                          break;
82                         case 3 : locarray[i].loc_type=LOC_BAR;
83                                          break;
84                         case 5 : locarray[i].loc_type=LOC_LAST;
85                                           break;
86                         default : locarray[i].loc_type=LOC_GENERIC;
87                 }
88     }
89  
90     imap.close();
91         return locarray;
92
93 }
94
95 /*
96 void main()
97 {
98         pair<int, int> S = GetMapSize();
99         vector<Location> locs = MapGenerator();
100         int vsize = locs.size();
101
102         cout<<"MAPSIZE "<<S.first<<","<<S.second<<endl;
103         for (int i=0;i<vsize;i++)
104         {
105                 int x;
106                 cout<<"LOCATION "<<i+1<<endl;
107                 cout<<locs[i].name<<endl;
108         cout<<locs[i].ur_x<<","<<locs[i].ur_y<<" to "<<locs[i].ll_x<<","<<locs[i].ll_y<<endl;
109                 cout<<"LOCTYPE "<<LocType(locs[i].loc_type)<<endl;
110                 cin>>x;
111                 
112         }
113
114 }*/
Note: See TracBrowser for help on using the browser.