Search This Blog

Bee nightmare script, annotated

 [Originally written July 12 2021]

I started by examining the official beehive upgrade script. It includes scripts for both bees and hive. I started first with the hive, and found that most of the scripts are fairly simple. The push script looks complex and frightening at first, but on closer inspection they’ve just crammed multiple statements into the same line. Split up for readability and annotated, the script is long but not so frightening.

The biggest problem here is that this is the push script, which should feed the creatures in accordance with similar vendors, but instead it dispenses bees. I suspect this is so that you get bees upon clicking the hive, so when I swap the scripts, I’ll either have to disable that feature or find a way to conditionally react differently to the hand.

Then I moved on to the bees themselves. Whoever wrote this monstrosity should be keelhauled. 

Thanks, I hate it! I went through and added linebreaks and indentation for readability, then annotated the whole thing. You're welcome.

scrp 2 10 3 7
loop
 anim [01R]
 rndv var0 0 1
 doif var0 eq 0
  doif obv0 le 0
   gsub hunt
  endi
  doif obv0 ge 2
   wait 10
   gsub hive
  endi
  rndv var0 -1 1
  addv obv0 var0
 else
  rndv var3 10 20
  reps var3
   rndv var0 -10 10
   rndv var1 -1 -5
   mvby var0 var1
   rndv var4 1 4
   wait var4
  repe
 endi
ever

subr hunt
anim [01R]
setv var0 posl
setv var3 post
rtar 2 4 14
doif targ ne 0
 setv var1 posl
 setv var4 post
 setv objp targ
 targ ownr
 setv var6 var1
 setv var7 var4
 subv var1 var0
 subv var4 var3
 setv var5 var1
 doif var5 lt 0
  negv var5
 endi
 doif var5 lt 2100
  divv var1 200
  divv var4 50
  reps 50
   reps 4
     rndv var2 -5 5
    mvby var1 var2
   repe
   rndv var2 -2 2
   mvby var2 var4
  repe
 else
  divv var1 600
  divv var4 60
  reps 60
   reps 10
    rndv var2 -5 5
    mvby var1 var2
   repe
   rndv var2 -5 5
   mvby var2 var4
  repe
 endi
 setv var0 posl
 setv var3 post
 subv var6 var0
 subv var7 var3
 divv var6 30
 divv var7 30
 reps 30
  mvby var6 var7
 repe
 targ objp
 doif touc targ ownr gt 0
  rndv var9 0 5
  doif var9 eq 0
   mesg writ targ 1
  endi
  targ ownr
  addv obv0 1
 endi
endi
targ ownr
reps 20
 rndv var0 -5 5
 rndv var1 -5 5
 mvby var0 var1
repe
retn

subr hive
anim [01R]
setv var0 posl
setv var3 post
rtar 2 8 1
setv var1 posl
setv var4 post
setv objp targ
targ ownr
subv var1 var0
subv var4 var3
setv var5 var1
doif var5 lt 0
 negv var5
endi
doif var5 lt 2100
 divv var1 200
 divv var4 50
 reps 50
  reps 4
   rndv var2 -5 5
   mvby var1 var2
  repe
  rndv var2 -5 5
  mvby var2 var4
 repe
else
 divv var1 600
 divv var4 30
 reps 30
  reps 20
   rndv var2 -5 5
   mvby var1 var2
  repe
  rndv var2 -5 5
  mvby var2 var4
 repe
endi
setv var0 posl
setv var3 post
targ objp
setv var1 posl
setv var4 post
targ ownr
subv var1 var0
subv var4 var3
divv var1 10
divv var4 5
reps 5
 reps 2
  mvby var1 0
 repe
 mvby 0 var4
repe
setv obv0 0
retn

endm
ENTER SCOPE SCRIPT
Endless loop
{Flap wings animation
 Pick random choice of 0 or 1
 If choice is 0
 {if obv0 is 0 or less (obv0 = fullness)
  {run the hunt subroutine
  }
  if obv0 is 2 or more
  {wait for 10
   run the hive subroutine
  }
  Pick random value
  adjust obv0 accordingly
 }else (if choice is 1)
 {pick random number of repetitions
  For that many times...
  {pick random vertical value
   pick random horizontal value
   move by that amount
   pick random amount of time
   wait that amount.
  }
 }
}

HUNTING SUBROUTINE (when bee is hungry)
flap wings animation
record x position
record y position
target random beelacanth
if target exists
{record x position of plant
 record y position of plant
 set object pointer to point to this plant
 target bee again
 save plant x position
 save plant y position
 find x distance to plant
 find y distance to plant
 record soon-to-be-absolute x dist to plant
 if it's less than 0
 {negate it to make it positive
 }
 If absolute distance is less than 2100
 {divide x distance by 200
  divide y distance by 50
  for 50 repetitions
  {for 4 repetitions
   {pick random value between -5 and 5
    move toward plant in x, random y
   }
   pick random value between -2 and 2
   move toward plant in y, random x
  }
 }else (absolute distance is more than 2100)
 {divide x distance by 600
  divide y distance by 60
  for 60 repetitions
  {for 10 repetitions
   {pick random value between -5 and 5
    move toward plant in x, random y
   }
   pick random value between -5 and 5
   move toward plant in y, random x
  }
 }
 record new x position
 record new y position
 find new x distance to plant
 find new y distance to plant
 divide x distance by 30
 divide y distance by 30
 for 30 repetitions
 {move toward plant
 }
 Target beelacanth
 If the beelacanth touches the bee
 {pick random value between 0 and 5
  if that value is 0
  {beelacanth pull script
  }
  target bee again
  add 1 to obv0
 }
}
target bee
for 20 repetitions
{pick random value
 pick random value
 move by random values
}
end subroutine

HIVE SUBROUTINE (when bee is full)
flap wings animation
record x position
record y position
pick random beehive
record beehive x position
record beehive y position
set pointer to beehive
target bee again
find x distance to beehive
find y distance to beehive
save soon-to-be-absolute x distance
if it's negative
{negate it to make it positive
}
if absolute x distance is less than 2100
{divide x distance by 200
 divide y distance by 50
 for 50 repetitions
 {for 4 repetitions
  {pick random value
   move toward beehive in x, random y
  }
  pick random value
  move toward beehive in y, random x
 }
}else (distance is more than 2100)
{divide x distance by 600
 divide y distance by 30
 for 30 repetitions
 {for 20 repetitions
  {random value
   move toward hive in x, random y
  }
  random value
  move toward hive in y, random x
 }
}
find new x position
find new y position
target hive
get hive x position
get hive y position
target bee again
find new x distance
find new y distance
divide x distance by 10
divide y distance by 5
for 5 repetitions
{for 2 repetitions
 {move toward hive in x, no y change
 }
 move toward hive in y, no x change
}
set obv0 to 0, bee is no longer full
end subroutine

end script

Next I looked at the push script for the bee, which brought me to a conundrum. Creatures 1 makes no distinction between good critters and bad, and the majority of critters are neutral or good. Therefore, the bees are the oddballs that break behavioral expectations. You can’t expect a Norn to understand that carrot beetles are okay to play with but bees are not. So my options are to either make bees invisible to creatures, or try to make an entirely new object category. I wasn’t sure if that was even possible, so I threw together a test COB (using the unused microscope sprite). Sure enough, Betty the Beta Tester was able to process this as a new item type!

Not long after I had a new version of the bee and hive upgrade: one where the bees are a new type of object, and where the hive behaves similarly to other vendors (getting the hand to get different results than creatures was just a matter of a simple doif from eq pntr statement in the push script, where I triggered the pull script instead). Also, I made two versions; normally the bees at the hive have eyes but the ones that roam do not, and I made a version where they all have eyes.

Of course, the updated hive and beelacanth go hand in hand, so next on my to-do list is updating the unruly beelacanth, and I won't be releasing the beehive update until that's done!

2 comments:

  1. I LOVE that you are doing this! I'm gonna follow you around and beg for your coding scraps when you've finished them lol.
    (also... Give them poor 1996 programmers a break lol)

    ReplyDelete
    Replies
    1. Ha, you're right that I should cut them some slack since a lot of programming guidelines that I now take for granted didn't exist yet, but even so, there's no excuse for wall-of-text code with no newlines!
      Feel free to crack open any of my COBs in bobcob or your editor of choice for backwards engineering!

      Delete