mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-29 03:26:38 +00:00 
			
		
		
		
	Merge remote branch 'korslund/master'
This commit is contained in:
		
						commit
						afe545f953
					
				
					 5 changed files with 102 additions and 10 deletions
				
			
		|  | @ -41,10 +41,21 @@ namespace MWScript | ||||||
|                     runtime.pop(); |                     runtime.pop(); | ||||||
| 
 | 
 | ||||||
|                     ESM::Position pos; |                     ESM::Position pos; | ||||||
|                     pos.pos[0] = pos.pos[1] = pos.pos[2] = 0; |  | ||||||
|                     pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; |                     pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; | ||||||
|  |                     pos.pos[2] = 0; | ||||||
|  | 
 | ||||||
|  |                     if (const ESM::Cell *exterior = context.getWorld().getExterior (cell)) | ||||||
|  |                     { | ||||||
|  |                         context.getWorld().indexToPosition (exterior->data.gridX, exterior->data.gridY, | ||||||
|  |                             pos.pos[0], pos.pos[1], true); | ||||||
|  |                         context.getWorld().changeToExteriorCell (pos); | ||||||
|  |                     } | ||||||
|  |                     else | ||||||
|  |                     { | ||||||
|  |                         pos.pos[0] = pos.pos[1] = 0; | ||||||
|                         context.getWorld().changeCell (cell, pos); |                         context.getWorld().changeCell (cell, pos); | ||||||
|                     } |                     } | ||||||
|  |                 } | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         class OpCOE : public Interpreter::Opcode0 |         class OpCOE : public Interpreter::Opcode0 | ||||||
|  | @ -64,7 +75,7 @@ namespace MWScript | ||||||
| 
 | 
 | ||||||
|                     ESM::Position pos; |                     ESM::Position pos; | ||||||
| 
 | 
 | ||||||
|                     context.getWorld().indexToPosition (x, y, pos.pos[0], pos.pos[1]); |                     context.getWorld().indexToPosition (x, y, pos.pos[0], pos.pos[1], true); | ||||||
|                     pos.pos[2] = 0; |                     pos.pos[2] = 0; | ||||||
| 
 | 
 | ||||||
|                     pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; |                     pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; | ||||||
|  |  | ||||||
|  | @ -691,6 +691,30 @@ namespace MWWorld | ||||||
|         changeCell (x, y, position); |         changeCell (x, y, position); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     const ESM::Cell *World::getExterior (const std::string& cellName) const | ||||||
|  |     { | ||||||
|  |         // first try named cells
 | ||||||
|  |         if (const ESM::Cell *cell = mStore.cells.searchExtByName (cellName)) | ||||||
|  |             return cell; | ||||||
|  | 
 | ||||||
|  |         // didn't work -> now check for regions
 | ||||||
|  |         std::string cellName2 = ESMS::RecListT<ESM::Region>::toLower (cellName); | ||||||
|  | 
 | ||||||
|  |         for (ESMS::RecListT<ESM::Region>::MapType::const_iterator iter (mStore.regions.list.begin()); | ||||||
|  |             iter!=mStore.regions.list.end(); ++iter) | ||||||
|  |         { | ||||||
|  |             if (ESMS::RecListT<ESM::Region>::toLower (iter->second.name)==cellName2) | ||||||
|  |             { | ||||||
|  |                 if (const ESM::Cell *cell = mStore.cells.searchExtByRegion (iter->first)) | ||||||
|  |                     return cell; | ||||||
|  | 
 | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     void World::markCellAsUnchanged() |     void World::markCellAsUnchanged() | ||||||
|     { |     { | ||||||
|         mCellChanged = false; |         mCellChanged = false; | ||||||
|  | @ -756,12 +780,18 @@ namespace MWWorld | ||||||
|         // TODO cell change for non-player ref
 |         // TODO cell change for non-player ref
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void World::indexToPosition (int cellX, int cellY, float &x, float &y) const |     void World::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const | ||||||
|     { |     { | ||||||
|         const int cellSize = 8192; |         const int cellSize = 8192; | ||||||
| 
 | 
 | ||||||
|         x = cellSize * cellX; |         x = cellSize * cellX; | ||||||
|         y = cellSize * cellY; |         y = cellSize * cellY; | ||||||
|  | 
 | ||||||
|  |         if (centre) | ||||||
|  |         { | ||||||
|  |             x += cellSize/2; | ||||||
|  |             y += cellSize/2; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void World::positionToIndex (float x, float y, int &cellX, int &cellY) const |     void World::positionToIndex (float x, float y, int &cellX, int &cellY) const | ||||||
|  |  | ||||||
|  | @ -145,6 +145,9 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|             void changeToExteriorCell (const ESM::Position& position); |             void changeToExteriorCell (const ESM::Position& position); | ||||||
| 
 | 
 | ||||||
|  |             const ESM::Cell *getExterior (const std::string& cellName) const; | ||||||
|  |             ///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
 | ||||||
|  | 
 | ||||||
|             void markCellAsUnchanged(); |             void markCellAsUnchanged(); | ||||||
| 
 | 
 | ||||||
|             std::string getFacedHandle(); |             std::string getFacedHandle(); | ||||||
|  | @ -154,7 +157,7 @@ namespace MWWorld | ||||||
| 
 | 
 | ||||||
|             void moveObject (Ptr ptr, float x, float y, float z); |             void moveObject (Ptr ptr, float x, float y, float z); | ||||||
| 
 | 
 | ||||||
|             void indexToPosition (int cellX, int cellY, float &x, float &y) const; |             void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; | ||||||
|             ///< Convert cell numbers to position.
 |             ///< Convert cell numbers to position.
 | ||||||
| 
 | 
 | ||||||
|             void positionToIndex (float x, float y, int &cellX, int &cellY) const; |             void positionToIndex (float x, float y, int &cellX, int &cellY) const; | ||||||
|  |  | ||||||
|  | @ -209,6 +209,38 @@ namespace ESMS | ||||||
|         return it2->second; |         return it2->second; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     const Cell *searchExtByName (const std::string& id) const | ||||||
|  |     { | ||||||
|  |         for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter) | ||||||
|  |         { | ||||||
|  |             const ExtCellsCol& column = iter->second; | ||||||
|  |             for (ExtCellsCol::const_iterator iter = column.begin(); iter!=column.end(); ++iter) | ||||||
|  |             { | ||||||
|  |                 if (iter->second->name==id) | ||||||
|  |                     return iter->second; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const Cell *searchExtByRegion (const std::string& id) const | ||||||
|  |     { | ||||||
|  |         std::string id2 = toLower (id); | ||||||
|  | 
 | ||||||
|  |         for (ExtCells::const_iterator iter = extCells.begin(); iter!=extCells.end(); ++iter) | ||||||
|  |         { | ||||||
|  |             const ExtCellsCol& column = iter->second; | ||||||
|  |             for (ExtCellsCol::const_iterator iter = column.begin(); iter!=column.end(); ++iter) | ||||||
|  |             { | ||||||
|  |                 if (toLower (iter->second->region)==id) | ||||||
|  |                     return iter->second; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     void load(ESMReader &esm, const std::string &id) |     void load(ESMReader &esm, const std::string &id) | ||||||
|     { |     { | ||||||
|       using namespace std; |       using namespace std; | ||||||
|  |  | ||||||
|  | @ -83,12 +83,28 @@ static size_t getLength(const char *arr, const char* input, bool &ascii) | ||||||
| { | { | ||||||
|   ascii = true; |   ascii = true; | ||||||
|   size_t len = 0; |   size_t len = 0; | ||||||
|   unsigned char inp = *input; |   const char* ptr = input; | ||||||
|  |   unsigned char inp = *ptr; | ||||||
|  | 
 | ||||||
|  |   // Do away with the ascii part of the string first (this is almost
 | ||||||
|  |   // always the entire string.)
 | ||||||
|  |   while(inp && inp < 128) | ||||||
|  |     inp = *(++ptr); | ||||||
|  |   len += (ptr-input); | ||||||
|  | 
 | ||||||
|  |   // If we're not at the null terminator at this point, then there
 | ||||||
|  |   // were some non-ascii characters to deal with. Go to slow-mode for
 | ||||||
|  |   // the rest of the string.
 | ||||||
|  |   if(inp) | ||||||
|  |     { | ||||||
|  |       ascii = false; | ||||||
|       while(inp) |       while(inp) | ||||||
|         { |         { | ||||||
|       if(inp > 127) ascii = false; |           // Find the translated length of this character in the
 | ||||||
|  |           // lookup table.
 | ||||||
|           len += arr[inp*6]; |           len += arr[inp*6]; | ||||||
|       inp = *(++input); |           inp = *(++ptr); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|   return len; |   return len; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue