Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Micro Input Milestone 1 implementation #49

Merged
merged 29 commits into from
Apr 13, 2021

Conversation

Winsalot
Copy link
Collaborator

@Winsalot Winsalot commented Feb 9, 2021

Implementation of features discussed in #38

Current progress (copy-pasted from #38 )

  1. Preparation of environment:
  • Resource to set game mode. Options could be "default" and "micro-input". Should be change-able in-game and some systems (eg. Creep spawner, simple ai movement) should check it's value before running. Reason is that if micro-input is to be a separate module, then there will be a lot of systems that will be relevant only to this module, and vice versa.

  • Custom game start/map with no creep spawning and all units idle. Further steps would add unit orders, therefore units should not do anything before any order is given.

  • Add mouse support and cursor to the font-end. (Kinda works, but has some serious issues)

  1. Unit selection:
  • Decide on architecture. What part of the game stores what units are selected? Is this information stored in the unit itself, or are selected entity id's stored in a separate container?
  • Implement selection of single unit
  • Implement deselect by clicking empty space or selecting another unit.
  • Multiple unit selection.
  • Auto control groups (automatically assigned control group for each leader and their summons if available).
  1. Unit orders and unit AI:
  • OrderQueue component and UnitOrder type.
  • Review unit AI (units should behave in different ways depending on what their current Order is)
  • Implement idle order behaviour. Basically unit behaviour when no active UnitOrder is present. At current stage it would be: unit stands in place, moves and attacks enemy if it enters aggression radius.
  • Implement M-move order.
  • Implement stop order (clears OrderQueue of all orders, sets current order to idle)
  • Implement Hold position order.
  • Implement A-move order.
  • Implement focus-fire/follow order

@Winsalot
Copy link
Collaborator Author

Winsalot commented Mar 25, 2021

The PR is almost done. The only thing left to do is to fixing the rendering of cursor.

Therefore I invite to try out the changes by compiling and running the branch.

Micro-input "game mode" is not enabled by default. Therefore to see all the functionality you can do the following:

  1. cargo run to start the game.
  2. Once it starts press i. This will switch the game mode from "shotcaller" to "micro-input".
  3. You will notice that all units will start behaving differently. This is due to couple of factors:
  • All units have no orders (aka. idle order). This means that they stand in place unless an enemy enters their aggro range. Then they attack.
  • Additionally, currently shotcaller has no unit-unit collisions, and as a result units often stack on top of each other. To adress this, I made stacked units spread out when idle.
  • This automatic spreading-out behavior can sometimes place units in aggro range of enemies. After that violence happens.
  1. Next point to pay attention to is Input State:
  • De: Default state. Clicking on units will select them (yes, you can select and control enemy units too). Clicking empty tile will deselect all units. Switch back to this state by pressing "Esc" key.
  • Mo: Movement order state. Activated by pressing "m" key. Once in this state, clicking a tile give all selected units "M-Move" order to that position. If target of order is another unit, then "follow" order is given.
  • At: attack move state. Activate by pressing "a". In this state mouse input will give attack-move orders to selected units.
  1. Some orders can be given regardless of current input state:
  • Hold position. Key "h". Units will stop and not move even if enemies are nearby.
  • Stop order. Key "s". Current orders of selected units get cleared giving them "idle order". What this order does was discussed in point 3.
  • Auto-control groups. Activated by pressing keys 1-5. Will deselect all units and select a corresponding leader from your team.

Some things to keep in mind:

  • Auto control groups should also select all summoned units of corresponding leader. This functionality can be implemented later after implementing a consistent logic/architecture for summoning.
  • Anti stacking spread out behavior performs a grid-search to find if any other units occupy same tile. Ideally this should be optimized using some space partitioning algorithm to find all entities in some area without iterating over every entity in the game. But this is beyond the scope of this PR.
  • Current PR supports units with multiple queued orders. However, orders cannot be queued in-game because of limitations in input support.
  • It might seem like input is quite awkward with having to manually switch between input states. I am aware of this and I implemented it like this intentionally. Reason is that currently input is quite limited in shotcaller (eg. right-clicks are not supported, some keys like shift or control are not directly supported). This is also beyond the scope of this PR.
  • It is also easy to notice, that in-game cursor lags behind actual mouse position. I believe that this is caused by built-in latency. In my opinion this should be addressed eventually, by applying built-in latency only to gameplay, but not UI and input.

@Winsalot Winsalot marked this pull request as ready for review April 4, 2021 15:11
Conflicts:
	Cargo.lock
	Cargo.toml
	assets/keymap.yaml
	src/events.rs
	src/main.rs
@erlend-sh erlend-sh requested a review from AnneKitsune April 4, 2021 19:05
@erlend-sh
Copy link
Contributor

@Jojolepro I'm fine with merging this even with

Kinda works, but has some serious issues

As long as computer-players can give input, we're good for now! (yes, same line as #47 )

Copy link
Contributor

@AnneKitsune AnneKitsune left a comment

Choose a reason for hiding this comment

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

Nice features!

I just have a few nitpicks (mostly typos 😄 )

Also, in the future it might be a good idea to create a new State with a different dispatcher. This will avoid adding the match GameMode at the start of the different systems.

.gitignore Outdated Show resolved Hide resolved
src/components.rs Outdated Show resolved Hide resolved
src/resources.rs Show resolved Hide resolved
src/systems/amove_order.rs Outdated Show resolved Hide resolved
src/systems/holdpos_order.rs Outdated Show resolved Hide resolved
src/systems/idle_order.rs Outdated Show resolved Hide resolved
src/systems/idle_order.rs Outdated Show resolved Hide resolved
src/systems/unit_selection.rs Outdated Show resolved Hide resolved
src/systems/unit_selection.rs Outdated Show resolved Hide resolved
src/systems/update_mouse_events.rs Outdated Show resolved Hide resolved
@AnneKitsune AnneKitsune merged commit 9af271f into spicylobstergames:master Apr 13, 2021
@AnneKitsune
Copy link
Contributor

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants