big-brain icon indicating copy to clipboard operation
big-brain copied to clipboard

[Feature] Manual Triggering of Actions

Open chrisburnor opened this issue 2 years ago • 4 comments

The Action system in Big Brain is quite powerful. However, not all actions in a game are triggered by the AI itself. There might be traps, triggers, player input, etc. It would be very powerful to enable manual triggering of such actions. However, currently this does not seem to be possible.

An Action can be added to an actor as follows:

        let drink_action_builder = DrinkBuilder;
        drink_action_builder.attach(&mut cmd, actor_entity);

However, there is no way to replicate the logic in thinker.rs#347::

        let new_action = picked_action.1.attach(cmd, actor);
        thinker.current_action = Some((ActionEnt(new_action), picked_action.clone()));

Because thinker.current_action is private.

chrisburnor avatar Nov 29 '21 20:11 chrisburnor

The only way I can think to do this in the current API would be to force the score to 1.0 for that action. That seems suboptimal though as there is no way to guarantee that a different choice does not also have the same score. Also, a picker like FirstPastThreshold might find another action that is past the threshold as well.

Perhaps thinker.current_action could be set by a private(crate) setter and the logic in in thinker.rs#347 could be moved to Action.attach

chrisburnor avatar Nov 29 '21 20:11 chrisburnor

So I have a branch that almost does this. I added the following to thinker.rs:

+    pub fn trigger(
+        &mut self,
+        cmd: &mut Commands,
+        action_builder: Arc<dyn ActionBuilder>,
+        actor: Entity,
+    ) {
+        let new_action = action_builder.attach(cmd, actor);
+
+        let action_builder_wrapper =
+            ActionBuilderWrapper::new(action_builder.clone());
+        let new_current_action =
+            Some((ActionEnt(new_action), action_builder_wrapper.clone()));
+        self.current_action = new_current_action;
+    }

which works from exec_picked_action, but when I try to trigger it in the example, using a Player resource, I find that the Thinker entity is not the same as the entity created in init_entities

chrisburnor avatar Dec 04 '21 03:12 chrisburnor

@chrisburnor did anything ever come out of your branch? Is there anything I can do to help here?

zkat avatar Jan 08 '22 19:01 zkat

I've taken a detour to figure out how I actually want to handle actions in my game to get a sense for what manual triggering might look like. I realized that the problem was not quite well formed in my own mind. Once I finish Bevy v0.6 updates, I'll take a second look.

One thing that would help would be a better understanding of the different entities that get created and their relationships in Big-Brain. IIRC from my investigation, the brain and the action are separate entities and both of those are separate from the entity to which the Thinker builder is attached which was really confusing. I wish I could be more specific, but it was a few weeks ago and that branch is currently broken.

chrisburnor avatar Jan 11 '22 03:01 chrisburnor

working on this now. Just testing my implementation and I think it'll be ready soon :)

zkat avatar Sep 25 '22 00:09 zkat