rimworld進行mod制作的起步難度很低,由於大部分mod功能都是由xml語言進行實現的,因此可以從他人的mod中快速了解mod的基本結構並將自己的想法實現。
下面先介紹mod的主要組成
一個模組(mod)一般含有以下幾個文件夾:
1.About:對於mod的簡介和版本更新說明等等內容。
2.Defs:mod的核心代碼,一般包含mod添加的主要內容
3.Textures:mod添加內容的材質和界面ui
4.Sounds:音效等等聲音文件
5.Assemblies:mod添加的底層代碼,在riworld原代碼結構的基礎上添加或修改內容,包含dll文件和c#文件
6.Languages:不同版本的語言包
7.Patches:與其他mod的兼容和聯動補丁
這里主要介紹代碼實現部分
由於一般的模組代碼都是由xml組成的,而對象所包含的屬性等配置參數
下面是一個自己寫的建築模組的代碼樣例,包含了一個防御建築的所有元素,材質路徑默認/Textures作為根目錄
<?xml version ="1.0" encoding="utf-8"?> <Defs><ThingDef ParentName="BuildingBase"> <defName>Bjwhile_BU_bunkerboy_Base</defName><!--定義物品名字--> <label>dick boy</label> <description>base_tower</description> <thingClass>Building_TurretGun</thingClass><!--定義物品分類--> <graphicData> <texPath>Buildings/Bjwhile_BU_bunkerboy_Base</texPath> <!--定義材質路徑--> <graphicClass>Graphic_Single</graphicClass> <shaderType>Transparent</shaderType> <drawSize>(3,3)</drawSize> <damageData> <rect>(0.05,0.05,0.3,0.3)</rect> </damageData> </graphicData> <size>(1,1)</size> <!--定義物品大小--> <passability>PassThroughOnly</passability> <pathCost>50</pathCost> <castEdgeShadows>true</castEdgeShadows> <fillPercent>0.4</fillPercent> <hasTooltip>true</hasTooltip> <uiIconPath>UI/Bjwhile_UI_bunkerboy_Gun</uiIconPath> <uiIconScale>1</uiIconScale> <!--物品特效--> <rotatable>true</rotatable> <altitudeLayer>Building</altitudeLayer> <stealable>false</stealable> <!--物品分類--> <thingCategories> <li>BuildingsSecurity</li> </thingCategories> <minifiedDef>MinifiedThing</minifiedDef><!--可以裝卸--> <tickerType>Normal</tickerType> <!--屬性--> <statBases> <WorkToBuild>6000</WorkToBuild> <MaxHitPoints>400</MaxHitPoints> <Flammability>0.5</Flammability> <Beauty>0</Beauty> <Mass>100</Mass> <MarketValue>500</MarketValue> </statBases> <!--耗材--> <!--> <stuffCategories> <li>Metallic</li> </stuffCategories> <--> <costList> <Steel>300</Steel> <ComponentIndustrial>5</ComponentIndustrial> </costList> <!--建築定義--> <building> <ai_combatDangerous>true</ai_combatDangerous> <turretGunDef>BJ_bunkerboy_gun</turretGunDef> <!-->><turretBurstWarmupTime>4.0</turretBurstWarmupTime><--> <turretBurstCooldownTime>8.0</turretBurstCooldownTime> <buildingTags> <li>Artillery</li> </buildingTags> </building> <!--功能--> <comps> <li Class="CompProperties_Explosive"> <explosiveRadius>2</explosiveRadius> <explosiveDamageType>Bomb</explosiveDamageType> <chanceNeverExplodeFromDamage>0.6</chanceNeverExplodeFromDamage> </li> <li Class="CompProperties_Power"> <compClass>CompPowerTrader</compClass> <basePowerConsumption>200</basePowerConsumption> </li> <li Class="CompProperties_Forbiddable"/> <!-->><li Class="CompProperties_Mannable"/><--> <li Class="CompProperties_Flickable"/> <li Class="CompProperties_Breakdownable"/> <li Class="CompProperties_Glower"> <glowRadius>10</glowRadius> <glowColor>(217,217,180,0)</glowColor> </li> <li Class="CompProperties_Refuelable"> <fuelLabel>Shots until barrel change</fuelLabel> <fuelGizmoLabel>Barrel durability</fuelGizmoLabel> <fuelFilter> <thingDefs> <li>Steel</li> </thingDefs> </fuelFilter> <fuelCapacity>200</fuelCapacity> <initialFuelPercent>1</initialFuelPercent> <autoRefuelPercent>0.75</autoRefuelPercent> <showFuelGizmo>true</showFuelGizmo> <minimumFueledThreshold>1</minimumFueledThreshold> <fuelMultiplier>3.75</fuelMultiplier> <factorByDifficulty>true</factorByDifficulty> <consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed> <outOfFuelMessage>Cannot shoot: Needs new barrel</outOfFuelMessage> <fuelIconPath>UI/Overlays/Barrel</fuelIconPath> </li> </comps> <specialDisplayRadius>28</specialDisplayRadius> <constructionSkillPrerequisite>5</constructionSkillPrerequisite> <designationCategory>Security</designationCategory> <researchPrerequisites> <li>Mortars</li> <!--><li>Bjwhile_RE_Terran_pro</li><--> </researchPrerequisites> <!--需要工作人員--> <placeWorkers> <li>PlaceWorker_TurretTop</li> <li>PlaceWorker_ShowTurretRadius</li> </placeWorkers> </ThingDef> <ThingDef ParentName="BaseBullet"> <defName>BJ_Bullet_bunkerboy</defName> <label>dickboy bullet</label> <graphicData> <texPath>Projectile/BJ_bullet</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <projectile> <damageDef>Bullet</damageDef> <damageAmountBase>10</damageAmountBase> <speed>70</speed> </projectile> </ThingDef> <ThingDef ParentName="BaseWeaponTurret"> <defName>BJ_bunkerboy_gun</defName> <label>turret gun</label> <description>A automatic gun made to be mounted on a turret.</description> <graphicData> <texPath>Buildings/Bjwhile_BU_bunkerboy_Gun</texPath> <graphicClass>Graphic_Single</graphicClass> </graphicData> <soundInteract>Interact_Rifle</soundInteract> <statBases> <Mass>40</Mass> <AccuracyTouch>0.60</AccuracyTouch> <AccuracyShort>0.64</AccuracyShort> <AccuracyMedium>0.5</AccuracyMedium> <AccuracyLong>0.4</AccuracyLong> <RangedWeapon_Cooldown>1</RangedWeapon_Cooldown> </statBases> <verbs> <li> <verbClass>Verb_Shoot</verbClass> <hasStandardCommand>true</hasStandardCommand> <defaultProjectile>BJ_Bullet_bunkerboy</defaultProjectile> <warmupTime>1</warmupTime> <range>35</range> <ticksBetweenBurstShots>5</ticksBetweenBurstShots> <burstShotCount>6</burstShotCount> <soundCast>Shot_AssaultRifle</soundCast> <soundCastTail>GunTail_Light</soundCastTail> <muzzleFlashScale>9</muzzleFlashScale> <consumeFuelPerShot>1</consumeFuelPerShot> </li> </verbs> </ThingDef> </Defs>
一個建築模組的基本結構在這段代碼里面都包含了。
絕大多數的模組都是以這種形式實現的。