ULTIMA8: Const and type correctness

This commit is contained in:
Matthew Duggan 2020-04-25 18:50:56 +09:00
parent f89e6e4b1b
commit 4d72136ed1
6 changed files with 17 additions and 17 deletions

View File

@ -273,8 +273,8 @@ uint32 Container::getContentVolume() const {
}
void Container::containerSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, bool recurse) {
Std::list<Item *>::iterator iter;
uint32 scriptsize, bool recurse) const {
Std::list<Item *>::const_iterator iter;
for (iter = _contents.begin(); iter != _contents.end(); ++iter) {
// check item against loopscript
if ((*iter)->checkLoopScript(loopscript, scriptsize)) {

View File

@ -84,7 +84,7 @@ public:
//! \param scriptsize The size (in bytes) of the loopscript
//! \param recurse If true, search through child-containers too
void containerSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, bool recurse);
uint32 scriptsize, bool recurse) const;
//! Get the weight of the container and its contents
//! \return weight

View File

@ -431,7 +431,7 @@ void CurrentMap::clipMapChunks(int &minx, int &maxx, int &miny, int &maxy) const
void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, const Item *check, uint16 range,
bool recurse, int32 x, int32 y) {
bool recurse, int32 x, int32 y) const {
int32 xd = 0, yd = 0;
// if item != 0, search an area around item. Otherwise, search an area
@ -474,9 +474,9 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
continue;
// check item against loopscript
if ((*iter)->checkLoopScript(loopscript, scriptsize)) {
if (item->checkLoopScript(loopscript, scriptsize)) {
assert(itemlist->getElementSize() == 2);
uint16 objid = (*iter)->getObjId();
uint16 objid = item->getObjId();
uint8 buf[2];
buf[0] = static_cast<uint8>(objid);
buf[1] = static_cast<uint8>(objid >> 8);
@ -485,7 +485,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
if (recurse) {
// recurse into child-containers
Container *container = p_dynamic_cast<Container *>(*iter);
const Container *container = p_dynamic_cast<const Container *>(item);
if (container)
container->containerSearch(itemlist, loopscript,
scriptsize, recurse);
@ -497,7 +497,7 @@ void CurrentMap::areaSearch(UCList *itemlist, const uint8 *loopscript,
void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, const Item *check,
bool above, bool below, bool recurse) {
bool above, bool below, bool recurse) const {
int32 origin[3];
int32 dims[3];
check->getLocationAbsolute(origin[0], origin[1], origin[2]);
@ -509,7 +509,7 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, ObjId check,
int32 origin[3], int32 dims[3],
bool above, bool below, bool recurse) {
bool above, bool below, bool recurse) const {
const Rect searchrange(origin[0] - dims[0], origin[1] - dims[1],
dims[0], dims[1]);
@ -563,9 +563,9 @@ void CurrentMap::surfaceSearch(UCList *itemlist, const uint8 *loopscript,
continue;
// check item against loopscript
if ((*iter)->checkLoopScript(loopscript, scriptsize)) {
if (item->checkLoopScript(loopscript, scriptsize)) {
assert(itemlist->getElementSize() == 2);
uint16 objid = (*iter)->getObjId();
uint16 objid = item->getObjId();
uint8 buf[2];
buf[0] = static_cast<uint8>(objid);
buf[1] = static_cast<uint8>(objid >> 8);
@ -606,7 +606,7 @@ bool CurrentMap::isValidPosition(int32 x, int32 y, int32 z,
ObjId *roof) const {
const ShapeInfo *si = GameData::get_instance()->
getMainShapes()->getShapeInfo(shape);
int xd, yd, zd;
int32 xd, yd, zd;
// Note: this assumes the shape to be placed is not flipped
si->getFootpadWorld(xd, yd, zd, 0);

View File

@ -84,18 +84,18 @@ public:
//! \param y y coordinate of search center if item is 0.
void areaSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, const Item *item, uint16 range,
bool recurse, int32 x = 0, int32 y = 0);
bool recurse, int32 x = 0, int32 y = 0) const;
// Surface search: Search above and below an item.
void surfaceSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, const Item *item, bool above,
bool below, bool recurse = false);
bool below, bool recurse = false) const;
// Surface search: Search above and below an item.
void surfaceSearch(UCList *itemlist, const uint8 *loopscript,
uint32 scriptsize, ObjId id,
int32 origin[3], int32 dims[2],
bool above, bool below, bool recurse = false);
bool above, bool below, bool recurse = false) const;
// Collision detection. Returns true if the box [x,y,z]-[x-xd,y-yd,z+zd]
// does not collide with any solid items.

View File

@ -618,7 +618,7 @@ uint32 Item::getVolume() const {
}
}
bool Item::checkLoopScript(const uint8 *script, uint32 scriptsize) {
bool Item::checkLoopScript(const uint8 *script, uint32 scriptsize) const {
// if really necessary this could be made static to prevent news/deletes
DynamicUCStack stack(0x40); // 64bytes should be plenty of room

View File

@ -377,7 +377,7 @@ public:
//! \param script The loopscript to run
//! \param scriptsize The size (in bytes) of the loopscript
//! \return true if the item matches, false otherwise
bool checkLoopScript(const uint8 *script, uint32 scriptsize);
bool checkLoopScript(const uint8 *script, uint32 scriptsize) const;
uint32 callUsecodeEvent_look(); // event 0
uint32 callUsecodeEvent_use(); // event 1