本讲以fueled stove【炉灶(燃料)】与machining table【机械加工台】为例,讲解工作台的制作
首先看到Core\Defs\ThingDefs_Buildings\Buildings_Production.xml,第125行至149行,关于BenchBase的定义。这是绝大多数工作台def的父对象
<ThingDef Name="BenchBase" ParentName="BuildingBase" Abstract="True">
<canOverlapZones>false</canOverlapZones>
<minifiedDef>MinifiedThing</minifiedDef>
<terrainAffordanceNeeded>Medium</terrainAffordanceNeeded>
<thingCategories>
<li>BuildingsProduction</li>
</thingCategories>
<statBases>
<Mass>20</Mass>
</statBases>
<interactionCellIcon>DiningChair</interactionCellIcon>
<comps>
<li Class="CompProperties_ReportWorkSpeed">
<workSpeedStat>WorkTableWorkSpeedFactor</workSpeedStat>
</li>
</comps>
<placeWorkers>
<li>PlaceWorker_ReportWorkSpeedPenalties</li>
</placeWorkers>
<building>
<buildingTags>
<li>Production</li>
</buildingTags>
</building>
</ThingDef>
我们重点看到几个部分
interactionCellIcon指的是
的图标,填一个ThingDef,你填椅子这里就是椅子的样子,你填沙发就是沙发
Comp中CompProperties_ReportWorkSpeed是用于报告一些工作速度的影响因素,比如户外、恶劣温度、没电等等,注意这个只能用于报告,不能用于决定,也就是说这些因素实际影响的代码不在这个comp里
PlaceWorker_ReportWorkSpeedPenalties与上面的comp类似
总而言之,当你需要创造一个工作台时,直接以BenchBase作为父对象就不会有太大问题。
往下走,先看到578行至654行的机械加工台
<ThingDef ParentName="BenchBase">
<defName>TableMachining</defName>
<label>machining table</label>
<description>A work station for assembling machinery like guns and ammunition, or breaking down dead mechanoids.</description>
<thingClass>Building_WorkTable</thingClass>
<graphicData>
<texPath>Things/Building/Production/TableMachining</texPath>
<graphicClass>Graphic_Multi</graphicClass>
<drawSize>(3.5,1.5)</drawSize>
<damageData>
<cornerTL>Damage/Corner</cornerTL>
<cornerTR>Damage/Corner</cornerTR>
<cornerBL>Damage/Corner</cornerBL>
<cornerBR>Damage/Corner</cornerBR>
</damageData>
</graphicData>
<castEdgeShadows>true</castEdgeShadows>
<staticSunShadowHeight>0.20</staticSunShadowHeight>
<costList>
<Steel>150</Steel>
<ComponentIndustrial>5</ComponentIndustrial>
</costList>
<altitudeLayer>Building</altitudeLayer>
<fillPercent>0.5</fillPercent>
<useHitPoints>True</useHitPoints>
<statBases>
<WorkToBuild>3000</WorkToBuild>
<MaxHitPoints>180</MaxHitPoints>
<Flammability>1.0</Flammability>
<Cleanliness>-2</Cleanliness>
</statBases>
<size>(3,1)</size>
<designationCategory>Production</designationCategory>
<uiOrder>2520</uiOrder>
<passability>PassThroughOnly</passability>
<pathCost>50</pathCost>
<hasInteractionCell>True</hasInteractionCell>
<interactionCellOffset>(0,0,-1)</interactionCellOffset>
<surfaceType>Item</surfaceType>
<constructionSkillPrerequisite>4</constructionSkillPrerequisite>
<recipes>
<li>ButcherCorpseMechanoid</li>
</recipes>
<inspectorTabs>
<li>ITab_Bills</li>
</inspectorTabs>
<comps>
<li Class="CompProperties_Power">
<compClass>CompPowerTrader</compClass>
<shortCircuitInRain>true</shortCircuitInRain>
<basePowerConsumption>350</basePowerConsumption>
</li>
<li Class="CompProperties_Flickable"/>
<li Class="CompProperties_Glower">
<glowRadius>5</glowRadius>
<glowColor>(73,123,138,0)</glowColor>
</li>
<li Class="CompProperties_AffectedByFacilities">
<linkableFacilities>
<li>ToolCabinet</li>
</linkableFacilities>
</li>
<li Class="CompProperties_Breakdownable"/>
</comps>
<building>
<spawnedConceptLearnOpportunity>BillsTab</spawnedConceptLearnOpportunity>
</building>
<constructEffect>ConstructMetal</constructEffect>
<researchPrerequisites>
<li>Machining</li>
</researchPrerequisites>
<designationHotKey>Misc7</designationHotKey>
<placeWorkers>
<li>PlaceWorker_ShowFacilitiesConnections</li>
<li>PlaceWorker_PreventInteractionSpotOverlap</li>
</placeWorkers>
</ThingDef>
我们仅分析与工作台相关部分
thingClass:这是xml与C#连接的部分,工作台使用Building_WorkTable
designationCategory:影响的是这个建筑存在于哪个栏内,Production就是“生产”
hasInteractionCell:是否存在互动点,也就是上文提到那个椅子图标,如果这个填false的话,小人只需要触碰到工作台即可。
interactionCellOffset:如果存在互动点的话,使用这个来修改互动点相对于建筑物中心的位置,格式为(x,0,y),这个互动点会随着建筑物的旋转而旋转。
surfaceType:默认为None,床头柜、矮柜、所有的物品架、工作台为Item,能拿来吃饭的桌子填Eat
recipes:填工作台自带的清单,注意这里不是填什么就只有什么,在使用recipeMaker时或recipeDef时也可以往工作台里增添清单。
inspectorTabs指选中后左侧出现的按钮,ITab_Bills指的是
这个按钮
接下来看一下comps:
CompProperties_Power:耗电,其中class使用的是CompPowerTrader,结合其他数据,决定了机械加工台耗电为350W,并且会在雨中短路。注意,具备像这样的comp的机器,在断电时会完全无法工作,然而,这也有例外,在裁缝台(电力)中,有这样一行:
<building>
<spawnedConceptLearnOpportunity>BillsTab</spawnedConceptLearnOpportunity>
<unpoweredWorkTableWorkSpeedFactor>0.5</unpoweredWorkTableWorkSpeedFactor>
<paintable>true</paintable>
</building>
当出现unpoweredWorkTableWorkSpeedFactor的大于0的数据时,断电的工作台工作效率会乘该值,而不是直接无法工作。
CompProperties_Flickable:指的是这个东西
CompProperties_Glower:该comp可以使Thing发光,并且是否发光会受到许多其他comp控制,比如电力相关,开关相关,燃料相关。
CompProperties_AffectedByFacilities:这使得机械加工台可以与工作柜连接并受到其提供的加成。
CompProperties_Breakdownable:使得机械加工台会损坏,需要使用零部件维修才能继续工作。
placeWorkers中有两项:
PlaceWorker_ShowFacilitiesConnections带来与工作站连接的预览,是视觉效果。
PlaceWorker_PreventInteractionSpotOverlap是渲染互动点的预览。
综上可以看出,thingClass改为Building_WorkTable,inspectorTabs的添加,使得Thing真正成为了工作台,在辅助互动点的设置与recipe的添加,并使用电力进行限制,再进行其他次要数据的调整,机械加工台便完成了。
炉灶也是大同小异,在748行至837行
<ThingDef ParentName="BenchBase">
<defName>FueledStove</defName>
<label>fueled stove</label>
<description>A wood-fueled stove with an attached countertop for preparing meals.</description>
<thingClass>Building_WorkTable_HeatPush</thingClass>
<drawerType>MapMeshAndRealTime</drawerType>
<graphicData>
<texPath>Things/Building/Production/TableStoveFueled</texPath>
<graphicClass>Graphic_Multi</graphicClass>
<drawSize>(3.5,1.5)</drawSize>
<damageData>
<cornerTL>Damage/Corner</cornerTL>
<cornerTR>Damage/Corner</cornerTR>
<cornerBL>Damage/Corner</cornerBL>
<cornerBR>Damage/Corner</cornerBR>
</damageData>
</graphicData>
<castEdgeShadows>true</castEdgeShadows>
<staticSunShadowHeight>0.20</staticSunShadowHeight>
<constructEffect>ConstructMetal</constructEffect>
<costList>
<Steel>80</Steel>
</costList>
<altitudeLayer>Building</altitudeLayer>
<fillPercent>0.5</fillPercent>
<useHitPoints>True</useHitPoints>
<statBases>
<WorkToBuild>2000</WorkToBuild>
<MaxHitPoints>180</MaxHitPoints>
<Flammability>1.0</Flammability>
</statBases>
<size>(3,1)</size>
<designationCategory>Production</designationCategory>
<uiOrder>2120</uiOrder>
<passability>PassThroughOnly</passability>
<pathCost>50</pathCost>
<hasInteractionCell>True</hasInteractionCell>
<interactionCellOffset>(0,0,-1)</interactionCellOffset>
<surfaceType>Item</surfaceType>
<recipes>
<li>CookMealSimple</li>
<li>CookMealFine</li>
<li>CookMealFine_Veg</li>
<li>CookMealFine_Meat</li>
<li>CookMealLavish</li>
<li>CookMealLavish_Veg</li>
<li>CookMealLavish_Meat</li>
<li>CookMealSurvival</li>
<li>CookMealSimpleBulk</li>
<li>CookMealFineBulk</li>
<li>CookMealFineBulk_Veg</li>
<li>CookMealFineBulk_Meat</li>
<li>CookMealLavishBulk</li>
<li>CookMealLavishBulk_Veg</li>
<li>CookMealLavishBulk_Meat</li>
<li>CookMealSurvivalBulk</li>
<li>Make_Pemmican</li>
<li>Make_PemmicanBulk</li>
<li MayRequire="Ludeon.RimWorld.Biotech">Make_BabyFood</li>
<li MayRequire="Ludeon.RimWorld.Biotech">Make_BabyFoodBulk</li>
</recipes>
<inspectorTabs>
<li>ITab_Bills</li>
</inspectorTabs>
<comps>
<li Class="CompProperties_Refuelable">
<fuelConsumptionRate>160.0</fuelConsumptionRate>
<fuelCapacity>50.0</fuelCapacity>
<fuelFilter>
<thingDefs>
<li>WoodLog</li>
</thingDefs>
</fuelFilter>
<consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed>
<showAllowAutoRefuelToggle>true</showAllowAutoRefuelToggle>
</li>
<li Class="CompProperties_HeatPusher">
<compClass>CompHeatPusherPowered</compClass>
<heatPerSecond>4</heatPerSecond>
</li>
</comps>
<placeWorkers>
<li>PlaceWorker_PreventInteractionSpotOverlap</li>
</placeWorkers>
<building>
<isMealSource>true</isMealSource>
<spawnedConceptLearnOpportunity>BillsTab</spawnedConceptLearnOpportunity>
<heatPerTickWhileWorking>0.10</heatPerTickWhileWorking>
</building>
</ThingDef>
需要指出其中一些不同:thingClass填Building_WorkTable_HeatPush,同时building下有一个heatPerTickWhileWorking,使得工作台在被使用,进行清单时会持续产热,使房间内温度升高。当然了,你也可以填负值,也就是吸热。
Comp中:
CompProperties_Refuelable即燃料机制,consumeFuelOnlyWhenUsed使得工作台只有在进行清单时才会消耗燃料,而不是像篝火那样持续消耗。
CompProperties_HeatPusher也是产热,但与Building_WorkTable_HeatPush代码中的产热机制不同,这个comp是只要有燃料就会一直产热。当然这里的产热不会影响燃料消耗。
不止为何,在我撰写本文之时,该comp无论如何都不生效,即使我把他的数值改到非常高,他也不会产热,无论该工作台是否工作。
building.isMealSource:建筑可以被作为食物来源,仅与“缺少食物源:你缺少把生食加工成烹饪食品的方式。建造一个炉灶、篝火,或者营养膏合成机。(不能放置在监狱房中,否则殖民者将无法使用它)”这条提示有关。