# TurnBased-Toolkit (TBTK)

Discussion in 'Assets and Asset Store' started by Song_Tan, Aug 11, 2013.

1. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Exactly! Thanks for your well-articulated input. Couldn't have put it better myself.

Basically, it's a huge undertaking. here's a lot of issues that affect almost every aspect of the framework, that I need to solve in order to get this working. Honestly, I don't have the answer yet to some of these issues.

2. ### Stexe

Joined:
Feb 2, 2014
Posts:
217
The easiest system would be to just have a single unit occupy multiple spaces and if any of the spaces are hit then the core unit is hit. Likewise, each space can be used for determining line of sight and other things for the unit (I'd assume you'd loop through each space, find the most favorable space and use that as the origin). When the unit moves it is treated the same as other units -- either it requires a clear path for every movement (if units block movement for other units) or completely clear location for ending its movement (if units don't block movement). And all "large units" are perfect squares. Not sure how you could easily do it with hexes without it complicating the matter hugely due to rotational issues. The article the other person shared shows just how complex it can get.

Even that is probably a lot of work, but that seems like a reasonable starting spot for others to iterate on. Couldn't imagine expanding it much behind that due to the huge number of edge cases.

3. ### Tarrasque

Joined:
Jan 5, 2015
Posts:
21
I found this discussion on the subject of big creatures:

https://www.reddit.com/r/rogueliked...nding_for_multitiled_creatures_with_dijkstra/

So I think the best way to go would be using only rectangular shapes (1x2, 2x2, 2x3, 3x3) and finding all the positions where creature can be positioned. I could probably survive with only 2x2 for boss monsters. Also, all the tiles that creature occupies would be valid for hitting the creature. I probably will not be able to figure this out, so I would appreciate some advice if anyone else is able to solve this.

Btw, here is a small trailer for my game if anyone is interested. That "coming soon" at the end probably still means few years though..

4. ### Stexe

Joined:
Feb 2, 2014
Posts:
217
Rectangular shapes are problematic due to rotation and other spacing constraints. 2x2 or 3x3 or so on I could understand, but the complexity starts to become exponentially difficult with units that are not perfect squares.

5. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65
Hi @songtan Found a strange issue with the camera, basically the main camera won't render anything from the tbtk unless "everything" is set in the culling mask.

So I've added a layer for icons in a mini map however can't actually mask them from the main camera without losing the units/grid indicators etc etc.

Checked with a fresh build (although not the very latest one) and still present.

Last edited: Sep 22, 2020
6. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Just tested it on my working project and a fresh import on Unity2019. It's working fine for me. In fact, by default the camera doesn't use 'everything' for its culling mask. Layer30 is omitted for invisible object hidden in fog-of-war.

7. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65

Fresh install and project. Added a new layer "testlayer" and unless it is ticked, this is what happens.

With the new layer ticked it works fine.

8. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I see. You will need to name all your layers. Or at least, the layers that are used for TBTK. These are the layers in question:

25: Terrain
27: CoverHalf
28: CoverFull
29: Node
30: Invisible
31: Unit​

Last edited: Sep 22, 2020
wrackz01, Stexe and Liberation85 like this.
9. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65
Thanks Songtan, works a treat!

10. ### sisko89

Joined:
Mar 8, 2019
Posts:
20
Hi Songtan,

In the 3.1.1 patch you added this fix:
- Fixed a bug where the game would break when a unit moving through a node occupied by other unit

Could you please send me the code for that fix only? I don't want to apply the whole patch because I made a lot of customizations to the code already...
Thanks a lot!

11. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Honestly I can't quite remember the exact change I've made for the fix, only that it's some where in Unit.cs, MoveRoutine(). You can download the latest version and check against that function. Alternatively you can email me your Unit.cs and I can give it a look.

12. ### dansyrotyn

Joined:
Oct 16, 2012
Posts:
14
@songtan
Hi! I have found an error when You are creating new ability and trying to setup it to unit, there will be a bug with the ability name in the list

The problem is caused with
AbilityUDB.cs
public static string[] label;
which is not updated

Fix:
go to AbilityEditorWindow.cs
then put this code into OnGUI ()
``````
if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save"))
{
AbilityUDB.UpdateLabel();
AbilityFDB.UpdateLabel();

GUI.FocusControl(null);
TBE.SetDirty();
}
``````

it will update the labels list

Last edited: Oct 9, 2020
13. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Thanks for feedback. I'll get it fixed.

For anyone who are wondering, this is just an editor bug for displaying. It shouldn't affect the game in anyway.

14. ### TCabeca

Joined:
Aug 30, 2013
Posts:
1

I have an error using the unity URP and in the game scene there are no images of the project.

Assertion failed on expression: 'task.rasterData.vertexBuffer == NULL'
UnityEngine.GUIUtility: ProcessEvent (Int32, IntPtr, Boolean &)

File size:
54 KB
Views:
307
15. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
The art-assets used in this framework doesn't support URP or HDRP. You will have to use a normal 3D setting or your own URP compatible assets.

16. ### dansyrotyn

Joined:
Oct 16, 2012
Posts:
14
Look likes method HasMoved of Unit.cs is buggy if EndMoveAfterAttack is off in GameControl and should be rewritten to

Code (CSharp):
1.         public bool HasMoved() { return (moveThisTurn) > 0; }

17. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I should have named the method better. It's not a bug. The purpose of that method is to check if the unit has taken any action, not just movement. I'll address that in future update.

18. ### dansyrotyn

Joined:
Oct 16, 2012
Posts:
14
EndMoveAfterAttack does not work correctly if is off

19. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
How so? Do you have a specific scenario when it's 'off'? It's working for me as far as I can tell.

20. ### dansyrotyn

Joined:
Oct 16, 2012
Posts:
14
There are some editor errors with UIHPOverlayItem class which is derived from Monobehaviour and should be stored in separate file
There are much more classes which are stored in one file like Faction in UnitManager etc (though Faction does not derives from mono)

21. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
While MonoBehaviour class needs in a file of their own for them to be added to a game-object and have their public variable displayed in Inspector, not being in a file of their own won't stop them from running correctly. UIHPOverlayItem is a special case where it's added to a game-object in runtime, not by user. And there's no reason for user to do that or edit the variable on the script instance added to a game-object. It's a bit unconventional but I wouldn't say it's an error. It's just my preference to group it with UIOverlayUnit in the same file for easier access and editing.

The rest of the class which are not stored in their own files are done so for the similar reason.

22. ### dansyrotyn

Joined:
Oct 16, 2012
Posts:
14
Method IsAvailable() of Ability is returning int value which is nondocumented and contrintuitive to understand. It would be better to create special enum for this method. What does they mean?

Code (CSharp):
1.         public int IsAvailable(){
2.             if(currentCD>0) return 1;
3.             if(HasUseLimit() && GetUseRemain()<=0) return 2;
4.
5.             if(isUnitAbility){
6.                 if(srcUnit.AbilityDisabled()) return 3;
7.                 if(srcUnit.ap<GetAPCost()) return 4;
8.                 if(srcUnit.GetAbilityRemain()<abilityCost) return 5;
9.                 if(srcUnit.GetMoveRemain()<moveCost || srcUnit.GetAttackRemain()<attackCost) return 6;
10.             }
11.
12. als
13.             //check available target?
14.             return 0;
15.         }
Also it would make more sense from design perspective to implement each type of Ability as separate classes
Within current implementation every ability is containing same field and it is much harder to add new abilities

Last edited: Oct 11, 2020

Joined:
Oct 9, 2019
Posts:
4
Chipping in a +1 on large entities as a feature request, even if they're restricted to regular square dimensions. Entity size is a parameter close to the heart of my project's design and no grid-based asset like this seems to support it, for reasons outlined earlier in the thread.

24. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
@dansyrotyn, sorry about the confusion. I'll see what I can do about it. For now, when it return 0, the ability is available. As for the rest of the value being returned (1, 2, 3, 4, 5, 6), each one of them corresponding to a specific reason why the ability aren't available.

I don't see why ability should be separate to individual class based on the type. Yes there are a lot of variables and not everyone of them is used in every type but most of them are shared by multiple types.

@redtroubadour, I'm not sure what you are referring to? Is it the entity component system? If yes, I don't think it's possible.

Joined:
Oct 9, 2019
Posts:
4
Square grid. Units occupying more than one square. Viable?

26. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Unit that occupy multiple tiles are not supported I'm afraid.

Last edited: Oct 30, 2020

Joined:
Oct 9, 2019
Posts:
4
What are the technical barriers to implementing them? I can't find an asset that supports them off-the-shelf.

28. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Quite a few. Path-finding is first that comes to mind. A generic path-finding algorithm will not work in this case. Then there's there are a lots of little things when it comes to game logic, presentation and user interaction. When you have unit with different foot-print, the logic that determine and visualizing what tiles they occupy, where they can move to, what they can attack, or what unit can attack them is more complicated than a system where all units has the same foot-print.

On top of that and in TBTK specifically where almost everything can be customized, I expect the bigger unit is not limited to only one size. You can have unit that occupy 2x2 tiles, 3x3 tiles, 2x3 tiles.Then there's hex grid counterpart. It gets really complex.

29. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65
@songtan Got abit of a question regarding Ap.

When I set an ability to use Ap, it always cost double of what I've inputted, which is fine.. however if the unit only has 15 ap remaining and the ability cost 30 ap, then the units ap goes to -15. I'd rather the unit was not able to use the ability until its ap had been replenished and was equal to the amount required by the ability.

Any ideas where to go delving to sort this?

EDIT: I've done this "if(srcUnit.ap<GetAPCost()*2) return 4;" but feel that might be a bit of bodge.

Last edited: Nov 14, 2020
30. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
My apology for this obvious bug that somehow hasn't been picked up. You can fix it by removing the line ap-=ability.apCost; in UseAbilityRoutine() in Unit.cs (around line-513).

31. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65
Also, 1 other question. If I wanted to use the overwatch ability code without actually making it an ability how would I get HasOverwatch(){ return activeEffectMod.overwatch; } to return true without it involving abilities?

I am planning on having the overwatch an option on the hud, rather than an ability, as they are used for other things.

Oh and thanks for that, I did wonder.. seemed a bit strange

32. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I think it would be easier if you just add a variable on the unit and by pass the effect system. Like this:
Code (csharp):
1. public bool overwatching;
2. public bool HasOverwatch(){ return activeEffectMod.overwatch || overwatching; }
Then you can activate overwatch on a unit by just setting overwatching to true.

33. ### originzavros

Joined:
Jan 21, 2020
Posts:
5
Hey @songtan
I seem to have a problem with the default attack range of units.
No matter what I set it too, in runtime it gets set to 9. my tbtk version is 3.1 f3
I've checked to make sure theres no mult or mod on the range. I'm not sure where else the default range is pulled or modified outside of Unit.cs and GridManager.cs
Outside of that problem, is there a generic way to disable the default attack targeting for players? I see I can stop it from making a target list under GridManager's GetAttackableList() but that also stops the ai from putting together a target list.

I've also noticed a bug with auto deploy where units occasionally deploy on top of each other.

34. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I don't have a problem with the range being reset. Have you tried any of the example scene or just the default scene created from the drop down menu? Are the units range being set to 9 too in those scene? I suspect what happen is you have somehow left a XCom.cs scene modifier script in your scene.

I'm not sure what do you mean by 'disable default targeting'? To stop the unit from targeting certain unit. Or don't attack at all? If the latter, simply set the unit attack range to zero. If the former, you will have to do some code modification. What I would do is add the disabled target reference on the unit prefab and pass that information to GridManager.GetAttackableList() and have the function to ignore the passed unit.

I can't replicate the bug with deployment if there's one. If it happen in your scene, can you get a screen-shot it and send it to me? With more context maybe I can see what's wrong.

35. ### originzavros

Joined:
Jan 21, 2020
Posts:
5
Ah, there was the modifier script hanging around, perfect at least that was easy.

The default attack for player units is what I wanted to disable so it looks like setting it to 0 range works.

This vid shows units deploying on top of each other with auto deploy. It's not consistent but it can happen to either faction's deployment.

36. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I run some tests and check the code and everything I can think of. I can't replicate it and I just don't see how this is possible. The only plausible explanation is somehow you got two nodes (or even grid?) stack on top of each other.

Can you try the following and let me know how it turns out:
• Reduce the deployment node to only 3. Since you have 4 units this will force them to stack if somehow your code allows it. If we can get to a point where we can reliably reproduce this, then I can find out what's wrong.
• Regenerate the grid and see if the problem persists. This should clear out any fault your current grid might have.
• Test it with the example scene (or the default scene created from the drop down menu) and see if this happens.

37. ### sisko89

Joined:
Mar 8, 2019
Posts:
20
Hi Songtan,
I'm having an issue that whenever I add new variables to the Unit class all units get removed from the database and I have to add them again one by one.
I didn't have this problem before so it must be because of some of the changes I've been doing, it's not a bug from your asset, but anyway can you think of anything that could be causing something like this? I checked the unit database script but coudn't find anything relevant.
Please note I'm not using any of the custom editors (I do everything directly in unity's defaut inspector), but I still rely on the database.
Thanks a lot

38. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Nothing comes to mind to be honest. If you only do something simple like adding variable in Unit class, it shouldn't break anything. I do this all the time myself.

What changes have you made? Have you make any changes to UnitDB.cs or any of the editor scripts?

39. ### originzavros

Joined:
Jan 21, 2020
Posts:
5
• with only 3 dep. nodes they definitely stack
• regenerating the grid has the same problem unfortunately
• the example scene also does it
Another question, I'm looking to modify unit attacks. I see there are functions to handle the results of an attack in Unit.cs but I'm not sure where to find the actual logic that determines if an attack hits and how much dmg its doing.

I see references to an attack class like this but not sure where to find it :
Attack attack=new Attack(srcUnit, this, null, isCounter, isOverwatch)

40. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I think something must be wrong with your scripts. Have you modified it? If not, I suggest you update to latest. Otherwise, I'll have to look at your scripts to find out what's wrong. Can you send them to me?

The logic and calculation of an attack is done in Attack.cs.

41. ### originzavros

Joined:
Jan 21, 2020
Posts:
5
I've modified parts of the project but I don't think I've touched anything to do with deploying models in UnitManager. I'll pull a newer version and see if I'm getting the same thing and diff the files for changes.

I must be blind, I even looked for an Attack script but just didn't see it sitting there with everything else.

42. ### originzavros

Joined:
Jan 21, 2020
Posts:
5
@songtan
I figured out the auto Deployment problem.
GetDeploymentNode() in GridManager.cs was adding the same deployment node to the list twice because it's making 2 passes over the grid nodes. It needs a line like this before it adds the node to prevent doubling up:
if (list.Contains(grid[x][z])) { continue; }

DeployUnit() in UnitManager.cs was randomly picking that same node twice because the list had duplicates, and it uses PlaceUnit() so it just puts it there without checking if something is in that spot.

I'm not sure how the most recent version of TBTK(3.1.3) was not stacking units as the GridManager files were not really different when I diff'd them, but I wasn't having the auto deployment problem. Maybe it's catching it somewhere else?

I've found another bug or I might be doing this wrong.
I've made my own collectible and added it to the database/collectible editor. When I put collectibles on the map using the grid_manager_generator, they work fine until I save my unity project, then they become unwalkable nodes and I can't remove them from the grid with the editor, forcing me to re-generate the grid.
https://ibb.co/gVTv658
Forum's having problems embedding this, here's the link.

I tested it some using a new project and the most recent unity + tbtk versions. I can consistently get it to do this if I edit the collectible in the collectible editor while I have the same type of collectible placed on the map with the grid editor.

That said, there's a lot of sweet updates I want to add from the newer version to my version. It didn't look like Unity has any merge tools, is there one you would recommend for merging unity scripts?

43. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
There's no need for a check to see if a node is already in a list as the function is simply looping through the grid's node one by one. There shouldn't be any duplicate node. If there's is, then the problem lies somewhere else, probably when generating and setting up the grid. And the problem probably doesn't stop at deployment. I would suggest you to check your GridGenerator.cs.

About the second bug. I'm not sure where that come from. I can replicate it but so far I've been struggling to find out what exactly cause it. I'll need some time to on this. Thanks for bring it to my attention tho.

I'm not sure what's the best way to merge the script. Version control comes to mind but I'm not really familiar with it so I have no idea how to actually do it.

44. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Question for Mac user: Have you ever experience any problem editing the grid? I have someone complaining on the review saying that grid editing does not work on Mac. I myself doesn't have a Mac so I just want to make sure if this has been a thing.

45. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65
@songtan I don't own a mac so can't help with that, however I have noticed that obstacles are very hard to delete after placing them and exiting the grid manager edit mode. Latest version, however I think this has been around for a while.

46. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Thanks for your feedback. You mean deleting the obstacle manually without using the Edit mode in GridManager? Can you elaborate in what way they are hard to delete?

47. ### Liberation85

Joined:
Apr 16, 2019
Posts:
65
@songtan

Sorry, I meant in edit mode in GridManager, right clicking works for everything else flawless but multiple obstacles (full or half) in a line or a shape, and you won't be able to delete most of them.

48. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
I see. I'll try it myself and see if I can figure out what's wrong. Thanks.

49. ### Jor_Brando

Joined:
Jan 24, 2021
Posts:
4
Hello, sir.

Is there a way to make it so that, even if you have a total of six, you can only move 2 units at a time (and not all six) during each of your turns, then your turn ends?

Thank you for all your wonderful work on this asset.

50. ### Song_Tan

Joined:
Apr 9, 2011
Posts:
2,993
Sorry for the slow respond.

The answer to your question is yes. Just enable the 'Enable Unit-Limit/Turn' option in GameControl and specify the limit.