Skip to content
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

Merged
merged 56 commits into from
Sep 25, 2017
Merged

Add water-based units #87

merged 56 commits into from
Sep 25, 2017

Conversation

tbeddy
Copy link
Contributor

@tbeddy tbeddy commented Jul 3, 2017

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.

tbeddy added 30 commits June 20, 2017 18:08
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
@tbeddy
Copy link
Contributor Author

tbeddy commented Aug 26, 2017

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?

@djwhitt
Copy link
Contributor

djwhitt commented Aug 26, 2017

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.

@tbeddy
Copy link
Contributor Author

tbeddy commented Aug 28, 2017

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
@djwhitt
Copy link
Contributor

djwhitt commented Aug 28, 2017

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.

@tbeddy
Copy link
Contributor Author

tbeddy commented Aug 28, 2017

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'?

Copy link
Contributor

@djwhitt djwhitt left a 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.

(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)))}))
Copy link
Contributor

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.

@tbeddy
Copy link
Contributor Author

tbeddy commented Aug 31, 2017

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.

@tbeddy
Copy link
Contributor Author

tbeddy commented Sep 2, 2017

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.

@djwhitt
Copy link
Contributor

djwhitt commented Sep 2, 2017

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?

@tbeddy
Copy link
Contributor Author

tbeddy commented Sep 2, 2017

The former (I think). I'm currently using this to load the :buildable-at info as :can-build

{:db/id (db/next-temp-id)
 :terrain-type/_can-build [:terrain-type/game-id-idx terrain-type-idx]
 :terrain-can-build/unit-type unit-type-eid}

If I were to only create terrain-type/_can-build...

{:db/id (db/next-temp-id)
 :terrain-type/_can-build unit-type-eid}

...wouldn't the :can-build info not be associated with a terrain-type?

@djwhitt
Copy link
Contributor

djwhitt commented Sep 7, 2017

Using the current code structure, I think this is the transaction you want:

{:db/id [:terrain-type/game-id-idx terrain-type-idx]
 :terrain-type/can-build unit-type-eid}

Or you could use a reverse reference when loading the unit-type like this:

{:db/id unit-type-eid
 ;; other attributes omitted...
 :terrain-type/_can-build (map #(->> % to-terrain-type-id (game-id-idx game-id)) (:buildable-at unit-def))}

Warning: I haven't tested either of these. 😁

@tbeddy
Copy link
Contributor Author

tbeddy commented Sep 7, 2017

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.
BTW, any suggestions for understanding Datomic/Datascript through and through? Just reading over the project docs?

@tbeddy
Copy link
Contributor Author

tbeddy commented Sep 17, 2017

Any other changes you'd like me to make?

Copy link
Contributor

@djwhitt djwhitt left a 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.

{: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))]
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tbeddy tbeddy mentioned this pull request Sep 24, 2017
@djwhitt djwhitt merged commit d5f9afe into Zetawar:develop Sep 25, 2017
@tbeddy tbeddy deleted the add-water-units branch September 25, 2017 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants