A fairly productive weekend, all things considered. I spent pretty much all day Saturday coding, and probably most of Friday evening. I took a siesta on Sunday, putting forth the last steps to shucking Lavos out of its shell in Chrono Trigger DS. I've pretty much exhausted all the side quests, and now I've little doubt my level 55ish heroes can pull it off.
Wasps
My communal-level defenders of the planets have undergone a radical restructuring of concept over the weekend. Instead, they're colonies of insects of sorts whose main focus is in redistributing nutrients. I'm fairly reminded of the Zerg from Starcraft. I've even implemented a Creep of sorts, this insect-like race actually changes the surface of the planet to suit their needs.
The behavior was surprisingly hive-like. The "Queen" lays an egg which hatches a "worker." The worker finds nutrients (such as grassland), consumes it, and returns the nutrients to the Queen. The Queen uses these nutrients to lay more eggs. Before you know it, there's hundreds of workers swarming around, looking for nutrients.
I found the CPU tends to bottleneck around the 700th worker. It's not a BYOND problem, it's a game design problem: I really shouldn't need 700 moving NPCs for an effective swarm implementation. What's going on right now is the Queen is getting glutted with more nutrients, outpacing her egg-production capacity, as she has nothing good to spend them on.
I think I'm ready to make the game a little more advanced now - introducing more specialized roles to my workers. Unless I decide to make these guys as little more than cannon fodder, I need to make them interesting for players to play. Perpetually feeding the queen is probably not most players' idea of a good time. (Granted, there is a working model of a game that has found a way to make that interesting.)
This is primarily a game involving conflict between multiple factions, after all. Before I'm done, these little virtual bugs are going to be building actual hives, complete with specialized chambers and deadly defenses.
Smart Guns
I mentioned in earlier comments the concept of having a weapon contain also the AI in using it. I tested that principal this weekend and found that there's a certain degree in which it works well.
At one point, I had code that would work a bit like a chess AI. It would look at every weapon in the mob's contents and get those weapons to return a score reflecting its viability as the best action. That was going too far. The mob carrying the weapon usually has a primary goal in mind that the weapon isn't able to be made aware of. Besides, having the AI on the weapons perpetually re-assessing the situation of the mob carrying them is just too bloaty.
Instead, I've adopted an understanding that each weapon in a mob's inventory addresses a specific need. The mob handles the state-level choice of which need to address and chooses the weapon which addresses that need. Then, the weapon contains the AI to place itself in a state in which it can activate. That works rather well.
In case it isn't clear by now, when I'm saying "weapon," I'm actually referring to actual abilities that mob carries in its inventory, which do things more diverse than merely attacking. These same abilities are actually usable by players controlling those mobs, using the same procedures that the AI utilizes.
Next Milestone
I can really put it off no longer: if it is indeed my plan to have these units drive like vehicles, I'm going to need to add movement code that takes the place (or rather harnesses) step_towards and other like procs. This basically breaks down to plotting out moves ahead of time and sequencing them at an appropriate speed.
The queen should be able to have workers construct a hive. The queen could then enter the hive and remain dormant with other workers who aren't needed at the moment. You could then regulate how many workers are out and about since they have to enter and exit the hive in order to get to the queen.
You could then have a swarm of 500 wasps exit the hive whenever it's under attack. |
If you're looking to implement a pather, my humble suggestion would be a datum. In SotS II, pathing is handled with a special datum that basically contains a specialized list for heap sorting, and then the datum can make cost choices based on who it's being used by. It can also keep things like info on path cost separated per unit instead of storing that stuff in a turf var. I've been big on movement queues since my earliest BYOND experiments. (This is because I never liked the idea of just hammering your cursor keys for fast movement, which seems to work in most BYOND games.) At first, I used corresponding arrays, but after I picked up the gist of datums, that was definitely a better way of going about it. Object orientation to the rescue! My last design had something that looked like: action ..var/actionObject/what ..var/atom/where ..var/how The actionObject would be a reference to a class of objects that have the action being performed. The where would refer to what that action is being performed on. Of course, some actions might implicitly be performed without a target, but in that case the arg is just ignored by the interpretation engine. The "how" would refer to a special argument that might modify some actions. Not all actions would take an argument, of course. The real fun of this trick was that I would not only use these arrays for movement engines, I would also use for them client.images generating procs which show the player controlling the unit the moves they've got queued. The queen should be able to have workers construct a hive. The queen could then enter the hive and remain dormant with other workers who aren't needed at the moment. You could then regulate how many workers are out and about since they have to enter and exit the hive in order to get to the queen. You could then have a swarm of 500 wasps exit the hive whenever it's under attack. Hmm, you know, I was avoiding doing it this way because I thought it would be important to have everything out an exposed at all times, make it into a game of attacking a swarming hive in order to get at the queen. However, what you're recommending puts me in mind of a great idea for an evolution of what I'm doing. The "queen" right now is pretty much just a big sack of nutrients that spits out new units. Maybe instead of having her directly exposed and out in the open, I could have her represented by a simple hole in the ground. She's actually referring to the whole hive's nutrient storage and unit generation capacity. Now, if you want to defeat the hive, what you have to do is starve the queen. |
On second read, I see what you (Lummox JR) are saying now with having a specialized movement handling datum. Much more advanced than just having a list of that datum, to actually have the datum tracking its own list.
I like that idea a lot. I could even include a proc for generating client images. I was suffering from a bit of a handicap because I never actually understood how to pass lists. However, I just took 5 minutes in the Dream Maker and figured it out. I've got to specifically use "var/list/variable" as the arg variable. |
I need a good pathing library. I tried using Theodis' but I'm having trouble getting it to work, and also I need one that evaluates using turf.Enter(). Any recommendations?
|
One of my first mini-projects on BYOND actually was to propose a means of adding regions to Deadron's pathfinding library, so I've had some interest in this topic myself for a while.
I suspect libraries are best used though in situations where pathfinding is a secondary concern or something that calls for only a relatively un-customized system. For games that want to get more out of pathfinding, rolling your own is probably the better way to go. In SotS II my pather works by using an associative list to point to an index in another list where data about a turf is stored (its cost and heuristic functions for A*, basically). It's a little convoluted but speed-wise I think it's pretty decent. The Stickster actually stresses it to its limits because in the current setup he can path across levels using ladders, so he can actually plot a route to get to a player who is otherwise blocked off by temporarily switching pages. The NPCs however only path across a shorter distance at any given time, calculating just part of their route and periodically rechecking. That's not a universal solution of course because my NPCs and the Stickster can both blast walls out of their way if they have to, but it does get the job done. |
I was afraid you'd say that. After I wrote that, I realized Enter() or .density checks weren't going to hack it.
Oh well, I actually sort of look forward to gaining the experience involved in rolling my own pathing algorithm. Sounds like you came up with a pretty cool one. I found at least one good tutorial on how to make an A*. After I wrote this Blog entry, I went off to do some more coding, switching my NPCs over to a movement queue system. My head really wasn't in the game, but I managed to power through anyway. Having my NPCs run on a model where they plan ahead instead of reassessing the situation every turn has saved a lot of CPU cycles. I'm running nearly 600 thralls right now, all actively foraging, and my CPU is at about 20% capacity. The little guys have really decimated the local flora. :) It's remarkable to see desert stretching out about 50 spaces in all direction and yet my little foragers can still find a bite to bring back to the queen. Maybe I won't need to teach them how to farm after all. |
A* pathing actually isn't that bad, plus you can hack it a bit to make shortcuts. In SotS II the pather will use the autojoin flags for the empty spaces to tell it how far it can explore in any given direction, which can help a lot with quickly getting a lower-cost turf in the mix.
Heap sorting has worked quite well for me in this, since with A* at any given time you're working with the turf on the "open" list that has the best cost+heuristic value. You can quite easily keep a loosely sorted list and bubble up the best candidate as you go along. |
This is neat.
As far as the insect movement goes. May I offer a potential movement idea. ExitHive() IfNoFoodAndNoLocation() BeginSearch() AskNearByFriendsForLocation() IfLocationProvided() GotoLocation() else MoveRandomlyAwayFromHive() BeginSearch() GotoLocation() I will move toward this location without any further processing until I arrive or something triggers me to change what I'm doing. This can be an attack event or I've entered a turf surrounding food in which case, I change my course. If I arrive to my destination and no food is present, BeginSearch(). MoveRandomlyAwayFromHive() Move randomly away from hive with a +1 value for moving away from hive. If no food has alerted me to it presence, continue to move randomly. As a side note, your insects should have a health bar that goes down as they travel. After x(3) random searches for food, they must give up and return to the hive. I think this would give the hive a sort of realistic pattern as they form a path to the food source like ants. If the food source dries up, they would scatter from the last known location. If the food really dried up, they would start to scatter from the hive. If you make it possible for some hive members to spawn and move without getting information first, you would get more spread. If you also add a few random events which cause havoc for your hive. - Shiny object which tricks the hive into investigating and losing its last location. Shiny objects spawn at random locations and must be removed by the player once they notice it's causing problems for their critters. - A battle would cause the loss of food location. - An attack on the hive would cause loss of last food location if they were involved. This is fun to think about and fun to program for sure. I could go on all day. You definitely need roles for you spawn though. They could automatically be assigned based on a balance scheme but the player could override. As an example... the hive gets attacked, they all automatically switch over to attack mode. After the battle, should they switch back to their last known action or should the forget it and ask the hive what they should do? The hive would respond with, I'm damaged and need repair more than I need food, repair me. The player would see all the insects moving to repair but they could override this and go collect resources instead. ah.. this is all obvious stuff... but fun to think about none the less. ts |
A* pathing actually isn't that bad, plus you can hack it a bit to make shortcuts. Sounds like an ongoing project. Still, what kind of game designer would I be if I didn't like to dabble? ;) As far as the insect movement goes. May I offer a potential movement idea. Looks like we're thinking along like lines in many aspects. I've got a lot of these built into the same proc - my "consume" weapon AI routine - right now: IfNoFoodAndNoLocation(), AskNearbyFriendsForLocation(), MoveRandomlyAwayFromHive(). Right after last night's comment, I came up with a pretty cool mechanism for finding food. The idea is that this hive has a hive-mind mentality - they can share all knowledge, and they do so via the hive - so what I have is a "lastNutrientsLocations" list on the hive. The first thing a worker does is check its view() for any edibles, and if it can't find any, it goes to a random member of lastNutrientsLocations, and if there's nothing good there, it randomly wanders to one hex within the outer range of its view(). There's a (currently 25% chance) that they'll ignore lastNutrientsLocations and forage off of their own anyway. I'm not making them move directly away from the hive because there's a chance some nutrients will show up even after an area has been stripped. A really slick thing about this implementation is that the lastNutrientsLocations list is automatically maintained. Every time a nutrient is found, it's added to the list, and also any close by locations in lastNutrientsLocations are consolidated to this location. Every time a worker reaches the "there's no nutrients in view" mode, it removes all turfs in view from lastNutrientsLocations. When I count lastNutrientsLocations.len, those are really individual locations at least half a world.view apart where nutrients had been found recently, and I've seen the number hit the 20s. What I have on the actual mob itself is probably going to be a current behavior state. The "consume" AI is followed as long as the worker is in "forage" mode, but they might be swapped into other behavior states. "Battle," "build," and so on. Workers might be able to do everything from that one state. I'm currently planning on having workers treat enemy units and structures as nutrient sources. ;) This should result in a steady trickle of workers descending on any poor player who allows a bite to be taken out of them. What I'm really stuck on is more the idea of find new and interesting thing for the individual members of the hive to do. I want being an individual member of these hives to be something players are interested in doing. Consequently, I'm thinking I'll probably have a mechanism of "evolving up" to more complicated (not just foraging) forms of the insects. You might start off as a humble forager, but before long you might be a nest maintainer (fortifies the nest) or a soldier, and so on. |
Well, if they could build things... that would give you a lot of options.
- Build defensive fortifications they can call there own and sort of branch out. They are in charge of defending this area because they happen to build there. If they could redirect water... If they could move boulders to redirect water for both good and bad purposes. Think, flood hive. Build bridges over water which is a blocking obstacle. Dig tunnels. If your game provided an underground view where the hive can expand and wars can be done. Think water flooding enemy cave because of gravity and blocking rocks put into place. By terraforming, can they transform dirt into walls? Transform dirt into a turrent that will be manned as needed. Can the individual hive members gain some form of xp? I think you mentioned that at some point which allow for building bigger things and having more health and what not. You could do more of a skill tree. Complete x number of things in order to unlock the next things. What if player mobs could recruit AI mobs to perform tasks such as moving larger objects. I could come back to the hive, recruit 4 AI mobs (because of my rank), and then use them to attack an enemy structure. I stand back and watch as they get slaughtered, and flee when things get bad. Now I have to apply some strategy to succeed at capturing that enemy structure such as digging under it, diverting water via terraforming, recruiting different types of units, and etc. ts |
Geldonyetich wrote:
Right after last night's comment, I came up with a pretty cool mechanism for finding food. The idea is that this hive has a hive-mind mentality - they can share all knowledge, and they do so via the hive - so what I have is a "lastNutrientsLocations" list on the hive. In SimAnt, nutrients and nest entrances were found via scent trails, which is roughly what regular ants use. Bees on the other hand perform a dance that indicates how far the flower field is from the hive and what its orientation is relative to the sun. I guess this would be equivalent to the bee dance. |
Some interesting ideas here. Walls and Turrets have come to mind, as well as potentially setting traps. Though I thought of building bridges, the idea of redirecting water never occurred to me -- that could be quite cool.
I've avoided going subterranean for now because I'm sticking to K.I.S.S. and this supposed to be a vehicular warfare game. Underground tanks? Not uncool, just a bit unusual. When it comes to terraforming, I'm currently thinking I'll have them turn barren land into this sticky goo that can be molded into various shapes. The idea of redirecting water makes this potentially interesting because I was thinking that this terraformed land may require being fed, and maybe a nearby water source could be one means to do so. Can the individual hive members gain some form of xp? I'm currently thinking that players who are going to play a role in the hive will need some kind of incentive, so some kind of "karma" system that enables them to evolve up into the next form is going to be added. I'm trying to avoid too much focus on accumulation. I don't want this to be a grind. So I'll probably keep things simple enough that they just have to demonstrate a basic competence to evolve their unit. I may also leverage that Hive Mind aspect by allowing them to switch bodies to uncontrolled members of the hive. I haven't decided yet. What if player mobs could recruit AI mobs to perform tasks such as moving larger objects. This worked well in SimAnt, quite possibly I'll add something like this. One concept I had was the idea that a new queen takes half the hive with her. This is similar to swarming. In SimAnt, nutrients and nest entrances were found via scent trails, which is roughly what regular ants use. Bees on the other hand perform a dance that indicates how far the flower field is from the hive and what its orientation is relative to the sun. I guess this would be equivalent to the bee dance. Hehe, the bee dance, I didn't think of that but you're right. SimAnt's scent trials definitely occurred to me. There's a couple reasons I balked from that, however: First, if players were allowed to lay down trails, they could use it to sabotage the hive. Second, because all that pathing sounds tricky to program. ;) The idea behind my current recentNutrients variable is that it can only be generated from successful consumption of a nutrient, so you can't fake that you found some. It works similar to a scent trail in that the little insects head straight towards a random one, but it's a lot simpler. |
That is sort of confusing me. A vehicular war game with bugs... or is it microbugbots? :) I can grasp microbugbots upgrading into larger vehicles and what not but bugs... :) heh.
Will a player be a bug driving in a vehicle or will they be the vehicle or will they control a bunch of vehicles? ts |
Basically, these are alien bugs the size of vehicles, and only one of the factions the players can play.
You'll encounter a situation in which you're piloting a Battlemech fending off swarms of bugs, or working along with other players trying to take down a hive. Or you could be a member of the hive trying to dismantle a colonist settlement, one digested subneutronium metal plate at a time. |
So... you control a single bug and hopefully work along side a couple of other player controlled bugs and a ton of AI controlled bugs right?
ts |
Pretty much. Or maybe you and your fellow players are sentient presences within the hive mind that lends its intelligence to individual members of that hive. (I say this because I'll probably make it so can swap between the individual bugs.)
|
So... a player might have to come back to the hive in order to transform. Each "bug" has unique abilities. As part of their abilities, they get n number of drones that follow them. The number is based on the abilities of the bug. You place a building framework and your drones hurry to build it by gathering nearby resources. Your building location is important because if you need water+dirt+hyberium to build a turrent, then you want those 3 resources to be close by unless you brought some with you.
Interesting, can the hive store materials for you or will you implement the concept of storage via special mounds (silos) built by the players. Could players have their own private storage bin? A large part of strategy could be your storages and protecting them. If you build a silo out in the middle of nowhere, it suggests that it connects to the main hive so you have access to all the resources in the main hive remotely so getting resources can be done faster. However, their is risk involved if the enemy should get access to it. Perhaps the player should get punished of the mound is accessed through their structure. Bad karma as you said. ts |
More good stuff - I love the brainstorming capacity of some of the members of the BYOND community.
It's sort of up in the air as to just how the transformation will occur. It might be that I don't have the units actually evolve (zerg-like) but rather the Hive births different units with different roles. Currently, the only resource for the hive is "nutrition." that comes from devouring certain things on the map. It's not that it hasn't occurred to me to go all RTS in resource types, but I'm thinking it might be more interesting if these insects will work on a heavily biological theme. Everything they make is repurposed life, though they might chew apart manmade things to get the needed "nutrition" to make it happen. Of course, that could all change if I decide there's a really good reason for me to stop dragging my feet and stop trying to reinvent what RTS games have already done. ;) Another heavy aspect I'm trying to preserve if you play as a bug is that the idea of personal ownership is set aside in exchange for communal advancement. If you're playing a bug, you benefit if the hive benefits. This is in stark contrast to some of the other factions I've been thinking of. For example, I'm thinking I might just have a Pirate/Mercenary faction which is all about going solo, stealing everything you can get your mitts on, and personal power advancement. A path of extreme power with one little catch: you don't have anyone to back you up if things turn sour, and death of a Pirate/Mercenary is permanent. To an extent, I think I'm trying to shoehorn a moral lesson into the thing. If you want to be self-serving, you can, but you leave no lasting legacy. A bug is essentially part of a greater superorganism, so they don't truly die unless the entire hive does. An individual that would be part of the human colonization efforts might die, but they leave behind a legacy that benefits their respawn (those who follow). A pirate/mercenary leaves behind a beautiful corpse, but upon restarting pretty much just starts from scratch. |
Eventually I think I'll probably update the Stickster's AI to something a lot more like the NPCs', except maybe a little more single-minded so it still does stuff like bump into crayon barriers.