Changeset 05051c7 in network-game for common


Ignore:
Timestamp:
May 19, 2013, 7:12:07 PM (11 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

Location:
common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r035d852 r05051c7  
    124124      // using moveCanceled in a hacky way just to indicate that the server
    125125      // has updated some player info. Should change the variable name
    126       switch(map->getObject(newPos.x/25, newPos.y/25)) {
    127       case WorldMap::OBJECT_BLUE_FLAG:
     126      switch(map->getStructure(newPos.x/25, newPos.y/25)) {
     127      case WorldMap::STRUCTURE_BLUE_FLAG:
    128128         hasBlueFlag = true;
    129129         moveCanceled = true;
    130130         break;
    131       case WorldMap::OBJECT_RED_FLAG:
     131      case WorldMap::STRUCTURE_RED_FLAG:
    132132         hasRedFlag = true;
    133133         moveCanceled = true;
  • 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}
  • common/WorldMap.h

    r035d852 r05051c7  
    55
    66#include <vector>
     7
     8#include "Common.h"
    79
    810using namespace std;
     
    1719   };
    1820
     21   enum StructureType {
     22      STRUCTURE_NONE,
     23      STRUCTURE_BLUE_FLAG,
     24      STRUCTURE_RED_FLAG
     25   };
     26
    1927   enum ObjectType {
    2028      OBJECT_NONE,
     
    2331   };
    2432
     33   class Object {
     34   public:
     35      ObjectType type;
     36      POSITION pos;
     37
     38      Object(ObjectType type, int x, int y);
     39      Object(ObjectType type, POSITION pos);
     40
     41      ~Object();
     42   };
     43
    2544   int width, height;
    2645   vector<vector<TerrainType>*>* vctMap;
    27    vector<vector<ObjectType>*>* vctObjects;
     46   vector<vector<StructureType>*>* vctStructures;
     47   vector<Object>* vctObjects;
    2848
    2949   WorldMap(int width, int height);
     
    3454   void setElement(int x, int y, TerrainType type);
    3555
    36    ObjectType getObject(int x, int y);
    37    void setObject(int x, int y, ObjectType type);
     56   StructureType getStructure(int x, int y);
     57   void setStructure(int x, int y, StructureType type);
     58
     59   vector<Object> getObjects(int x, int y);
     60   void addObject(int x, int y, ObjectType type);
    3861
    3962   static WorldMap* createDefaultMap();
Note: See TracChangeset for help on using the changeset viewer.