Mindustry
logic to control payload of units / логика загрузки юнитов
LED  [developer] 10 out. 2023 às 15:16
Code! try to analize!
# Pay is Payload
set Control @mega
set NearToCoreDrop 6.9
set NearToPlayer 10
set NearToDrop 6
set NearToShoot 7
set NearMine 7
set HoldPos false

set Player null

op sub NearDrop NearToDrop 1
op sub NearShoot NearToShoot 1

ubind Control
sensor UnitRange @unit @range
op mul UR UnitRange 0.2
radar player any any distance @this 1 Player

NoWork:
sensor isEnable switch1 @enabled
jump NoWork equal isEnable false

start:
sensor isPlayerControl Player @controlled
jump HavePlayer equal isPlayerControl @ctrlPlayer
#NoPlayer:
radar player any any distance @this 1 TryPlayer
sensor isDead Player @dead
jump CheckPlayer strictEqual isDead false # CHECK death of player - if he died in battle the control jump to new player!
uradar player any any distance 0 1 TryPlayer
CheckPlayer:
jump NullPlayer equal TryPlayer null
set Player TryPlayer
NullPlayer:
HavePlayer:
ubind Control
sensor UnitFlag @unit @flag
jump NoFlag equal UnitFlag 0 #Unit Have Flag BUT it can be trash flag. then else processors forget to remove flags! (it not clear flags of group control - HAHAHAHAHAH I think, im not sure :\ OKEY I CHECK IT AND I WAS RIGHT IT DOSNT TACKE CONTROL OF GROPE OF 1 PROCESSOR)
sensor ControllerOfUnit @unit @controlled
jump start equal ControllerOfUnit @ctrlProcessor #Check Unit control, it can't be this cuz this always have 0 flag.(Open to take)
ucontrol flag 0 #Clear flag
NoFlag:
jump start strictEqual Player null
sensor PlayerX Player @x
sensor PlayerY Player @y

#1-Check Shoot
sensor isPlayerShoot Player @shooting
jump PShoot equal isPlayerShoot true

#2-Check Enemy
uradar enemy any any distance 0 1 nearEnemy
ucontrol targetp nearEnemy 1

#3-Check Mining
sensor isPlayerMine Player @mining
jump Mine equal isPlayerMine true
ucontrol stop

#4-Check Items
sensor itemsIn @unit @totalItems
jump CoreDrop notEqual itemsIn 0

#5-Check Payload
sensor Pay Player @payloadType

uradar ground ally attacker distance 0 1 NearPay
jump ToDrop equal NearPay null

jump ToDrop equal Pay null
jump PayEffect always

ToDrop:
jump MoveToPlayer notEqual Pay null
sensor PayUnit @unit @payloadType
jump MoveToPlayer equal PayUnit null
jump PayEffect always

#6-Make distance
MoveToPlayer:
ucontrol approach PlayerX PlayerY NearToPlayer

sensor isEnable switch1 @enabled
jump OffWork equal isEnable false

jump start always


Mine:
sensor MX Player @mineX
sensor MY Player @mineY
ucontrol approach MX MY NearMine
ucontrol mine MX MY
jump start always


CoreDrop:
ulocate building core false @copper Corex Corey isCore Core
ucontrol approach PlayerX PlayerY NearToCoreDrop
ucontrol itemDrop Core 1000
jump start always


PShoot:
sensor ShX Player @shootX
sensor ShY Player @shootY
sensor UX @unit @x
sensor UY @unit @y
op sub Len ShX UX
op sub Hei ShY UY
op len lenght Len Hei
op div C UR lenght
op mul RelativeUSX Len C
op mul RelativeUSY Hei C
op add USX UX RelativeUSX
op add USY UY RelativeUSY
jump PSC equal HoldPos true
#ucontrol within PlayerX PlayerY NearToShoot isClose
#jump PSC equal isClose true
ucontrol approach PlayerX PlayerY NearShoot
PSC:
ucontrol target USX USY isPlayerShoot
jump start always


PayEffect:
ucontrol within PlayerX PlayerY NearToDrop isClose
ucontrol approach PlayerX PlayerY NearDrop
jump start equal isClose false
MakePay:
jump Take notEqual Pay null
ucontrol payDrop
jump start always
Take:
ucontrol payTake 10
jump start always


OffWork:
set inRowCounter 24

UnBind:
ucontrol stop
ucontrol unbind

SubRowCounter:
op sub inRowCounter inRowCounter 1
jump NoWork lessThan inRowCounter 0
ubind Control
sensor UnitFlag @unit @flag
jump NoFlagToOff equal UnitFlag 0
sensor ControllerOfUnit @unit @controlled
jump SubRowCounter equal ControllerOfUnit @ctrlProcessor #Check Unit control, it can't be this cuz this always have 0 flag.(Open to take)
ucontrol flag 0 #Clear flag
NoFlagToOff:

jump UnBind always