The top-most objects on the floor

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
Erik Svanberg

The top-most objects on the floor

Post by Erik Svanberg »

I tried to fill in mouse coordinates in the configure file in order to pick up
objects from the floor with the aid of the keyboard.
This works almost all the time, but a small object (like a coin) that lies
behind a large object (worm round) would not make it possible to pick up
the coin. If I adjust the new coordinates needed to pick the coin, then
the keyboard would fail elsewhere.

I want to implement this in the code instead (if possible). I want to bind
four keys to the upper-most object on each square.
Would it be hard to find out the top-most object of a given square, and
put it in the hand (whithout using the mouse)?
User avatar
Paul Stevens
CSBwin Guru
Posts: 4322
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Post by Paul Stevens »

I think you you mean the topmost object in
each of the four piles of objects rather than the
topmost object in the cell. The things you can
pick up are in four piles, two in the cell you
occupy and two in the cell immediately ahead of
you. I cannot think of a way to 'define' the topmost
object in the room that makes sense an all cases.

Assuming I am right about your intent........

You should not be able to pick up any but the topmost
object in a pile. You already know that. If the topmost
object in a pile is hidden by an object in a closer pile
then you cannot see it and you should not be able to
pick it up. Do you mean to break this rule?

The engine allows you to pick objects you can see.
So there is no way to define the keystrokes in the
config.txt file. Your experience confirms this fact.

So....can it be done in the code? I think it could. It is
not exactly straight-forward however. The best I can think
is to translate the keystrokes to unique mouse-click
codes (buttons 11 through 13, for example). Then, when the
mouse-clicks are processed we would have to examine the
position of the graphics on the screen (ensuring that the
adventrue screen is being displayed) and either discard
the click or translate it back to a normal click with the
necessary x-y coordinates. Then process as usual.
Erik Svanberg

Post by Erik Svanberg »

I feared something like this.

But, my hope is that the game should know what object lies top most in each
pile, and its screen coordinates, and all I have to do is ask.


please enlighten someone who dont know the inner workings of CSB.
Where do I find the topmost objects? Where should I start (what files)?
User avatar
Paul Stevens
CSBwin Guru
Posts: 4322
Joined: Sun Apr 08, 2001 6:00 pm
Location: Madison, Wisconsin, USA

Post by Paul Stevens »

The game has a list of items for each cell.
Within that item is the position of the item
within the cell (north, east south, or west for
walls and nw, ne, se, sw for floors). So there
is one list for each cell. You start at the top and
find the first item that is not a teleporter or
door or actuator, etc which is at the position
of interest. That is the item at the top of that pile.

When the viewport is drawn there are several
side-effects. One of the side-effects is that the rectangle
bounding each object is entered into a table.
The topmost because that is the last one drawn. These
rectangles may overlap so when processing a mouse
click it looks at the rectangle for the nearer pile first.

Where to look in the code? I have no idea. The CSBUI
gets the input and puts it into queues. There is a function
something like 'ProcessMouseEvents' which takes things
from the queue and decides if the click is in the viewport.
I think there is a function like 'ClickInViewport'.
If it is then it starts examining the rectangles. Don't forget
that switches can be down low and objects can be in alcoves.
Also, don't forget that the record/playback business has been
attached to the mouse queue in a rather, shall we say, fragile
way (I'm still amazed that it works). So you will need to
modify the recording and playing code, too. I think.

I am not against attempting this. But perhaps it would be
getter to attend to the ugly details offline. I reformatted my
system disk and would have to go to the backups to find your
EMail. You probably know mine. If you want to proceed I
can help a lot more after referencing the code. Also, remember
taht if you want to change the code you need to get my version
of the source, not the released version, unless you plan to
go off on your own and split this into two separate projects.

Hope I have not frightened you. But I would like to convey the
notion that it will be a challenge. CSBwin is not a clean program.
Post Reply

Return to “Chaos Strikes Back for Windows & Linux (CSBWin) / CSBuild”