[Scummvm-git-logs] scummvm master -> bb4944cb673e9b8456d92542ecb0e1763e82b82d

OMGPizzaGuy noreply at scummvm.org
Sun Jan 14 03:39:36 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
bb4944cb67 ULTIMA8: Ensure item locations within containers are valid.


Commit: bb4944cb673e9b8456d92542ecb0e1763e82b82d
    https://github.com/scummvm/scummvm/commit/bb4944cb673e9b8456d92542ecb0e1763e82b82d
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-01-13T21:39:02-06:00

Commit Message:
ULTIMA8: Ensure item locations within containers are valid.
Fixes #14848

Changed paths:
    engines/ultima/ultima8/gumps/container_gump.cpp
    engines/ultima/ultima8/gumps/container_gump.h


diff --git a/engines/ultima/ultima8/gumps/container_gump.cpp b/engines/ultima/ultima8/gumps/container_gump.cpp
index 1c04d7f11c6..425b4be8dc6 100644
--- a/engines/ultima/ultima8/gumps/container_gump.cpp
+++ b/engines/ultima/ultima8/gumps/container_gump.cpp
@@ -83,19 +83,71 @@ void ContainerGump::InitGump(Gump *newparent, bool take_focus) {
 	// U8 puts a container gump slightly to the left of an object
 }
 
-void ContainerGump::getItemCoords(Item *item, int32 &itemx, int32 &itemy) {
-	item->getGumpLocation(itemx, itemy);
+void ContainerGump::run() {
+	Gump::run();
+
+	Container *c = getContainer(_owner);
+	if (!c) {
+		// Container gone!?
+		Close();
+		return;
+	}
+
+	Std::list<Item *> &contents = c->_contents;
+	Std::list<Item *>::iterator iter;
+	for (iter = contents.begin(); iter != contents.end(); ++iter) {
+		Item *item = *iter;
+
+		int32 itemx, itemy;
+		item->getGumpLocation(itemx, itemy);
 
-	if (itemx == 0xFF && itemy == 0xFF) {
-		// randomize position
-		// TODO: maybe try to put it somewhere where it doesn't overlap others?
+		const Shape *sh = item->getShapeObject();
+		assert(sh);
+		const ShapeFrame *fr = sh->getFrame(item->getFrame());
+		assert(fr);
 
-		Common::RandomSource &rs = Ultima8Engine::get_instance()->getRandomSource();
-		itemx = rs.getRandomNumber(_itemArea.width() - 1);
-		itemy = rs.getRandomNumber(_itemArea.height() - 1);
+		// Ensure item locations within item area.
+		int32 minx = fr->_xoff;
+		int32 miny = fr->_yoff;
 
-		item->setGumpLocation(itemx, itemy);
+		int32 maxx = _itemArea.width() + fr->_xoff - fr->_width;
+		int32 maxy = _itemArea.height() + fr->_yoff - fr->_height;
+
+		if (itemx == 0xFF && itemy == 0xFF) {
+			// randomize position
+			// TODO: maybe try to put it somewhere where it doesn't overlap others?
+
+			Common::RandomSource &rs = Ultima8Engine::get_instance()->getRandomSource();
+			itemx = rs.getRandomNumberRng(minx, maxx);
+			itemy = rs.getRandomNumberRng(miny, maxy);
+
+			item->setGumpLocation(itemx, itemy);
+		}
+
+		if (itemx < minx) {
+			itemx = minx;
+			item->setGumpLocation(itemx, itemy);
+		}
+
+		if (itemx > maxx) {
+			itemx = maxx;
+			item->setGumpLocation(itemx, itemy);
+		}
+
+		if (itemy < miny) {
+			itemy = miny;
+			item->setGumpLocation(itemx, itemy);
+		}
+
+		if (itemy > maxy) {
+			itemy = maxy;
+			item->setGumpLocation(itemx, itemy);
+		}
 	}
+}
+
+void ContainerGump::getItemCoords(Item *item, int32 &itemx, int32 &itemy) {
+	item->getGumpLocation(itemx, itemy);
 
 	itemx += _itemArea.left;
 	itemy += _itemArea.top;
diff --git a/engines/ultima/ultima8/gumps/container_gump.h b/engines/ultima/ultima8/gumps/container_gump.h
index 04ac3a9fa82..68046713cd1 100644
--- a/engines/ultima/ultima8/gumps/container_gump.h
+++ b/engines/ultima/ultima8/gumps/container_gump.h
@@ -53,6 +53,8 @@ public:
 	// Init the gump, call after construction
 	void InitGump(Gump *newparent, bool take_focus = true) override;
 
+	void run() override;
+
 	// Paint the Gump
 	void PaintThis(RenderSurface *, int32 lerp_factor, bool scaled) override;
 




More information about the Scummvm-git-logs mailing list