Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

TurnBased-Toolkit (TBTK)

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

  1. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Hey @songtan!

    1) Very nice work! I love this asset. Highly reccomend it! I have the same bug with the spawnUnit as mention days ago, but I can wait for the next release if it would be soon :D. Beyond this little bug, the overall project is flawless.

    2) I been trying to get for individual units to have different AP amounts per move. I enable the variable for them from the script but of course Im fighting against what seems to be the global settings or the database? My global settings are off, but I have enable 'AP per move' on set to 0. but I desired to overried with changing the amounts in the prefabs. I am not sure what else I am missing. I think it would be a great feature to have AP move amounts for each unit instead the same for all.

    If you can help, I appreciated. Thank you!
     
    Stexe likes this.
  2. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Thanks for your kind word!

    1. I'll fix that and upload an update to AssetStore within the next few days.

    2.There's no way to achieve what you want without some code modification. If you ask me, the easiest way to do it would be modify Unit.cs to bypass any check involve GameControl.UseAPToMove() entirely. Instead, just add a variable 'apCostPerMove' in Unit.cs and use that instead of using the value from GameControl.GetAPPerMove(). That way you can give individual unit different ap cost when moving. Make sense?
     
  3. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    I saw the update thanks! This asset rocks!
    I was able to simply add a boolean to the section you pointed out 'GameControl.GetAPPerMove()' since I wanted the ap to work in certain units. The code is super nice for custom edits. Great job again, thanks!
     
  4. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Oh, I see the update was not for the SpawnUnit fix - for the UI health bar to show for the spawned unit. Looking forward for when this is fix. Thanks you!
     
  5. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Ah, sorry I missed that. I'll get to it asap.
     
  6. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Just did an update. :)
     
    Stexe likes this.
  7. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Thanks, but I am now wondering if I am doing something wrong since the Health (HP) bar still does not display when a new unit is spawn from abilities.
    1. I downloaded the entire project from scratch and used the classic demo scene to test it out to make sure nothing I did interfere.
    2. I added a new ability with the settings of 'spawnunit' and chose one of the units to spawn for it.
    3. Then, I added this ability to one of the existing units in the scene.
    4. Finally, When the ability is used, the new unit is spawn but it has no Health Bar/ HUD showing.
     
  8. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    It works on my end. I just create a new scene and use the default "Reinforcement" ability. I tried it by creating a unit ability too. I haven't change any setting, everything is by default. Are you seeing any error message?
     
  9. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    It is working after all!

    I was in Unity version 2019.2 and it did not seem to work. Then, I updated to 2019.3 and it might have not been the version and it could have simply me that the new version did not properly update in the browser. So I am not actually sure if it was due to the Unity version. Most likely it was my browser.

    Thank you, it is running great now! :D Nice job!
     
  10. psONE-BubbleGUM

    psONE-BubbleGUM

    Joined:
    Jul 4, 2015
    Posts:
    2
    Hello, @songtan !
    Thank you for the great job and for such awesome toolkit! :)

    I have some issue: when I check "Generate Grid on Start" in the Grid Manager script of the GRID_MANAGER_GENERATOR object I have a couple of deployments points on the Enemy side.
    I didn't change anything in the Grid Manager script. I only changed "Unwalkable Rate" to 0 and "Obstacle Rate" to 0.1, and add a couple of new obstacles.

    1.png
     
  11. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    The deployment point on the grid persist even when you regenerate it, runtime or not. You can see any deployment point on the gird in SceneView as a cross (with color of their respective faction). To get rid of them, you need to manually clear them. The easier way would be to just use the 'Edit Grid' function in GridManager, select Node->Deployment and Clear All. Alternatively you can do it one node at a time by right-clicking on individual node.
     
    psONE-BubbleGUM likes this.
  12. adrianov

    adrianov

    Joined:
    Dec 23, 2015
    Posts:
    4
    Hi @songtan, first off, great asset! We've just started using TBTK3 to prototype our studio's next game and have found it extremely robust and perfect for our needs!

    I was wondering how I could handle spawning units onto the board at runtime? Say as an Ability, I wanted a unit to be able to spawn another unit next to itself. How could I handle that, making sure the unit spawned could be successfully added to the player/ai/faction logic so that it runs it's own logic within subsequent faction turns?
     
    Stexe likes this.
  13. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    There is already an ability that does exactly that. Look for the ability 'Reinforcement' in faction ability. It's available by default in the scene created from the drop down menu.
     
    Stexe likes this.
  14. adrianov

    adrianov

    Joined:
    Dec 23, 2015
    Posts:
    4
    Awesome, thanks!

    Also, I'm trying to limit the camera rotation but the angle clamps values in the camera control don't seem to do anything, am I missing something @songtan ?
     
  15. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Those angle clamp are for x-axis rotation (up and down). If you want clamp the angle for y-axis (left and right), you will have to make some modification on the script.
     
  16. psONE-BubbleGUM

    psONE-BubbleGUM

    Joined:
    Jul 4, 2015
    Posts:
    2
  17. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    I'm having trouble understanding how to spawn units from a cache when starting a new game, instead of just loading from one scene to another.

    Say I have an empty board and I want to spawn 3 units for Team 1 on squares 3, 9, and 12, and spawn 4 units for Team 2 on squares 42, 46, and 59.

    How can I create a function using calling

    UnitManager.GetCachedUnitList ()
    public static List<DataUnit> GetCachedUnitList(int factionIndex)

    to spawn them?

    Should I just manually place units, create a cache with

    UnitManager.CacheFaction ()
    public static void CacheFaction(int factionIndex, List<Unit> unitList)

    and then serialize that information somehow for later use to pass into the above? Or is there a better way? And how do you determine location for cache unit spawn? I don't see a parameter for that, but maybe I'm just missing something.

    Also, what do you think would be the best way to implement a check to look at all units on the board and generate effects based on that (say synergies from having X type of a unit)?

    Thanks! =)
     
  18. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Hello,

    I am having an issue with a rapair HP type ability. I have the setings as illustrated in my attached screenshot. What is happening is that the HP part works, but for some odd reason the AP also gets modified. I have the AP set to 0 - not sure what is wrong?
     

    Attached Files:

  19. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    @Stexe, unless you are working on a non gameplay scene, you shouldn't have to deal with GetCachedUnitList() or CacheFaction(). You simply check the loadFromCache and SaveToCache option for the faction in UnitManager. When loadFromCache is checked, the loaded unit will be used to override the StartingUnitList. Fyi StartingUnitList is the units you manually deploy (but of course you can have them auto-deployed).

    So if you want to spawn 3 units for Team 1 on squares 3, 9, and 12. Simply set square 3, 9, 12 as the deployment node for team1.

    As for how you have units to start with, you can either start with another TBTK scene and check the SaveToCache option for the factions. The units left at the end of the game will be cached as the starting unit for the next TBTK scene. If you are loading from a custom scene, then you will need to call UnitManager.CacheFaction() before you start loading. It's very simple. Something like this would work.

    Code (CSharp):
    1. public List<Unit> unitList=new List<Unit>();
    2.  
    3. void LoadGamePlayScene(){
    4.     UnitManager.CacheFaction(0, unitList);
    5.  
    6.     //Load scene
    7. }


    @nlv22, Thank you for letting me know. It's a bug. You can fix it by changing line802 of Unit.cs to ap=Mathf.Min(ap+srcAbility.GetRandAPModifier(), GetFullAP());
     
  20. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    What if I am working from a non-gameplay scene? The idea is that players will send an input, then once inputs are accepted, the scene would load with the selected units from the input (such as from a controller).

    Is there a way to set deployment nodes and starting spawn units through a script? And is there a way to have unit 1 spawn on square 3, unit 2 spawn on square 9, and unit 3 spawn on square 12 instead of it being randomly where they spawn?

    I mean, I guess I could have like a dozen different scenes and depending on player input it loads the scene with the units already placed, caches them, and then loads another scene based on the other player's input, caches them, and then loads into a final scene with the cached units... that seems like a clunky way to do it though?
     
  21. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I don't understand what you mean specifically by player input. Are they selecting the scene to play? Or are they selecting the unit to start with? I take it it's the later? So this is how the snippet of code I send you intend to work. The unitList are by no mean fixed. You call CacheFaction() before loading the gameplayer scene but before that, in that non-gameplay scene, you would have the UI and code for the player to select what unit they want to use. Whatever unit(s) the player have selected, just put it into the unitList and pass it to CacheFaction().

    Please refer to the scene Demo_Persistent_PreGame and the script Demo_Persistent_PreGame.cs to see exactly what I mean.

    You can remove the randomness in the deployment by removing the line that do the randomization in the function DeployUnit() in UnitManager.cs, in line699. Just set rand=0 then the deployment will always follow a fix order. First unit to first deployment node, second unit to second deployment node and so on.
     
    Stexe likes this.
  22. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Awesome, yeah that generally solved it. Some minor UI errors I'm getting but I can figure that out later. Worked for what I needed it to do, thanks!

    How would you assign deployment nodes through scripts? Say I turn off random deployment and have a 4x8 area and want certain units to spawn at certain squares.

    Would I have the main game have 0 deployment nodes and then create the deployment nodes through a script and with the passed cache units in a certain order to ensure first unit goes to first node and so on. Or should I pass 32 units, with all 4x8 squares set as deployment nodes, and for the spaces I don't want want a unit somehow pass a "non-unit" or something? Sorry if that isn't clear, I can elaborate more if needed.
     
  23. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Unfortunately you can't have a null element in your unit list. So you can't pass a list with 32 elements with some of them being empty. I guess in this case, you will have to find a way to somehow match the unit you have into their intended slot. Maybe an additional identifier on the nodes to specify what kind of unit they will take for deployment and place your unit according to that. It goes without saying you will have to modify the DeployUnit() to do that. I'm afraid there's no way to do this without modify the existing coding.
     
    Stexe likes this.
  24. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Ah, gotcha. I guess I can maybe look at the code and try to add a line where if there is a null element (or any element that isn't a unit) it simply iterates to the next item in the list and increments to the next deployment node.

    Shame there is no way to easily create deployment nodes through scripts and has to be done in-editor. Thanks for your help though.
     
  25. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Thanks for the quick reply. I changed line 802, but the issue is still there. The AP that I am seeing is the 'Attribute on Impact' set to Positive. It seems to put the AP to full no matter what even though it reads at 0 Min and Max. I wonder if it needs one addtional change? :D
     
  26. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I made the change and everything seems to be working correctly now. Maybe send me your Unit.cs and Ability.cs so I can check to make sure.
     
  27. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Thanks Songtan, I DM you with them.
     
  28. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    I figured out how to do it finally and implemented it. Huzzah!

    I basically created a 32 element array populated by a "null" unit, added the unit I actually wanted to deploy in place of the null unit at the specific array element where I want it to spawn, then have it skip deployment for any null unit.

    One step down like 100 more to go. =)
     
  29. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    @nlv22, It seems like you have modified your Unit.cs. So my line802 is no longer your line802. Try change your line802 back to ap-=srcAbility.GetRandAPModifier(); and change line807 to ap=Mathf.Min(ap+srcAbility.GetRandAPModifier(), GetFullAP()); instead.
     
    Stexe likes this.
  30. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Yes, now it works! Yeah, my bad, I did edit my code and forgot about it - my line 802 was my 807. Now I see were 'HP" was in 807.

    Great, thanks for the super quick replies! :cool::D
     
  31. JohnBlake

    JohnBlake

    Joined:
    Jul 18, 2017
    Posts:
    2
    Hello, I would like to know if it is possible to limit the movement of the units as if it were a game of chess.

    Thanks
     
  32. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I'm afraid not. The only limitation you can apply to unit movement right now the range. If you want to limit specific unit movement to a specific pattern. You will have to do some modification. Depends on what you need, some of this movement pattern (like castle or bishop in chess) can be relatively easy and straight-forward to implement.
     
  33. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Hey songtan,

    In one of the scene examples I notice that the AI/enemy units collect items. In my build it has never happen. I am wondering how it happens that AIs can collect items. Is there a way I can increase that from occuring more often, and in my case, for it to happen? Thanks! :D
     
  34. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    I'm trying to save a list of Units in a file that I can then "load" into Demo_Persistant_PreGame so that the units are cached and then loaded in the main cache scene properly.

    Any idea on where I should start with that?
     
  35. sisko89

    sisko89

    Joined:
    Mar 8, 2019
    Posts:
    20
    Hi songtan,
    I realised I never replied after you fixed those bugs I found weeks ago... so just wanted to say thank you for the patches and thank you for all the hard work you keep doing on this script. You are doing a great contribution to the turn based games industry, keep up the good work!
     
  36. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Sorry all for not responding. I missed the notification again.

    @nlv22, The AI is never intended to collect item in the first place. It just some happy accident that they do move into nodes with item and the item trigger code doesn't distinguish AI unit from player unit. I'm afraid it's not possible to adjust that without modifying the existing AI code.

    @Stexe, You can use the function UnitManager.CacheFaction(factionID, squadList);. With factionID being the factionID set in Demo_Persistent_PreGame, and squadList being the list of the unit prefabs you want. You can either call this in prior scene, or any Awake() function in the same scene.

    @sisko89, Thank you!
     
  37. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    I was more talking about List serialization on the Unit type. Just decided to update to Unity 2019.3 since they have Generic List Serialization now. Hopefully this will work, so far it seems promising.
     
  38. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I'm sorry. I missed read your question. I haven't try it so I'm not sure if it would really work. I'm a bit doubtful if I'm honest. Serializing data is not the same as serializing prefab assignment.
     
  39. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    Yeah, that's the issue I had before, but apparently (?) there's a way to do that now? If you have any thoughts on how you'd implement that I'd love to hear it though.
     
  40. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    It's not how to implement it but how you want it implemented. Serialize data to a file is a pretty straight-forward matter. It's what you want and where to serialize from where and how you deploy the data once you deserialize it.

    The key thing here is we don't know if it will work. You can try it out though. Just use a simple read/write to file code and try to serialize class with prefab assignment and see if it work.
     
    Stexe likes this.
  41. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    191
    I tried something like that before but it ended up serializing the actual Unit data itself instead of the reference. When I made changes to the Unit prefabs they weren't reflected in the saved data... and worse yet it somehow would override the saved prefab data when using the saved files. Not sure how that happened. Going to try some more tests since I need to figure this out (and the NFC hookups) in the next week for my bigger project.

    Anyway, thanks for your help so far. =)
     
  42. ouraf

    ouraf

    Joined:
    Sep 4, 2019
    Posts:
    14
    the last time a similar question was answered was in 2016, so it's plausible to question again:

    Does the current iteration of the engine supports unitis bigger than one grid space? like a 2x2 giant or something like that
     
  43. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    Very sorry but I'm afraid that is still not supported.
     
  44. sisko89

    sisko89

    Joined:
    Mar 8, 2019
    Posts:
    20
    Hi, I think I found a bug: if an AI controlled unit can attack twice per turn, AI will only attack once. I made sure they had enough AP and everything, but they never use the second attack.
    I tried to fix it myself in AIRoutineUnit but no luck so far... any tips?
    Thanks!
     
    Stexe likes this.
  45. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    You are right. The AI don't use all their available action atm. I'll get this fixed and do an update asap.
     
    Stexe likes this.
  46. qazik123

    qazik123

    Joined:
    Jan 30, 2020
    Posts:
    6
    Hello,
    it is possible to make the "half" wall passable for certain types of units (and not for others)? I mean deactivate the wall functionality somehow if a certain unit type is selected.
    When it is not possible, it is hard to change code to do this? What would be the best way?
    Thanks.
     
  47. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    This is not supported by default. However if you are a competent coder I don't think it's too difficult to make the required modification. In Node class in Node&Wall.cs, there's a function IsBlocked(). It's used to determined if access to a neighbouring node is blocked to a unit. You can modify the checking to include the type of wall in the way and the unit trying to access it. That should be it if I remember correctly.
     
  48. qazik123

    qazik123

    Joined:
    Jan 30, 2020
    Posts:
    6
    Hi Songtan,

    I found this old post about flanking feature in the game, but in version 3.1f4 I can't find this option. Now it works differently, or does this feature completely disappear?

    Second, I found the option in the unit editor "Can move past Obs.:"
    and in the change log
    v3.1
    - added option for units to move pass between nodes with unit or obstacle

    So it seems that solved my request from 4:57 AM.
     
  49. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,738
    I've decided to discard that feature. The thing is I just can't figure out a clean and intuitive way to allow the player to adjust the unit facing. And I figure that it doesn't quite make sense if the game grant an attack bonus when attacking from certain direction but there's no way for the player to adjust the unit facing.
     
  50. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    52
    @songtan Hi, what would be the best way to expand on the stock AI, I'm finding units get stuck fairly easily.

    It seems that the AI pathfinding range is pretty short when negotiating obstacles/unwalkable tiles , I would like to improve this if possible.

    EDIT: One other thing, when using obstacles I would like to be able to set them as unwalkable as well to stop the curser from entering those hexagons.
     
    Last edited: Apr 5, 2020
unityunity