mindustry吧 关注:12,195贴子:74,826
  • 25回复贴,共1

萌新求个处理器代码呜呜呜

只看楼主收藏回复

求一个修复器在范围内建筑受损的时候自动开启然后满血的时候关闭的代码


IP属地:内蒙古来自Android客户端1楼2021-05-01 18:37回复
    用sensor探测目标生命值(health),再用jump比较,记得加end,最后把比较出的结果给control进行开(关)
    希望你听得懂


    IP属地:贵州来自Android客户端2楼2021-05-01 22:50
    收起回复
      给你个东西,你先自己看看吧
      http://tieba.baidu.com/p/6879321606?share=9105&fr=share&see_lz=1&share_from=post&sfc=copy&client_type=2&client_version=12.4.8.15&st=1619880662&unique=3C21B6559E9A2FAE502CFEFC32AB64E4


      IP属地:贵州来自Android客户端3楼2021-05-01 22:53
      收起回复
        一个处理器+1个内存
        set a 0
        set b 0
        set num 0
        set pos 0
        getlink result num
        sensor type result @type
        jump 10 equal type @mender
        jump 8 notEqual type @mender
        op add a a 1
        jump 13 always type @mender
        op add b b 1
        write num cell1 pos
        op add pos pos 1
        op add num num 1
        jump 4 lessThan num @links
        set repair_num 0
        getlink result repair_num
        sensor health result @health
        sensor maxhealth result @maxHealth
        jump 21 equal health maxhealth
        jump 28 notEqual health maxhealth
        set mender_pos 0
        read mender_num cell1 mender_pos
        getlink mender mender_num
        control enabled mender 0 0 0 0
        op add mender_pos mender_pos 1
        jump 22 lessThanEq mender_pos pos
        jump 35 always mender_pos pos
        set mender_pos 0
        read mender_num cell1 mender_pos
        getlink mender mender_num
        control enabled mender 1 0 0 0
        op add mender_pos mender_pos 1
        jump 29 lessThanEq mender_pos pos
        jump 16 always repair_num @links
        op add repair_num repair_num 1
        jump 16 lessThanEq repair_num @links
        jump 0 always repair_num @links


        IP属地:内蒙古4楼2021-05-02 15:48
        收起回复
          set a 0
          set b 0
          set num 0
          set pos 0
          getlink result num
          sensor type result @type
          jump 10 equal type @mender
          jump 8 notEqual type @mender
          op add a a 1
          jump 13 always type @mender
          op add b b 1
          write num cell1 pos
          op add pos pos 1
          op add num num 1
          jump 4 lessThan num @links
          set repair_num 0
          getlink result repair_num
          sensor health result @health
          sensor maxhealth result @maxHealth
          jump 21 equal health maxhealth
          jump 28 notEqual health maxhealth
          set mender_pos 0
          read mender_num cell1 mender_pos
          getlink mender mender_num
          control enabled mender 0 0 0 0
          op add mender_pos mender_pos 1
          jump 22 lessThanEq mender_pos pos
          jump 35 always mender_pos pos
          set mender_pos 0
          read mender_num cell1 mender_pos
          getlink mender mender_num
          control enabled mender 1 0 0 0
          op add mender_pos mender_pos 1
          jump 29 lessThanEq mender_pos pos
          jump 16 always repair_num @links
          op add repair_num repair_num 1
          jump 16 lessThanEq repair_num @links
          jump 0 always repair_num @links


          IP属地:贵州来自Android客户端5楼2021-05-03 16:01
          收起回复
            今天刚玩到解锁了大的修复器(修复投影器),但是昨天的代码只能用于小修复器,于是重新写了一下代码


            IP属地:内蒙古6楼2021-05-03 21:53
            回复
              《精确版》
              1.需要一个处理器连结2个内存使用
              2.处理器直接连结需要修复的建筑和修复器即可使用(可同时连结多个建筑和修复器)
              3.增加了修复器范围判断,现在每个修复器只在自己的修理范围内时有至少1个建筑受伤时工作
              4.优点是更精确,缺点当然是响应慢了,有一说一真的慢
              set build_num 0
              set mender_num 0
              set build_pos 0
              set mender_pos 0
              set num 0
              getlink result num
              sensor type result @type
              jump 13 equal type @mend-projector
              jump 13 equal type @mender
              op add build_num build_num 1
              write num cell1 build_pos
              op add build_pos build_pos 1
              jump 16 always type @mender
              op add mender_num mender_num 1
              write num cell2 mender_pos
              op add mender_pos mender_pos 1
              op add num num 1
              jump 5 lessThan num @links
              set a 0
              set bool 0
              set b 0
              read c cell2 a
              op add a a 1
              getlink mender c
              sensor x1 mender @x
              sensor y1 mender @y
              sensor type mender @type
              read d cell1 b
              op add b b 1
              getlink build d
              sensor x2 build @x
              sensor y2 build @y
              op sub x x2 x1
              op sub y y2 y1
              op len distance x y
              sensor health build @health
              sensor maxhealth build @maxHealth
              jump 40 equal type @mender
              jump 43 greaterThanEq distance 10.62
              jump 41 always distance 10.62
              jump 43 greaterThanEq distance 5
              jump 43 equal health maxhealth
              set bool 1
              jump 27 lessThan b build_num
              jump 46 equal bool 1
              control enabled mender 0 0 0 0
              jump 19 lessThan a mender_num
              jump 18 equal num @links
              end


              IP属地:内蒙古7楼2021-05-03 21:53
              收起回复
                《终极版》
                1.需要一个处理器连结2个小内存和1个内存库使用(或3个小内存,见5)
                2.处理器直接连结需要修复的建筑和修复器即可使用(可同时连结多个建筑和修复器,支持两种修复器同时使用)
                3.精确到每个修复器的修复范围,现在每个修复器只在自己的修理范围内时有至少1个建筑受伤时工作(极限距离情况可能不准,比如Δx=4.5,Δy=2.5,s=5.15>5明明大于修复器范围,但是游戏却显示是在范围内的,但是如果Δx=5,游戏里又显示不在不在范围内,麻了
                4.修复了精确版响应奇慢的问题(响应速度和处理器连结数量有关,连的太多了还是会慢
                5.内存库可替换为1个小内存,需要把代码内两个bank1替换为cell3,只能连结(m+n)个单元(m*n<64),
                6.我刷了6次屏了对不起!!因为短短5个小时每次改到能用了就发,然后下次用发现有bug又删了,来来回回发了6次删了6次,我保证这次98%能用了,要还有bug我也不改了
                set build_pos 0
                set build_num 0
                set mend_pos 0
                set mend_num 0
                set count 0
                getlink result count
                sensor type result @type
                jump 15 equal type @mender
                jump 15 equal type @mend-projector
                jump 18 equal type @memory-cell
                jump 18 equal type @memory-bank
                write count cell1 build_pos
                op add build_num build_num 1
                op add build_pos build_pos 1
                jump 18 always x false
                write count cell2 mend_pos
                op add mend_num mend_num 1
                op add mend_pos mend_pos 1
                op add count count 1
                jump 5 lessThan count @links
                set bank_pos 0
                set mend_pos 0
                set build_pos 0
                read pos cell2 mend_pos
                op mul temp1 pos 100
                op add mend_pos mend_pos 1
                getlink mend pos
                sensor x1 mend @x
                sensor y1 mend @y
                sensor type mend @type
                read pos cell1 build_pos
                op add build_pos build_pos 1
                getlink build pos
                sensor x2 build @x
                sensor y2 build @y
                op sub x x1 x2
                op sub y y1 y2
                op len distance x y
                jump 41 equal type @mender
                jump 45 greaterThanEq distance 10.62
                jump 42 always distance 10.62
                jump 45 greaterThanEq distance 5
                op add temp2 temp1 pos
                write temp2 bank1 bank_pos
                op add bank_pos bank_pos 1
                jump 30 lessThan build_pos build_num
                jump 22 lessThan mend_pos mend_num
                set mend_pos 0
                set bank_pos 0
                set switch 0
                read pos1 cell2 mend_pos
                op add mend_pos mend_pos 1
                getlink mend pos1
                read pos bank1 bank_pos
                jump 0 notEqual count @links
                op idiv pos2 pos 100
                jump 66 notEqual pos1 pos2
                op add bank_pos bank_pos 1
                op add bank_pos bank_pos 1
                op mod pos pos 100
                getlink build pos
                sensor health build @health
                sensor maxhealth build @maxHealth
                jump 65 equal health maxhealth
                set switch 1
                jump 53 equal pos1 pos2
                jump 69 equal switch 1
                control enabled mend 0 0 0 0
                jump 70 always x false
                control enabled mend 1 0 0 0
                jump 49 lessThan mend_pos mend_num
                jump 47 always x false


                IP属地:内蒙古14楼2021-05-04 23:11
                收起回复
                  快进到解锁相位物


                  IP属地:山东来自Android客户端15楼2021-05-05 00:53
                  回复
                    啊啊啊啊啊气死我了,我可能是吧,我好像什么时候不小心点到了复制,然后图里这里重复了一行!!!我说怎么今天改来改去一直有bug啊啊啊啊,***裂开来,去掉这行终于可以了,收工睡觉


                    IP属地:内蒙古来自Android客户端16楼2021-05-05 03:05
                    回复
                      set build_pos 0
                      set build_num 0
                      set mend_pos 0
                      set mend_num 0
                      set count 0
                      getlink result count
                      sensor type result @type
                      jump 15 equal type @mender
                      jump 15 equal type @mend-projector
                      jump 18 equal type @memory-cell
                      jump 18 equal type @memory-bank
                      write count cell1 build_pos
                      op add build_num build_num 1
                      op add build_pos build_pos 1
                      jump 18 always x false
                      write count cell2 mend_pos
                      op add mend_num mend_num 1
                      op add mend_pos mend_pos 1
                      op add count count 1
                      jump 5 lessThan count @links
                      set bank_pos 0
                      set mend_pos 0
                      set build_pos 0
                      read pos cell2 mend_pos
                      op mul temp1 pos 100
                      op add mend_pos mend_pos 1
                      getlink mend pos
                      sensor x1 mend @x
                      sensor y1 mend @y
                      sensor type mend @type
                      read pos cell1 build_pos
                      op add build_pos build_pos 1
                      getlink build pos
                      sensor x2 build @x
                      sensor y2 build @y
                      op sub x x1 x2
                      op sub y y1 y2
                      op len distance x y
                      jump 41 equal type @mender
                      jump 45 greaterThanEq distance 10.62
                      jump 42 always distance 10.62
                      jump 45 greaterThanEq distance 5
                      op add temp2 temp1 pos
                      write temp2 bank1 bank_pos
                      op add bank_pos bank_pos 1
                      jump 30 lessThan build_pos build_num
                      jump 22 lessThan mend_pos mend_num
                      set mend_pos 0
                      set bank_pos 0
                      set switch 0
                      read pos1 cell2 mend_pos
                      op add mend_pos mend_pos 1
                      getlink mend pos1
                      read pos bank1 bank_pos
                      jump 0 notEqual count @links
                      op idiv pos2 pos 100
                      jump 66 notEqual pos1 pos2
                      op add bank_pos bank_pos 1
                      op mod pos pos 100
                      getlink build pos
                      sensor health build @health
                      sensor maxhealth build @maxHealth
                      jump 65 equal health maxhealth
                      set switch 1
                      jump 53 equal pos1 pos2


                      IP属地:内蒙古来自Android客户端18楼2021-05-05 03:16
                      收起回复


                        IP属地:广东来自Android客户端19楼2021-05-05 07:36
                        回复
                          学习了


                          来自Android客户端20楼2021-05-08 13:26
                          回复