PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 16, 2017 5:16 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Feb 01, 2017 1:23 pm 
Offline
Forum Newbie

Joined: Sat Oct 22, 2016 10:42 am
Posts: 17
Help me simplify my idea?

I'm still working on my very complicated game (society simulator). One of my idea is change projects - that given enough time, objects can turn into other objects if they are inside a "machine" (pot, drying cloth, fire pit, oven). This doesn't require player characters to actively do things to advance the project, but for each project type, certain conditions must be met. So far, I have only worked with projects that require an ongoing fire. When ever a user sees the fire pit on the items page, it checks if there is a fire, if there is fuel for said fire, and if not, what time does the fire go out? I have this part figured out. But I need a similar system for presence of fresh water, brine and sunlight.

For soaking, there needs to be water and the amount of water must be large enough in relation to the amount of soakable resource (such as beans). So technically it needs to cover them. If I wanted to make things more complicated, I could also make it so that if there is less water than needed, part of the resource will eventually get converted, but that would require splitting the pile, which I would rather not do.

Then there's fermenting. It's similar to soaking except instead of fresh water, you have brine. If we want to get very technical, you should start with brine that has salinity of 12-14% and increase the salinity by 2% every 2 or 3 weeks. I might be okay with skipping that part, and agree that okay, you just need to check that brine is present and use a fixed salinity.

Likewise, if you are tanning hides using vegetable tanning, technically you need to start with a mild solution, then switch into a stronger solution gradually, because if you tossed the hides into the strongest solution straight off the bat, they would only tan on the surface and the inside would be left unchanged. I might also want to keep track of the level of bacteria in the tanning solution, and if the user doesn't change it often enough, the hides will start deteriorating.

For the drying cloth, it needs to check if it has rained since the last time it was checked and if yes, somehow set the condition of the dryable stuff into "wet", which will mean they take a longer time to dry and can potentially rot or get moldy. Weather is recalculated hourly in places that have someone checking and stored in a table. If no one checks the weather then it just assumes it was irrelevant. Each pile of a resource is a row in the objects table, and once it has dried for a long enough time, it will change the object type from normal resource to dried resource. So there are no different levels of dryness currently, either something is dried or it's fresh, there is no gray area. I do have an object status table that is currently used to record things like how much blood an animal has left, or if a flammable object is on fire or not. So technically I could also use it to keep track of dryness/wetness, but then I would have to duplicate the rows when ever the pile is split. Or what if someone merged two piles with different dryness levels? Should that even be possible? IRL if you put raisins and grapes in the same bowl, anybody would be able to tell the difference and be able to separate them into two groups.

Each time the user views the machine, it should check 1) are there things inside that are capable of changing and 2) are the other conditions met. How should I define the conditions in the database?


Top
 Profile  
 
PostPosted: Wed Feb 01, 2017 1:53 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6571
Location: WA, USA
This is getting complicated enough that you should consider switching away from the "update on view" approach and instead go to background tasks. For example, setting up a fire pit starts a background job that periodically reevaluates the amount of fuel left; if X amount of fuel lasts for Y minutes then every Y minutes you subtract X from the amount of available fuel and extinguish the fire if there isn't enough left. Soaking works the same way except the fire pit is beans and the fuel is water. Fermenting is also the same, but when evaluating the brine you also check its salinity.

However given the number of potential tasks, rather than actual background tasks (processes) you'd have a set of actions that are initiated periodically. Like how cron works.

But your question is about the database.

My opinion is somewhat controversial: store names of classes along with whatever information they need. Probably serialized, which is typically a no-no with databases but the issue is searching and I don't see a strong need for arbitrarily searching through conditions. These classes follow a specific design which allows them to be fired up whenever needed, with whatever data got serialized, and they do whatever they need to do. The "BurningFirePit" class is told which fire pit to process, "SoakingItemInWater" is told what item in what container is soaking, "FermentingItemInBrine" is told what item in what container and how long it's been soaking, and so on.

Getting more precise than that requires knowing more technical information about how your system works.


Top
 Profile  
 
PostPosted: Thu Feb 02, 2017 5:07 am 
Offline
Forum Newbie

Joined: Sat Oct 22, 2016 10:42 am
Posts: 17
Thanks for replying. One of my problems is that currently time works differently from any other game, in that each character has their own timeline and they can be ahead or behind other characters time-wise. So if someone views a fire pit in the future, it calculates the whole burning arc up to that point and if it runs out of fuel, it records which time. Then if a character in the past views the fire pit, if their time is before the time the fire runs out, they are able to take advantage of the heat because from their perspective it hasn't gone out yet. But I realize this is a very clumsy system, so I should probably change it into a system that gives people a certain amount of action points per hour, and everyone remains in the same time. The reason I didn't originally do that is because the game is very fast paced (one day in real time is one month game time), so I didn't want to run into a situation where characters could starve or freeze to death while the player is offline. In the current system, things only happen to characters while the player is active. It seems unnatural that characters would spend anywhere from 14 to 23 days out of 24 in a month asleep, so I would have to allow automated tasks that the player can set up. I'm willing to slow things down so that one day is 1 or 2 weeks, but no slower than that, because farming is going to have a big meaning in the finished product, and I don't want it to be unrealistic like Farmville where crops mature in anything from 5 minutes to a matter of hours.

One idea I had in the shower is that players could allow other players from other timezones to take turns commanding their characters like an NPC, so everybody could benefit from being controlled by a real player without players having to be logged in 24. So if there was a team of three players where one is from Moscow, one from New York and one in Sydney, they could decide that each one has a character in charge for one third of the day. That would reduce the number of decisions made by AI and have the characters behave in a more natural fashion.


Top
 Profile  
 
PostPosted: Thu Feb 02, 2017 10:06 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6571
Location: WA, USA
Seeeks wrote:
One of my problems is that currently time works differently from any other game, in that each character has their own timeline and they can be ahead or behind other characters time-wise.

Aww, why did you have to go and do that :(


Whether you want that system or not is a question for the game. Do you want all players advancing at the same rate? Or do you want this time mechanism in play? Honestly, I'm not sure how you can have it and keep any sort of realistic social aspect in the game: single player is fine, but multiplayer means interaction and people need some kind of common ground to share. With that said, the mechanic could lend itself to interesting gameplay, so don't let its novelty dissuade you.

Assuming you keep it,

...well, computed at view time sounds like the best, or even only, way to do it. My answer to how to store it in the database would be about the same as before: store the name of a handler class and whatever serialized data it deems necessary.


Top
 Profile  
 
PostPosted: Thu Feb 02, 2017 11:22 am 
Offline
Forum Newbie

Joined: Sat Oct 22, 2016 10:42 am
Posts: 17
My original logic was that I wanted to allow players to advance at their own pace, but it does hinder social interactions quite a bit. That's why I'm looking into changing it. It's going to require rewriting some things, so it's going to be a big change. My current idea is to limit the AP a person can spend in a real life hour. The logic is that AP will still be spent as fast as you can click, so if there was no limit at all, a person could make huge advancements in a matter of seconds. And for some reason, this would be bad. I forgot why. It just feels like the amount of actions that can happen within a short time need to be limited, but yet I don't want to make it so that every time you make a move, it would force you to wait anywhere between 5 minutes to 4 hours, unable to make another move. I want to be able to make multiple moves in a row, then take a break and do something else while waiting for my AP to refresh. And I want to be able to see the results of the moves straight away: for example if my character crafts a tool, I want to be able to use it immediately on the next step of their building process without having to wait an arbitrary time.

If they know they won't be able to log in, they can either automate the behavior or hand over control to a friend from a different timezone.


Top
 Profile  
 
PostPosted: Thu Feb 02, 2017 1:07 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6571
Location: WA, USA
What you're describing sounds typical for a casual game, but I don't see how the variable time solves the problem. If everyone accrues AP at the same(ish) rate then what's the problem with letting them spend a lot at once? For the player to do that it means they had to not spend a lot earlier and let the AP build up, and on the flip side other players could spend AP during that same time frame but they'd lose out on the big advancement. It's the kind of trade-off that's common to almost all games: do many little things now or wait and do bigger things later.


Top
 Profile  
 
PostPosted: Thu Feb 02, 2017 4:17 pm 
Offline
Forum Newbie

Joined: Sat Oct 22, 2016 10:42 am
Posts: 17
I went through all the files that had something to do with time advancement/reading/recording and changed it from individual timelines to using the same time for all. It took less time than I thought it would, but it's possible I overlooked something. Currently AP is gained through resting and since resting is instantaneous, currently people can technically get 1000 AP in one minute (that's the cap you can have stored at once). But since it's just a test version, it doesn't hurt anyone (yet) if people have unlimited AP.

There's a lot of things I need to work on. One of them is what I originally discussed in this topic, that is projects that cause things to change in time if conditions are met. Another thing is healing wounds. I don't want damage to be trivial, because if anybody can just bash an animal, then go rest until they regenerate and repeat once they have healed, that's too easy. Then there's the farming system. These three are at the top of my list. Technically for the healing system, I could start with something simple and refine it later.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group