-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add water-based units #87
Conversation
MobileFlak (currently unimplemented) can be built at a base or an airfield, so I'm using a set for each unit's :buildable-at.
-Only unit-types buildable at that base will be selectable. -Entire "Unit construction" section was moved in order to use a "Selection" track.
add-water-units -Also update sniper and new armored units' data
Other issues: I've revised the base? function (and every instance of it in the code base) to take the db as an argument and wrote a preliminary version of the function that uses a query, but I commented it out. Instead, I wrote a version similar to the earlier versions of base? that appears to work. Is there a reason why querying would be better, be it for efficiency, to be more idiomatic, or something else? I added a new attribute to the schema, :terrain-build/unit-type. Is that overkill? |
Regarding loading, I'm fine with using 'buildable-at' on the unit types in the definitions (not schema), and loading them using a reverse reference if that's easier. Attribute lookup is fine for 'base?' and probably preferable for performance reasons. I should have been more careful with my wording. When I said "query" I just meant we should traverse existing relationships rather than adding a flag. |
Do you mean going back to using 'buildable-at' in the unit types in the definitions, not using 'can-build' in the terrain types in the definitions, and converting the 'buildable-at' info into 'can-build', all during the setup phase? |
-Lookup ids for terrains instead of generating new ones
Yeah, that's right. I think we should use 'can-build' in the schema, but 'buildable-at' is fine in the definition and will likely make it a bit easier to load. Having 'buildable-at' in the definitions also means you don't have to modify the base terrain type attributes when adding a new unit type which seems like a nice feature. |
I realized that I was having so much trouble because I stupidly kept generating new db-ids for the terrains when I was loading 'can-build', when I could have just looked up them in the db. Thoughts on the revision I just made? 'terrain-can-build-tx' and 'build-terrains-tx' could probably be given clearer names, but I'm not sure what those should be. Would you still like me to use 'buildable-at'? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some issues with this approach that I mention below. They could be fixed, but I think things will still be simpler overall if we go with buildable-at in the the unit-type definitions.
src/cljs/zetawar/game.cljs
Outdated
(fn [unit-type-name] | ||
{:db/id (db/next-temp-id) | ||
:terrain-type/_can-build terrain-type-id | ||
:terrain-build/unit-type (e (find-by db :unit-type/id (to-unit-type-id unit-type-name)))})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terrain types should be related directly to unit types without an intermediate entity. Also, the find-by query will only work if there is a single ruleset loaded into the db. We want to be able to support multiple rulesets being loaded simultaneously.
Ah, I had no idea about the db issue. Switching back to :buildable-at makes total sense to me now. I'll get the revisions done in the next few days. |
-Retrieve :buildable-at from unit defs instead of :can-build from terrain defs -Largely modeled off of terrain-effects
I made some revisions but I don't know if they're exactly what you were looking for. I'm still using :terrain-build/unit-type (now renamed to :terrain-can-build/unit-type). Is that the intermediate entity you're referring to? Because I can't figure out to relate both the unit-type and the terrain-type only using :terrain-type/_can-build. |
Do you mean you don't understand how that relationship would work in the db or that you understand the relationship but don't understand how to structure the transaction to load it? |
The former (I think). I'm currently using this to load the :buildable-at info as :can-build
If I were to only create terrain-type/_can-build...
...wouldn't the :can-build info not be associated with a terrain-type? |
Using the current code structure, I think this is the transaction you want:
Or you could use a reverse reference when loading the unit-type like this:
Warning: I haven't tested either of these. 😁 |
Thanks. The former works. I was trying too hard to emulate the attack-strengths-tx and terrain-effects-tx functions and didn't think to make such a simple change. |
Any other changes you'd like me to make? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one minor change and then I think this is good to go.
src/cljs/zetawar/game.cljs
Outdated
{:terrain/game-pos-idx (game-pos-idx game q r) | ||
:terrain/q q | ||
:terrain/r r | ||
:terrain/type [:terrain-type/game-id-idx (game-id-idx game-id :terrain-type.id/base)] | ||
:terrain/type [:terrain-type/game-id-idx (game-id-idx game-id (keyword "terrain-type.id" base-type))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the to-terrain-type-id function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Closes #82
This is the most involved of all Elite Command unit PRs, since it involves rule changes, and will probably require some alterations.
I added a new terrain (seaport), a new armor type (naval), and three new units (cruiser, destroyer, frigate), two of which require new unit state maps (move-attack-twice, free-attack-once). All units now have a buildable-unit parameter (a set) and all terrains now have a base-type parameter (a boolean).
I significantly altered the "base?" function and the "available-unit-type-eids" track. I moved the entire "Unit construction" section in order to use other tracks that were further down in the "subs.cljs" file.
I changed the default map to include a capturable seaport for each of the two teams. We should probably port an Elite Command map or make a new one to fully take advantage of the new units.
I included two versions of base-type in the schema, both commented out currently. Though the version I have appears to run fine, the fact that I managed to sidestep using the schema seems incorrect, but I'm not sure what changes to make.