RE: weights of nested containers
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Feb 16, 2004
- 549 views
> -----Original Message----- > From: Michelle Rogers [mailto:michellerogers at bellsouth.net] > Subject: weights of nested containers > > > > I am writing a mud progam in Euphoria. Currently I have each > character with > a certain amount of strength. Depending on their strength, > they can pick up > a certain amount of weight. They can even pick up other > characters, if they > are strong enough to pick up the weight of the other character. > > The way I currently do this is that the weight of the person > being picked up > is evaluated. If they are too heavy, a message is given. If > they are not > too heavy, the person picks them up. > > However, here's the problem, what if you are trying to pick > up a person, who > is carrying a person, who is carrying a person, who is > carrying a person, > etc..etc.. > I cannot get a logic in my head that would allow you to go through an > unspecificed number of "carriers" and check the weight of > everything they > are carrying. This COULD be solved by just saying you can't > carry someone > who is carrying someone else....However, I will have the > problem again, when > I have to deal with things like....a backpack that contains a > pouch, that > contains a bag...etc..etc... How about something like this... function CalcWeight( object pHolder) atom lWeightSoFar lWeightSoFar = pHolder[kWEIGHT] for i = 1 to length(pHolder[kCarrying]) do lWeightSoFar += CalcWeight( TheWorld[ pHolder[kCarrying][i] ] ) end for return lWeightSoFar end function TotalWeight = CalcWeight ( theObject ) This assumes you have a sequence that holds all the data for an entity, and that sequence has a weight attribute and a list of things (an index into the 'world') that the entity is carrying. > Can someone help me figure out a logic for this. > > There is a variable on every object in the mud that I call a "roomin" > variable. I started it to tell which room a player or object was in. > However, each "thing" in the mud has a unique id. So, I've > changed it so > that the "roomin" variable doesn't have to point to a room. > This is how you > can be carried by another player. Instead of your "roomin" > variable having > the id number of a room, it has the id number of the person > carrying you. > So, in theory, you are "inside" the person carrying you > (according to the > data structure, anyway) > > So, here's how it would work. To know if someone is carrying > someone, I > have to check all players and see if their "roomin" variable > is the id of > the person I am checking. That's easy enough and I can add > the weights of > ...let's call them the "first generation of people being > carried". However, > it's when I start to check the roomin variables of everyone > to see if they > are carried by the first generation carriers, that I start to run into > problems. Sure, I can do that. It's basically the same thing. > > But, how do I tell the code to keep checking until I've > gotten to the end of > everyone who's being carried (i.e. the "last generation" of > people being > carried)? > > hmm...as I actually typed out an explanation..I'm getting a > sort of a hazy > idea..so I may figure this out..but I'm still going to post > the message, > just in case. > > Michelle Rogers > > > > TOPICA - Start your own email discussion group. FREE! > >