Loading

Paste #pntkyfdty

  1. def Plant(World world):
  2.     int NUM_LEVELS = 5;           # 5 levels displayed plant state.
  3.     int NUM_UNITS = 72;           # 1 level is 72 units water
  4.     int FRACTION_MULTIPLY = 1024; # 1 unit water is 1024/1024 water
  5.     int INITIAL_LEVEL = (NUM_LEVELS * NUM_UNITS - 1) * FRACTION_MULTIPLY;
  6.     int WARN_LEVEL = 1;           # Level to reach before the user is warned.
  7.  
  8.     XY position = nullptr; # Position of the plant in the world (if any).
  9.     int water;             # Fractions of water for all levels.
  10.     bool warned;           # Whether the user was warned about low level.
  11.  
  12.  
  13.     # Return the level of water available for the plant. Used for drawing the plant.
  14.     function int GetLevel():
  15.         return water // (NUM_UNITS * FRACTION_MULTIPLY);
  16.     end
  17.  
  18.  
  19.     state initial:
  20.         do  water = INITIAL_LEVEL;
  21.             warned = false;
  22.             SetAnimation(GetLevel());
  23.         goto wait_drop;
  24.  
  25.     state wait_drop:
  26.         recv drop_down(XY newpos)
  27.         do  position = newpos;
  28.         goto alive;
  29.  
  30.         recv time_tick; # Ignore time while in inventory.
  31.  
  32.     state alive:
  33.         recv time_tick
  34.         do  if refreshing:
  35.                 water = water + REFRESH_AMOUNT;
  36.                 if water >= INITIAL_LEVEL:
  37.                     water = INITIAL_LEVEL;
  38.                     refreshing = false;
  39.                     warned = false;
  40.                 end
  41.             else:
  42.                 water = water - position.GetTemperature();
  43.                 if water < 0: water = 0; end;
  44.             end;
  45.             SetAnimation(GetLevel());
  46.  
  47.             if not warned and GetLevel() <= WARN_LEVEL:
  48.                 ui.WarnUser("Plant at %s has low water level", position);
  49.             end;
  50.  
  51.         recv refresh_water:
  52.             refreshing = true;
  53.  
  54.         recv pick_up:
  55.         do  position = nullptr;
  56.         goto wait_drop;
  57.  
  58. end

Comments