Changeset 05051c7 in network-game for common/WorldMap.cpp


Ignore:
Timestamp:
May 19, 2013, 7:12:07 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
cc1c6c1
Parents:
035d852
Message:

Added support for objects that can be at any pixel on the map, not just one per grid cell. What used to be called objects are now caled structures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/WorldMap.cpp

    r035d852 r05051c7  
    1515
    1616   vctMap = new vector<vector<TerrainType>*>(width);
    17    vctObjects = new vector<vector<ObjectType>*>(width);
     17   vctStructures = new vector<vector<StructureType>*>(width);
     18   vctObjects = new vector<Object>();
    1819
    1920   for (int x=0; x<width; x++) {
    2021      vector<TerrainType>* newMapVector = new vector<TerrainType>(height);
    21       vector<ObjectType>* newObjectVector = new vector<ObjectType>(height);
     22      vector<StructureType>* newStructureVector = new vector<StructureType>(height);
    2223
    2324      for (int y=0; y<height; y++) {
    2425         (*newMapVector)[y] = TERRAIN_NONE;
    25          (*newObjectVector)[y] = OBJECT_NONE;
     26         (*newStructureVector)[y] = STRUCTURE_NONE;
    2627      }
    2728
    2829      (*vctMap)[x] = newMapVector;
    29       (*vctObjects)[x] = newObjectVector;
     30      (*vctStructures)[x] = newStructureVector;
    3031   }
    3132}
     
    3536   for (int x=0; x<width; x++) {
    3637      delete (*vctMap)[x];
    37       delete (*vctObjects)[x];
     38      delete (*vctStructures)[x];
    3839   }
    3940
    4041   delete vctMap;
     42   delete vctStructures;
    4143   delete vctObjects;
    4244}
     
    4951void WorldMap::setElement(int x, int y, TerrainType t)
    5052{
    51    cout << "getting element" << endl;
    5253   (*(*vctMap)[x])[y] = t;
    5354}
    5455
    55 WorldMap::ObjectType WorldMap::getObject(int x, int y)
    56 {
    57    return (*(*vctObjects)[x])[y];
    58 }
    59 
    60 void WorldMap::setObject(int x, int y, ObjectType t)
    61 {
    62    cout << "getting object" << endl;
    63    (*(*vctObjects)[x])[y] = t;
     56WorldMap::StructureType WorldMap::getStructure(int x, int y)
     57{
     58   return (*(*vctStructures)[x])[y];
     59}
     60
     61void WorldMap::setStructure(int x, int y, StructureType t)
     62{
     63   (*(*vctStructures)[x])[y] = t;
     64}
     65
     66vector<WorldMap::Object> WorldMap::getObjects(int x, int y) {
     67   vector<WorldMap::Object> vctObjectsInRegion;
     68
     69   return vctObjectsInRegion;
     70}
     71
     72void WorldMap::addObject(int x, int y, WorldMap::ObjectType t) {
     73   WorldMap::Object o(t, x, y);
     74
     75   vctObjects->push_back(o);
    6476}
    6577
     
    7789            m->setElement(x, y, TERRAIN_GRASS);
    7890
    79          m->setObject(x, y, OBJECT_NONE);
     91         m->setStructure(x, y, STRUCTURE_NONE);
    8092      }
    8193   }
     
    158170
    159171               int x, y, type;
    160                ObjectType object;
     172               StructureType structure;
    161173
    162174               getline(iss, token, ',');
     
    174186               switch(type) {
    175187               case 0:
    176                   object = OBJECT_NONE;
     188                  structure = STRUCTURE_NONE;
    177189                  break;
    178190               case 1:
    179                   object = OBJECT_BLUE_FLAG;
     191                  structure = STRUCTURE_BLUE_FLAG;
    180192                  break;
    181193               case 2:
    182                   object = OBJECT_RED_FLAG;
     194                  structure = STRUCTURE_RED_FLAG;
    183195                  break;
    184196               }
    185197
    186                m->setObject(x, y, object);
     198               m->setStructure(x, y, structure);
    187199            }
    188200         }
     
    197209   return m;
    198210}
     211
     212
     213/*** Functions for Object ***/
     214
     215WorldMap::Object::Object(ObjectType type, POSITION pos) {
     216   this->type = type;
     217   this->pos = pos;
     218}
     219
     220WorldMap::Object::Object(ObjectType type, int x, int y) {
     221   this->type = type;
     222   this->pos.x = x;
     223   this->pos.y = y;
     224}
     225
     226WorldMap::Object::~Object() {
     227}
Note: See TracChangeset for help on using the changeset viewer.