User Tools

Site Tools


preview

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
preview [2019/10/02 15:56] polymorphgamespreview [2020/04/22 11:50] vjraymon
Line 1: Line 1:
-====== Preview Modding Documentation for Foundation 1.4 ======+====== Custom component: how to compute ground or water elevation ====== 
 +Since 1.5, Foundation allows to mod Custom component and links it to a fbx (see Exemple02)
  
-:!: Please do not upload mods for Foundation 1.4 to mod.io before the official release of those modding features, since it would make your mod visible to all players, and they won't be able to play it :!:+The following LUA code computes and returns the global Y elevation of water from a global position:
  
-===== How to Access 1.4 Preview ? ===== +    function MY_CUSTOM_COMPONENT:computeWaterElevation(_globalPosition) 
-Contact developer on our [[https://discord.gg/foundation|discord server]].+        local raycastResult {} 
 +      
 +        -- Raycast from the _globalPosition + 1000 
 +        -- to _globalPosition - 1000 
 +        -- only on objects with a WATER flag 
 +        local FromPosition { _globalPosition[1], _globalPosition[2]+1000, _globalPosition[3] } 
 +        local ToPosition { _globalPosition[1], _globalPosition[2]-1000, _globalPosition[3] } 
 +        if not self:getLevel():rayCast(FromPosition, 
 +                                       ToPosition, 
 +                                       raycastResult, 
 +                                       2 ^ OBJECT_FLAG.WATER:toNumber()) 
 +        then 
 +            MyMod:logWarning("MY_CUSTOM_COMPONENT: Water not found on the vertical of " 
 +                          .. tostring(_globalPosition)) 
 +            return _globalPosition[2] 
 +        else 
 +            return raycastResult["Position"][2] 
 +        end 
 +    end
  
-===== Generated Documentation ===== +You can do the same with the ground by replacing OBJECT_FLAG.WATER by OBJECT_FLAG.GROUND
-  * [[preview:api|API]] +
-  * [[preview:assets|Assets]] +
-  * [[api:mod-functions|Mod Functions]]+
  
-===== New Features ===== +If the water (or the ground) is not found (for instance when the _globalPosition out of the map) then a warning is edited in the logsand the code return the Y of the _globalPosition.
-  * [[#Building part function|Building part functions are now assetsdeclared individually.]] +
-    * [[preview:assets:building_function|Core building part functions have also been exposed to the API.]] +
-  * [[#Resource type list|A resource can now have multiple resource types]] +
-  * [[preview:assets:behavior_tree|The market tender behavior is now available]]+
  
-===== Migration Notes ===== 
-==== Building part function ==== 
  
-For assets from type ''BUILDING_PART'', the attribute ''BuildingFunction'' is now replaced with ''AssetBuildingFunction''. Thus, the building function must now be declared as an asset of type ''BUILDING_FUNCTION''. 
  
-Migration example for the //Example 02// mod: 
-<file lua building_parts.lua> 
-mod:register({ 
-    DataType = "BUILDING_PART", 
-    ... 
  
---  OLD 
---  BuildingFunction = {  
---      DataType = "BUILDING_FUNCTION_WORKPLACE", 
---      WorkerCapacity = 4, 
---      RelatedJob = { Job = "MITHRIL_MINER", Behavior = "WORK_BEHAVIOR" }, 
---      ResourceProduced = { 
---          { Resource = "MITHRIL_ORE", Quantity = 5 } 
---      } 
---  }, 
- 
---  NEW 
-    BuildingFunction = "MITHRIL_MINE_FUNCTION", 
- 
-    ... 
-}) 
- 
--- ALSO NEW 
-mod:register({ 
-    DataType = "BUILDING_FUNCTION_WORKPLACE", 
-    Id = "MITHRIL_MINE_FUNCTION", 
-    WorkerCapacity = 4, 
-    RelatedJob = { Job = "MITHRIL_MINER", Behavior = "WORK_BEHAVIOR" }, 
-    ResourceProduced = { 
-        { Resource = "MITHRIL_ORE", Quantity = 5 } 
-    } 
-}) 
-</file> 
- 
-==== Resource type list ==== 
-The enumeration ''RESOURCE_TYPE'' has been removed, and has been replaced by plain strings. This change means that modders can now define their own new types to work with their custom systems. The list of resource types has been moved to another page. 
- 
-Another change is that resource, markets, granaries and warehouses can now have multiple resource types. This, combined with new customizable resource types, will be useful to customize where resources can be stocked and sold. This means that the property ''ResourceType'' from ''RESOURCE'' has been renamed to ''ResourceTypeList''. 
- 
-For example, before this change, the wine was a resource of type ''LUXURY_FOOD''. Now, it has the types ''GRANARY'' and ''TAVERN''. The granary is configured to only store resources of type ''GRANARY'', and the tavern can only sell resources of type ''TAVERN''. Thus, wine will only be stored in granaries, and sold in taverns. The luxury stall, with its types ''LUXURY'' and ''LUXURY_FOOD'', will not be able to sell wine anymore. 
- 
-Migration example: 
-<file lua> 
-mod:register({ 
-    DataType = "RESOURCE", 
-    ... 
- 
---  OLD 
---  ResourceType = "LUXURY_FOOD", 
- 
---  NEW 
-    ResourceTypeList = { 
-      "GRANARY", 
-      "TAVERN" 
-    } 
- 
-    ... 
-}) 
-</file> 

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki