Éa III, Sword & Sorcery: Coders' Thread

@Doopliss

I already posted some details for Lycanthropy way back, so I'm going to be possessive about that. ls612 was planning to work on Vampirism. It's going to be a while on both of these, but they should be worth waiting for.

One thing I didn't put on list above but has been discussed is Dungeons. Would you be interested in implementing a system for that? Maybe you could talk BouncyMischa into converting a tile improvement for it.
 
Unless you just want an FFH-style "stand on dungeon, use ability, messagebox pops up" I'm going to assume that's way beyond me. If that is what you want, I'll see what I can do.
 
Alright, next up in the continuing chronicles of Doopliss is Incapable of Learning Lua (really, you should have seen this coming when you asked me to do something):

Let's say I added EaDungeons.lua, which currently contains a non-local "explore dungeon" function that does nothing. I plan on doing quite a lot here, so I really don't want to dump the functions elsewhere. What do I have to do to call this function from a different lua script? include("EaDungeons.lua") doesn't seem to cut it, nor does including it and doing a "local EaExploreDungeon = EaExploreDungeon" definition. If it helps, the bug is "attempt to call upvalue 'EaExploreDungeon' (a nil value)", same thing as if I try to call a gibberish function. The function doesn't return an error if it's in the same lua file.

Hopefully it'll be smooth sailing from there, assuming I don't run into an inordinate amount of trouble making basic pop-up windows.
 
The one thing you didn't say above (that's needed) is to set VFS=true for your new file. I'm also assuming you put the include statement near the top of EaMain.lua with all the other includes. That's all it takes to make your file load. Just to make sure it's loading, add a print statement near the top (I have these in almost all files). In fact, put print statements everywhere when you are first coding something so you can see what's going on.

On UI, if you only need a popup with an image plus text (i.e., no player options). Then you can plug into an existing system used for all the Éa people and civ popups. I'll add the code line needed when I can look at mod code (it also requires image in a certain size/name format). But if you want player options or an image that isn't as big as the people portraits, you'll have to code it separately.
 
VFS=true worked perfectly. Pop-ups do seem pretty complicated, now that you mention it, but for once I have comprehensive tutorials! If you're still lurking the Ea forums, thanks, whoward!
 
Alright, dungeons are implemented. You can see any changes to the old files with a Ctrl-F for "dungeon", since mine are probably outdated.

General rules:
Spoiler :
-Dungeons can spawn on unowned, unimproved, non-resource, non-mountain land hexes. They have a 1-in-500 chance of spawning per-hex per-turn (speed-scaled), and won't appear within 3 tiles of any other dungeons. Unexplored or relatively benign dungeons have a 7% chance per-turn of spawning a barbarian, explored and relatively nasty dungeons have a 9% chance per-turn (both time-scaled, and some will spawn even more or less often). These numbers aren't really balance-tested, but hopefully they'll give the barbarians more "oomph" in the mid-game without making them too scary early-game. Dungeons currently use the Fort art defines.

-The barbarians spawned use a "baseline strength" of the strongest main-civ-owned unit in play, excluding Tree-Ents because Tree-Ents are terrifying. Barbarian strength will loosely float around the baseline. For unexplored dungeons it's a grab bag of Heldeofol, traditional barbs and Man units, for explored dungeons it's dungeon-appropriate.

-Dungeons can be explored by either a combat unit or GP, and if one of them explores while the other is on the tile they'll both count as exploring. Exploring a dungeon will traditionally let you choose between destroying the dungeon but spawning three barbs on top of you and leaving the dungeon be to spawn a more manageable trickle of barbs. This also locks in the dungeon so any future explorations will bring the same event up. Bringing a GP along will often unlock a "diplomatic" option or two like buying the inhabitants off, as well as some policy/class/tech-specific options like sending a Devout or Necromancer to deal with some undead. The combat unit is relevant for events that depend on the explorer's combat strength.

-This also includes a primitive "quest" system so you can spawn a handful of barbs, kill them and get a reward and another messagebox for your trouble. It relies pretty heavily on coercion, so it should be extensible to other events if such a thing strikes your fancy.

-The AI has no idea how to handle dungeons, but if they trip one they'll decide what option to pick by a simple flowchart-style system. Mostly how many troops they have near the dungeon.
Problems:
Spoiler :
-EaActions terrify and confuse me (why are you giving me errors about cities? I didn't say anything about cities), so at the moment a dungeon is "explored" by standing on it and ending turn. This is naturally not ideal. If you can get an EaAction working for it, just take the BeginDungeonEvent function call from EaPlots.lua. Dungeons are just tracked by an improvement.

-I'm using InitUnit to spawn units, and when I assign them to the barb player they're marked as "captured [UnitType]". They still function normally, and undead who break loose also seem to be marked as captured.

-The "recon" unit branch just seems to stand around under barbarian control, so they currently don't spawn from any dungeons.

-I couldn't work out how to change the fonts on buttons (though the main label was fine), so there are a couple places where "Anra" is spelled with normal letters.

-If one of the barbs disbands instead of being killed normally it doesn't register, and I have no idea how to make it recognize that a unit is disbanded. No idea if it's possible for barbarians to disband, but there you go.

-My unit-spawning function assumes land units, so even the occasional flying barbarian won't spawn in the mountains or water. I still can't figure out how to check the CombatType of a UnitType without having a specific unit to refer to.

-There are only 15 possible dungeons, and I'd feel more comfortable with 25 or so, but I had enough trouble coming up with this much variety. Hopefully more dungeons can be slotted in by you, me or someone else as new mechanics and units are implemented (Vampires? Vampire dungeon! Lycanthropy? Werewolf dungeon!). I also don't have any dungeons based on Barbarian GPs, so if and when Barbarian GPs have functioning AI that might be a worthwhile hook.

-It's very dependant on there only being one human player, so if two years from now you want to add multiplayer it'll take a lot of tweaking.

-I'm, uh, not all that proud of the code. It should be adequately commented, but I didn't use any console prints and I'm certain it's clumsy and inefficient in places.
I've left you a fair bit more work than I originally hoped, but these have me pretty thoroughly stumped. I may be able to plink away at some of it with advice where viable, but I'll leave that up to your judgment. As always, no hard feelings if you're burnt out or otherwise not interested in this implementation.
 

Attachments

  • Dungeons.zip
    80.9 KB · Views: 197
Top Bottom