通用型搬运控制器和遍历物品的代码结构
mindustry吧
全部回复
仅看楼主
level 9
懒,一张图预览
2020年11月27日 15点11分 1
level 9
主要特点:
1 依据xy坐标完全自定义抽取位置、投放位置、回收位置,只要那里有容器或工厂
2 指定某个种类和flag的所有单位进行运输
3 可以依次运输多种材料,只要在代码里修改需求参数
4 完备的信息展示,且性能占用低[滑稽]
2020年11月27日 16点11分 2
5 可设定抽取保留量,避免榨干
2020年11月27日 17点11分
level 9
处理器代码,加了简单注释[滑稽]
第二段和第四段利用索引值和@counter简单实现了类似for遍历的结构,遍历的是@物品关键字
set CARRIER_TYPE @flare
set CARRIER_FLAG_BIND 1919
set CORE_MIN_AMOUNT 50
set ToX @thisx
set ToY @thisy
set FromX @thisx
set FromY @thisy
set BinX @thisx
set BinY @thisy
getlink msg 0
getlink disp 1
/一些初始参数
set curItemIndex 0
set COUNTER_ITEMLIST @counter
op add COUNTER_ITEMLIST COUNTER_ITEMLIST 2
op add COUNTER_MAIN COUNTER_ITEMLIST 48 /这些是计算一些固定的指令行位置,如列表起始行COUNTER_ITEMLIST,主函数起始行COUNTER_MAIN。48是因为列表有16物品,对每物品有三条指令要执行。下面要用
set iType @Copper /一长串列表,按照统一的模式赋值@物品名和相关变量
set iReq 1000
set @counter COUNTER_MAIN
set iType @lead
set iReq 800
set @counter COUNTER_MAIN
set iType @titanium
set iReq 800
set @counter COUNTER_MAIN
set iType @thorium
set iReq 0
set @counter COUNTER_MAIN
set iType @silicon
set iReq 0
set @counter COUNTER_MAIN
set iType @metaglass
set iReq 0
set @counter COUNTER_MAIN
set iType @graphite
set iReq 0
set @counter COUNTER_MAIN
set iType @plastanium
set iReq 0
set @counter COUNTER_MAIN
set iType @phase-fabric
set iReq 0
set @counter COUNTER_MAIN
set iType @surge-alloy
set iReq 0
set @counter COUNTER_MAIN
set iType @sand
set iReq 0
set @counter COUNTER_MAIN
set iType @coal
set iReq 0
set @counter COUNTER_MAIN
set iType @spore-pod
set iReq 0
set @counter COUNTER_MAIN
set iType @scrap
set iReq 0
set @counter COUNTER_MAIN
set iType @pyratite
set iReq 0
set @counter COUNTER_MAIN
set iType @blast-compound
set iReq 0
set @counter COUNTER_MAIN
set temp null /看起来很随意的主函数
set temp null
set temp null
ubind CARRIER_TYPE
sensor flag @璐村惂鐢ㄦ埛_00Q6JQM馃惥 @flag
op rand RandomRestart 100000 iAmount
jump 0 lessThanEq RandomRestart 1
jump 66 notEqual flag CARRIER_FLAG_BIND
sensor iAmount ToBlock iType
op sub iNeed iReq iAmount
sensor uItemAmount @unit @totalItems
sensor uItemType @unit @firstItem
sensor uItemCapa @unit @itemCapacity
op sub showTime @time lastShowTime
jump 111 lessThanEq showTime 2000
op add lastShowTime @time 0
print "[violet]CARRIER REPORT |"
print "\n[white]Item: "
print iType
print curItemIndex
print "\n"
print "Cfg Req: "
print iReq
print "\nNeed: "
print iNeed
print "\nSourceStorage: "
print cItem
print "\nMinThreshold: "
print CORE_MIN_AMOUNT
print "\nTime: "
print @time
print "\nby [royal]MyIndustry2[stat]\nWhy "
print "does Anuke limit length of Print!!!!"
print "[red](ANGRY)"
printflush msg
draw clear 0 0 0 0 0 0
op div iAmountPct iAmount iReq
op mul iAmountPct iAmountPct 72
draw stroke 3 255 255 255 0 0
draw color 0 255 255 255 0 0
draw rect 0 8 iAmountPct 16 0 0
draw color 50 200 100 255 0 0
draw lineRect 0 8 72 16 0 0
draw color 255 255 255 255 0 0
draw lineRect 0 8 80 16 0 0
draw image 20 60 iType 32 0 0
draw image 60 60 CARRIER_TYPE 32 0 0
drawflush disp
jump 115 equal uItemType iType
ucontrol getBlock BinX BinY BinType DustbinBlock 0
ucontrol approach BinX BinY 3 0 0
ucontrol itemDrop DustbinBlock uItemAmount 4 0 0
jump 124 lessThan uItemAmount uItemCapa
sensor uItemType @unit @firstItem
jump 136 notEqual uItemType iType
ucontrol getBlock ToX ToY ToType ToBlock0 0
jump 121 equal ToBlock0 null
set ToBlock ToBlock0
ucontrol approach ToX ToY 5 0 0
ucontrol itemDrop ToBlock uItemCapa 0 0 0
jump 136 always uItemAmount uItemCapa
ucontrol getBlock FromX FromY FromType FromBlock0 0
jump 127 equal FromBlock0 null
set FromBlock FromBlock0
sensor cItem FromBlock iType
jump 136 lessThanEq cItem CORE_MIN_AMOUNT
sensor uItemCapa @unit @itemCapacity
sensor uItemAmount @unit @totalItems
op sub takeAmount uItemCapa uItemAmount
jump 134 notEqual uItemAmount 0
ucontrol approach FromX FromY 5 0 0
jump 136 lessThanEq iNeed 0
ucontrol itemTake FromBlock iType takeAmount 0 0
jump 138 greaterThan iNeed 0
op add curItemIndex curItemIndex 1 /计算并跳转到赋值下一物品的指令行。如果要保持iType不变,要想办法跳过第一句
op mul curItemCounter curItemIndex 3
op add curItemCounter curItemCounter COUNTER_ITEMLIST
op add COUNTER_MAIN COUNTER_ITEMLIST 49
jump 0 greaterThan curItemIndex 16
set @counter curItemCounter
2020年11月27日 16点11分 4
level 9
不过直接分析代码结构未免太心急
不如先说本蓝图工作流程
1抓到指定单位
2判断
【如果该种物品达到要求数量,跳转到下一个物品
【【如果单位身上物品不是正在进行搬运的,扔到回收容器
【【如果单位身上物品数量不够或没有物品,去抽取容器拿
【【如果单位是正在搬运的物品且数量够,送到投放容器
【如果所有物品遍历完了,就从头再执行
就这么简单
还有一些细节处理
1 信息输出和画图有一长串,留着影响效率,我设计成时间间隔足够大才执行一次
2 在绑定单位的时候,有极小的概率重置处理器(跳回第一句指令)。相当于更新所有初始参数
2020年11月27日 18点11分 5
level 9
@thisx和@thisy是什么意思呀
2020年11月28日 05点11分 7
处理器自己的xy坐标。
2020年11月28日 06点11分
@我的工业2♬ 嗷嗷,好的[摊手]
2020年11月28日 07点11分
level 2
草(一种植物) [滑稽]
2020年11月28日 15点11分 8
level 11
[乖]@counter是干嘛的啊,直接跳到指定行吗?
2020年11月30日 10点11分 9
如果赋值给它就是跳转
2020年11月30日 11点11分
到指定行
2020年11月30日 11点11分
@我的工业2♬ 那跟jump一样呗?
2020年11月30日 12点11分
@Cassiopeya 跳转效果一样。@counter可读性差一些,但更灵活
2020年11月30日 13点11分
1