Combining the Grid based Turn Based Strategy Game with Tasks Systems

Hi there !

I am studying the excellent Turn Based Strategy Game (thank you guys i am learning a lot and it’s very clear) and I am trying to adapt it a little bit to have a Task AI mechanic on non player Units.

The goal is to have prefabs placed on the grid that under certain conditions/events increment a task list indicating these specific non player units (workers) grid positions where they will walk and play an animation after reaching their destination. The units will go on to the next task then once the animation is performed.

I am re-following the TBS course and stopping at the beginning for now at the "Single active action "chapter as I am also trying to combine it with Code Monkey’s tutorial on “Task System in Battle Royale Tycoon” which can be found here on Youtube: Task System

The debug part works for me (until 4:20), then Hugo implements it’s own Worker model and animation, that is where I failed in adapting the standard “Unit” character that we have implemented in the course.

I want to replace 2 things for now : the 2D worker and it’s movement system.

I’ve changed my interface : CM_IWorker to have the method from the TBS tutorial MoveAction “Move(GridPosition gridposition, OnActionComplete)” instead of the MoveTo(Vector 3, OnArrivedAtPosition) from the video and CodeMonkey’s animation project.

More precisely, I am trying to replace
//CM_Worker worker = CM_Worker.Create(new Vector3(500,500)); with a reference to the a Unit prefab :

namespace CM_TaskSystem {

public class CM_GameHandler : MonoBehaviour
private Unit worker;
private void Start()
worker = GetComponent < Unit > ();
CM_TaskSystem taskSystem = new CM_TaskSystem();
CM_WorkerTaskAi workerTaskAi = worker.gameObject.AddComponent<CM_WorkerTaskAi>();
the error i am getting is :
Assets/Scripts/TaskManager/CM_GameHandler.cs(25,28): error CS1503: Argument 1: cannot convert from ‘Unit’ to ‘CM_TaskSystem.CM_IWorker’

I tried to change few things, it might be because we definined the “Unit” as a protected type, if it might be the reason, how can I adapt it please ?

Could you please help me on that one :slight_smile: ?
Thank you in advance for the help !

Note: I have not touched the TBS course in a while so I’m a little rusty on its implementations

The problem is just that Setup requires an CM_IWorker type, but you are passing it a Unit which is not of that type. A quick fix is to implement CM_IWorker on the Unit, so the Unit needs the following added (this is with your change)

public class Unit : MonoBehaviour, CM_IWorker
    public void Move(GridPosition gridPosition, System.Action onActionComplete)
        // Your implementation

Now when you pass Unit to the Setup() it will be of the correct type and the error will go away.

To be honest, I don’t think the two systems really work together. The Task system is for AI that continuously want to do something. The TBS is turn based and the enemy AI only want to do things when it’s their turn. I suppose the enemies could be WaitingForNextTask when it’s not their turn and only request a new task when it is. This will change all the AI for the enemies, though. Also, this code is very different from what Hugo did in the TBS course. It’s quite obvious how his style changed from 5 years ago.

Hi !
thanks a lot bixarrio for the help !

The AI in question is for another player but not the ennemi, otherwise I agree it wouldn’t be suitable.

I tried the implementation and tried to make it work,
The error goes away but I still have a problem here that I failed to fix this weekend :

My Unit script calls the Move Action script which is separated,
I am using the CM_TaskSystem’s namespace

I do have errors now with :
Assets/Scripts/Unit.cs(6,36): error CS0535: ‘Unit’ does not implement interface member ‘CM_IWorker.Move()’

Is there something missing ?

Thanks a lot in advance for the help !
I agree Hugo has changed his coding style in 5 years and continues to share awesome content, it is sometimes difficult to combine everything I am trying to produce the missing part that adapter the kind of implementation of the task system AI and the part that he used with a standard animator and actions system in his TBS or in his Kitchen Chaos tutorial ! :slight_smile:

This is saying that the Unit must now have a method named Move with the same parameters as the Move() method defined in the CM_IWorker interface.

Unfortunately, I’m not familiar with @CodeMonkey’s Task System In Battle Royal tutorial, so I’m not entirely sure how well these two systems will be to merge together.

Merging task systems with turn-based strategy like you’re doing is really cool. Following Bixarrio’s advice to tweak the Unit class so it works with the task system sounds like a solid plan. It’s all about making sure your game pieces can handle the tasks you want them to. Your approach to mixing these elements is super interesting. Just keep playing around with it, and you’ll find the right balance.

Privacy & Terms