铁锈战争模组和地图制作帮助文档

逻辑和条件

在铁锈战争中,逻辑和条件系统用于控制单位的行为和属性。本章节将详细介绍如何使用逻辑表达式和条件判断来创建复杂的单位行为。

逻辑基本语法

铁锈战争使用类C语言的逻辑语法:

基本逻辑值

# 布尔值
true     # 真
false    # 假

# 比较运算符
==       # 等于
!=       # 不等于
<        # 小于
>        # 大于
<=       # 小于等于
>=       # 大于等于

# 逻辑运算符
and      # 与
or       # 或
not      # 非

# 数学运算符
+        # 加
-        # 减
*        # 乘
/        # 除
%        # 取余
            

条件判断

可以使用if语句进行条件判断:

基本条件语法

# 基本条件
if self.hp < 100

# 复杂条件
if self.hp < 100 and self.energy > 50

# 使用括号分组
if (self.hp < 100 and self.energy > 50) or self.shield == 0
            

单位属性检查

可以检查单位的各种属性:

生命值检查

# 检查生命值
if self.hp < 100
if self.hp > 500
if self.hp == 0
if self.hp(lessThan:100)
if self.hp(greaterThan:500)
if self.hp(equalTo:0)
if self.hp(empty:true)
if self.hp(full:true)
            

能量值检查

# 检查能量值
if self.energy < 50
if self.energy > 100
if self.energy == 0
if self.energy(lessThan:50)
if self.energy(greaterThan:100)
if self.energy(equalTo:0)
if self.energy(empty:true)
if self.energy(full:true)
            

护盾值检查

# 检查护盾值
if self.shield < 50
if self.shield > 200
if self.shield == 0
if self.shield(lessThan:50)
if self.shield(greaterThan:200)
if self.shield(equalTo:0)
if self.shield(empty:true)
if self.shield(full:true)
            

资源检查

可以检查单位的资源:

资源检查语法

# 检查内置资源
if self.hasResources(credits:1000)
if self.hasResources(energy:50)
if self.hasResources(hp:100, shield:50)

# 检查自定义资源
if self.hasResources(gold:10)
if self.hasResources(manpower:20, gold:5)

# 检查单个资源
if self.resource(type:"credits", greaterThan:1000)
if self.resource(type:"energy", lessThan:50)
if self.resource(type:"gold", equalTo:10)
            

位置和移动检查

可以检查单位的位置和移动状态:

位置检查

# 检查位置状态
if self.isUnderwater()
if self.isFlying()
if self.isMoving()
if self.isAtTopSpeed()
if self.isInWater()
if self.isOverwater()
if self.isOverLiquid()
if self.isOverClift()
if self.isAtGroundHeight()

# 检查地形类型
if self.isOverPassableTile(type:"WATER")
if self.isOverPassableTile(type:"LAND")
if self.isOverOpenLand()

# 检查高度
if self.height(lessThan:50)
if self.height(greaterThan:100)
            

标签和队伍检查

可以检查单位的标签和队伍:

标签检查

# 检查标签
if self.hasTags(includes:"infantry")
if self.hasTags(includes:"vehicle,heavy")
if self.tags(includes:"infantry")
if self.tags(includes:"vehicle,heavy")

# 检查全局标签
if self.globalTeamTags(includes:"tech_unlock")
            

队伍检查

# 检查队伍ID
if self.teamId == 1
if self.teamId != 0

# 检查队伍关系
if self.isOnNeutralTeam()
if self.isControlledByAI()
            

统计信息检查

可以检查单位的统计信息:

统计检查

# 检查杀敌数
if self.kills(greaterThan:10)
if self.kills(lessThan:5)

# 检查队列大小
if self.queueSize(greaterThan:2)
if self.queueSize(equalTo:0)
if self.queueSize(empty:true)
if self.queueSize(full:true)

# 检查运输数量
if self.transportingCount(greaterThan:1)
if self.transportingCount(equalTo:0)
if self.transportingCount(empty:true)
if self.transportingCount(full:true)

# 检查子单位数量
if self.numberOfAttachedUnits(withTag:"turret", lessThan:1)
            

时间相关检查

可以检查时间相关的条件:

时间检查

# 检查存活时间
if self.timeAlive(laterThanSeconds:10)
if self.timeAlive(withinSeconds:5)

# 检查最后转换时间
if self.lastConverted(laterThanSeconds:30)
if self.lastConverted(withinSeconds:10)

# 检查自定义计时器
if self.customTimer(laterThanSeconds:5)
if self.customTimer(withinSeconds:2)

# 检查受到伤害时间
if self.hasTakenDamage(withinSeconds:1)
if self.hasTakenDamage(laterThanSeconds:5)
            

单位引用检查

可以检查单位引用:

引用检查

# 检查父单位
if self.hasParent()
if self.hasParent(withTag:"factory")

# 检查攻击状态
if self.isAttacking()

# 检查路径点
if self.hasActiveWaypoint(type:"move")
if self.hasActiveWaypoint(type:"attack")

# 检查运输单位标签
if self.transportingUnitWithTags(includes:"infantry")
            

地图相关检查

可以检查地图相关的条件:

地图检查

# 检查是否在地图内
if self.isInMap()

# 检查地图尺寸
if game.mapWidth() == 1000
if game.mapHeight() == 1000

# 检查队伍单位数量
if numberOfUnitsInTeam(withTag:"factory", greaterThan:0)
if numberOfUnitsInEnemyTeam(withTag="tank", greaterThan:5)
if numberOfUnitsInNeutralTeam(withTag="resource", greaterThan:10)
            

数学函数

可以使用数学函数:

数学函数

# 取整
if int(self.hp / 100) == 5

# 最大最小值
if max(self.hp, self.shield) > 500
if min(self.energy, self.ammo) < 10

# 平方根
if squareRoot(self.hp) > 20

# 三角函数
if cos(self.dir()) > 0.5
if sin(self.dir()) < 0.5

# 字符串操作
if length(self.name) > 10
if substring(self.name, 0, 3) == "ADV"
            

动态显示

可以使用动态显示:

动态显示语法

# 在文本中使用动态值
[action_special]
text:修复 (%{self.hp}/%{self.maxHp})
description:恢复生命值 %{self.maxHp - self.hp}

# 使用条件显示
[action_emergency]
text:紧急修复 %{select(self.hp < 100, "(可用)", "(不可用)")}
isVisible:if self.hp < 100
            

完整逻辑示例

复杂条件示例

# 复杂的自动触发条件
[hiddenAction_autoHeal]
autoTrigger=if (self.hp < 500 and self.energy > 30) or (self.shield < 100 and self.hasResources(credits:100))
addResources:hp:50, shield:25
spawnEffects:small_heal

# 基于时间的条件
[hiddenAction_timeBased]
autoTrigger=if self.timeAlive(laterThanSeconds:30) and self.kills(greaterThan:5)
addResources:experience:1

# 基于队伍的条件
[hiddenAction_teamBuff]
autoTrigger=if numberOfUnitsInTeam(withTag="tank", greaterThan=3) and self.isOnSameTeamAs(self.nearestUnit(withTag="commander"))
addResources:attackDamageMultiplier:1.2

# 基于资源的条件
[action_advancedRepair]
text:高级修复
description:消耗资源进行强力修复
price=credits:500, gold:10
isVisible=if self.hasResources(gold:10) and self.hp(lessThan:500)
addResources:hp:300
spawnEffects:large_heal
            

注意事项

回到顶部