Zetawar / zetawar

Zetawar is a turn based tactical strategy game implemented in 100% ClojureScript.
MIT License
169 stars 14 forks source link

Repair other units #52

Closed tbeddy closed 7 years ago

tbeddy commented 7 years ago

This allows specific unit types to repair other units. Currently only the medic is able to do so. Images have been added for the medic unit-type, along with an image to highlight the border of targeted friendly units in green. Bugs include medics being unable to repair others after moving once and inconsistent tile-masking. Update: I've fixed the first bug. The tile-masking is improved, though probably not ideal.

djwhitt commented 7 years ago

The use of sets for :can-repair in data.cljs is good, but they needed to be loaded into the DataScript DB a little differently. Each item in the set should result in a datom attached to the unit type entity in the DB. The closest analog for how this should work is :unit-type/zoc-armor-types.

tbeddy commented 7 years ago

I'm not familiar with DataScript, so I'm having some trouble with this. Should I be altering the schema as defined in db.cljs?

djwhitt commented 7 years ago

Yep, attributes with cardinality > 1 need schema entries. It should look something like this: https://github.com/Zetawar/zetawar/blob/5672efd67f8b8a2a06e5e67911d83c32cc039b6f/src/cljs/zetawar/db.cljs#L56

tbeddy commented 7 years ago

Is that last commit closer?

tbeddy commented 7 years ago

On a different note, are you okay with two of the repair functions I added in game.cljs (can-be-repaired? and compatible-armor-types-for-repair?) not following the check-next-state model you use for can-repair?, can-attack?, etc.?

djwhitt commented 7 years ago

You mean should a unit be able to repair another unit regardless of what state the other unit is in? If that's the question, I'd say yes.

tbeddy commented 7 years ago

I mean should a unit have to check its state at all to be able to repair another unit.

can-be-repaired? is currently... (defn can-be-repaired? [db game unit] (< (:unit/count unit) (:game/max-count-per-unit game)))

(which doesn't use the database at all)

...instead of something like... (defn can-be-repaired? [db game unit] (try (check-can-be-repaired db game unit) true (catch :default ex false)))

...which is how most of the surrounding functions have been designed.

djwhitt commented 7 years ago

Ah, I see what you mean. It doesn't really need to check the state, but it probably should work the same way as 'check-in-range' where there is both a 'check' version that throws an exception and a '?' version that returns a value. That way you can call the 'check' version in the 'repair-other-tx' as an assertion.

tbeddy commented 7 years ago

I adapted those functions. Let me know if they look alright and anything else you'd like worked on when you have the chance.

djwhitt commented 7 years ago

I'm traveling now, so it might be a few days before I can take a look. But I'll check it out as soon as I get a chance.

djwhitt commented 7 years ago

Merged. Thanks for all your work on this! I'll get started on a review/cleanup branch soon and ping you when it's ready.

tbeddy commented 7 years ago

Cool, thanks for all your help.