Special Order Package

From Gwen Morse's Wiki
Jump to: navigation, search

Needs Galvin's Virtual Array as well as /Note, /Cut, and Susan's Lists and Susan's Arrays Macros

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Special Order Handling
;;;
;;; Samples of in-game special orders
;;;
;;; #    PATTERN      SIZE  color       SHAPE         CLARITY  MARKETER    VALUE
;;; 3188 5 chord      vs    vp yellow    cylinder      p        Nathaniel   166
;;; 3060 2 x octave   s     d amethyst   octagon       p        Darby       9196
;;; 3167 3 row        s     d rose       pentagon      p        Nathaniel   163
;;; 3195 2 x Single   t     l green      cylinder      f        Nathaniel   129
;;;
;;; %P1=order number // %P2=pattern // %P3=size // %P4=shade // %P5=color // %P6=shape
;;; %P7=clarity //%P8= Marketer (not needed) %P9=value (only for sorter +mail)
;;; %P10=SO_NUMGROUPS

/set warn_curly_re=off

;;; Special Order help
;;;
;;;
;;;

/help_add /help_orders CrystalMUSH Special Orders

/def -i help_orders=\
  /_echo%;\
  /echo -aB CrystalMUSH Special Order Help: %;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def -T"tiny.mush.cm.*" -F orderhelp = \
  /_echo%;\
  /echo -aBCcyan This is the help for the CrystalMUSH Special Order Macros%;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def print_so_list = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {MATCH_COLOR} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /elseif (!strlen(%{MATCH}) & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def print_so_match = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {VEIN_COLOR} & {TEMP_SHADE} =/ {VEIN_SHADE} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0"))\
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def orderlist = \
  /let MATCH=%*%;\
  /if (regmatch((rose|blue|green|yellow|amethyst|black|white),{MATCH}) & (strlen({MATCH}))) \
    /set MATCH_COLOR=%{MATCH}%;\
  /endif %;\
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_list%;\
  /_echo %;\
  /unset MATCH%;\
  /unset MATCH_COLOR

/def ordermatch = \
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_match%;\
  /_echo

/def orderflush = \
  /_echo %;\ /echo -w -aBCcyan TFRC: Flushing the contents of the Special Order List%;\
/purge_array so

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Learn the the special order(s) from the chit or terminal
;;;

;; /def -F -p30 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9A-Za-z ]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \

/def -p100 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9a-zA-Z ]*[a-zA-Z]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \
      /set SO_NUM=%P1%;\
      /set SO_PATTERN=%P2%;\
      /set SO_SIZE=%P3%;\
      /set SO_SHADE=%P4%;\
      /set SO_COLOR=%P5%;\
      /set SO_SHAPE=%P6%;\
      /set SO_CLARITY=%P7%;\
      /set SO_MARKETER=%P8%;\
      /set SO_VALUE=%P9%;\
        /if (regmatch(' x ',%{P2})) \
                /set SO_NUMGROUPS=%PL%; \
                /set SO_PATTERN=%PR%; \
        /else \
                /set SO_NUMGROUPS=1%; \
        /endif%;\
        /if (%{SO_SHADE} =/ "vp") \
          /set SO_SHADE=very pale%;\
        /elseif (%{SO_SHADE} =/ "l") \
          /set SO_SHADE=light%;\
        /elseif (%{SO_SHADE} =/ "m") \
          /set SO_SHADE=medium%;\
        /elseif (%{SO_SHADE} =/ "d") \
          /set SO_SHADE=deep%;\
        /elseif (%{SO_SHADE} =/ "rd") \
          /set SO_SHADE=rich deep%;\
          /set CUT_SCALE=do%;\
        /elseif (%{SO_SHADE} =/ "p") \
                /if (%{SO_COLOR} =/ "white") \
                        /set SO_SHADE=pure%;\
                /elseif (%{SO_COLOR} =/ "black") \
                        /set SO_SHADE=pure%;\
                /else \
                        /set SO_SHADE=pale%;\
                /endif%;\
        /endif%;\
        /if (%{SO_CLARITY} =/ "p") \
                /set SO_CLARITY2=perfect%;\
                /set SO_CLARITY_LIST=perfect%;\
        /elseif (%{SO_CLARITY} =/ "vsf") \
                /set SO_CLARITY2=very slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "sf") \
                /set SO_CLARITY2=slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "f") \
                /set SO_CLARITY2=flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed%;\
        /elseif (%{SO_CLARITY} =/ "mf") \
                /set SO_CLARITY2=majorly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed|majorly flawed%;\
        /else \
              /echo -w -aBCcyan SPECIAL ORDER: Flaw match broken. %;\
        /endif%;\
        /eval /set _array_so_$[SO_NUM]_0=$[SO_PATTERN]%;\
        /eval /set _array_so_$[SO_NUM]_1=$[SO_SIZE]%;\
        /eval /set _array_so_$[SO_NUM]_2=$[SO_SHADE]%;\
        /eval /set _array_so_$[SO_NUM]_3=$[SO_COLOR]%;\
        /eval /set _array_so_$[SO_NUM]_4=$[SO_SHAPE]%;\
        /eval /set _array_so_$[SO_NUM]_5=$[SO_CLARITY2]%;\
        /eval /set _array_so_$[SO_NUM]_6=$[SO_MARKETER]%;\
        /eval /set _array_so_$[SO_NUM]_7=$[SO_VALUE]%;\
        /eval /set _array_so_$[SO_NUM]_8=$[SO_NUMGROUPS]%;\
        /eval /set _array_so_$[SO_NUM]_9=$[SO_CLARITY_LIST]%;\
        /eval /set _array_so_$[SO_NUM]_10=$[SO_NUMGROUPS] | $[SO_SIZE] | $[SO_PATTERN] | $[SO_SHADE] |$[SO_COLOR] | $[SO_SHAPE] | $[SO_CLARITY]  %;\
        /eval /set _array_so_$[SO_NUM]_11=$[SO_CLARITY]%;\
        /if (strlen({SO_ACCEPTFLAG})) \
          /if (!strlen({_array_so_accepted})) \
            /set _array_so_accepted=|%;\
            /addlist _array_so_accepted %{SO_NUM}%;\
          /else \
            /addlist _array_so_accepted %{SO_NUM}%;\
          /endif %;\
        /else \
          /addlist _array_so_list %{SO_NUM}%;\
        /endif

;; check if scanning for Special Order that have already been accepted.

/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'This terminal is totally dedicated to printing out work chits for specially ordered crystal.  At the touch of a button, the screen scrolls up to list the open orders*' so_trig_accept = \
        /repeat -1 1 /send -w scan accepted list


/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'* Orders Under Competition *' so_accept = \
        /set SO_ACCEPTFLAG=yes%;\
        /repeat -2 1 /unset SO_ACCEPTFLAG

;;; 9/13/2011 Fixed orderfill so it no longer shares variable names with the 
;;; SO chit code. This means SOs in the cut queue will not be mixed with 
;;; SO chits being handled by an alternate Sorter character.

;;; Kahlyla reminded me of a bug where SO's sometimes recut flaw acceptable to
;;; the SO. Recut VSF in a SO that needed MF or better.

/def -T"tiny.mush.cm.sing" orderfill = \
  /unset TEST_ORDERNUM%;\
  /set TEST_ORDERNUM=%{*}%;\
  /set FILLSO_NUM=%{*}%;\
  /unset RECUT_LIST%;\
  /unset CUT_NOTE%;\
  /unset CUT_SCALE%;\
  /eval /set FILLSO_SIZE=$[get_2array("so",$[FILLSO_NUM], 1)]%;\
  /eval /set FILLSO_SHADE=$[get_2array("so",$[FILLSO_NUM], 2)]%;\
  /eval /set FILLSO_COLOR=$[get_2array("so",$[FILLSO_NUM], 3)]%;\
  /eval /set FILLSO_SHAPE=$[get_2array("so",$[FILLSO_NUM], 4)]%;\
  /eval /set FILLSO_PATTERN=$[get_2array("so",$[FILLSO_NUM], 0)]%;\
  /eval /set FILLSO_NUMGROUPS=$[get_2array("so",$[FILLSO_NUM], 8)]%;\
  /eval /set FILLSO_CLARITY_LIST=$[get_2array("so",$[FILLSO_NUM], 9)]%;\
  /eval /set FILLSO_CLARITY=$[get_2array("so",$[FILLSO_NUM], 11)]%;\
  /if (!regmatch('[0-9]{4}',%{TEST_ORDERNUM}))%;\
    /_echo %;\
    /echo -w -aBCred SPECIAL ORDER: You didn't enter a proper special order number. The syntaxt is '/orderfill <SO Number>'. %;\
    /_echo %;\
  /elseif (%{FILLSO_SHADE}!/%{VEIN_SHADE})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_SHADE}" vein shade does not match the shade on Special Order: %{FILLSO_SHADE}.%;\
  /elseif (%{FILLSO_COLOR}!/%{VEIN_COLOR})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_COLOR}" vein color does not match the color on Special Order: %{FILLSO_COLOR}.%;\
  /else \
    /_echo %;\
    /echo -w -aBCcyan -p SPECIAL ORDER: The Special Order details match. If the vein is large enough, you can fill this order here. %{FILLSO_NUMGROUPS} x %{FILLSO_PATTERN} %{FILLSO_SIZE} %{FILLSO_SHAPE} %{FILLSO_CLARITY} for CREDITS: %{FILLSO_VALUE}%;\
    /test regmatch('(3 chord|4 chord|5 chord|3 row|4 row|5 row|octave|single)',"%{FILLSO_PATTERN}")%;\
    /let CUT_GROUP=%{P1}%;\
    /if (%{CUT_GROUP} =/ "octave") \
      /set CUT_SCALE=do mi so dx ti re fa la%;\
    /elseif (%{CUT_GROUP} =/ "3 chord") \
      /set CUT_SCALE=do mi so%;\
    /elseif (%{CUT_GROUP} =/ "4 chord") \
      /set CUT_SCALE=do mi so dx%;\
    /elseif (%{CUT_GROUP} =/ "5 chord") \
      /set CUT_SCALE=do mi so dx ti%;\
    /elseif (%{CUT_GROUP} =/ "3 row") \
      /set CUT_SCALE=do re mi%;\
    /elseif (%{CUT_GROUP} =/ "4 row") \
      /set CUT_SCALE=do re mi fa%;\
    /elseif (%{CUT_GROUP} =/ "5 row") \
      /set CUT_SCALE=do re mi fa so%;\
    /elseif (%{CUT_GROUP} =/ "single") \
      /set CUT_SCALE=do%;\
    /endif %;\
    /if (%{FILLSO_NUMGROUPS} =/ "2") \
    /set CUT_SCALE=%{CUT_SCALE} %{CUT_SCALE}%;\
    /endif %;\
    /repeat -3 -w 1 /so_loop %{CUT_SCALE}%;\
    /endif


;;;; 9/17/2011 fixed so_loop to make unsetting TEST_ORDERNUM
;;;; slow enough that the order number is added to the
;;;; list of accepted special orders.

/def so_loop = \
  /if (CUT_CARTON =~ "yes") \
    /beep 1 %;\
    /echo -w -arBCred SPECIAL ORDER: Cutting paused because you need a fresh carton. Type '/cut resume' when ready.%;\
    /repeat -w -130 1 /so_loop %{*} %;\
    /set CUT_PID=%?%;\
  /elseif ({#}) \
    /note %{1} %; \
    /set FILLSO_NOTE=%{1}%; \
    /send -w cut %{FILLSO_SHAPE} size=%{FILLSO_SIZE}%; \
    /shift %; \
    /repeat -w -130 1 /so_loop %{*} %; \
    /set CUT_PID=%?%; \
  /else \
    /if (strlen(%{RECUT_LIST})) \
      /echo -w -aBCcyan SPECIAL ORDER: Recutting flawed crystals now.%;\
      /repeat -2 -w 1 /so_loop %{TEMP_RECUT}%; \
      /unset RECUT_LIST%; \
    /else \
      /echo -w -aBCcyan SPECIAL ORDER: Special order %{TEST_ORDERNUM} is done.%;\
      /addlist _array_so_accepted %{TEST_ORDERNUM}%;\
      /quote -S /unset `/listvar -mglob -s FILLSO_* %;\
      /repeat -w -1 1 /unset TEST_ORDERNUM%;\
    /endif%;\
  /endif;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Special Order Handling
;;;
;;; Samples of in-game special orders
;;;
;;; #    PATTERN      SIZE  color       SHAPE         CLARITY  MARKETER    VALUE
;;; 3188 5 chord      vs    vp yellow    cylinder      p        Nathaniel   166
;;; 3060 2 x octave   s     d amethyst   octagon       p        Darby       9196
;;; 3167 3 row        s     d rose       pentagon      p        Nathaniel   163
;;; 3195 2 x Single   t     l green      cylinder      f        Nathaniel   129
;;;
;;; %P1=order number // %P2=pattern // %P3=size // %P4=shade // %P5=color // %P6=shape
;;; %P7=clarity //%P8= Marketer (not needed) %P9=value (only for sorter +mail)
;;; %P10=SO_NUMGROUPS

/set warn_curly_re=off

;;; Special Order help
;;;
;;;
;;;

/help_add /help_orders CrystalMUSH Special Orders

/def -i help_orders=\
  /_echo%;\
  /echo -aB CrystalMUSH Special Order Help: %;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def -T"tiny.mush.cm.*" -F orderhelp = \
  /_echo%;\
  /echo -aBCcyan This is the help for the CrystalMUSH Special Order Macros%;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def print_so_list = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {MATCH_COLOR} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /elseif (!strlen(%{MATCH}) & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def print_so_match = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {VEIN_COLOR} & {TEMP_SHADE} =/ {VEIN_SHADE} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0"))\
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def orderlist = \
  /let MATCH=%*%;\
  /if (regmatch((rose|blue|green|yellow|amethyst|black|white),{MATCH}) & (strlen({MATCH}))) \
    /set MATCH_COLOR=%{MATCH}%;\
  /endif %;\
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_list%;\
  /_echo %;\
  /unset MATCH%;\
  /unset MATCH_COLOR

/def ordermatch = \
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_match%;\
  /_echo

/def orderflush = \
  /_echo %;\ /echo -w -aBCcyan TFRC: Flushing the contents of the Special Order List%;\
/purge_array so

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Learn the the special order(s) from the chit or terminal
;;;

;; /def -F -p30 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9A-Za-z ]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \

/def -p100 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9a-zA-Z ]*[a-zA-Z]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \
      /set SO_NUM=%P1%;\
      /set SO_PATTERN=%P2%;\
      /set SO_SIZE=%P3%;\
      /set SO_SHADE=%P4%;\
      /set SO_COLOR=%P5%;\
      /set SO_SHAPE=%P6%;\
      /set SO_CLARITY=%P7%;\
      /set SO_MARKETER=%P8%;\
      /set SO_VALUE=%P9%;\
        /if (regmatch(' x ',%{P2})) \
                /set SO_NUMGROUPS=%PL%; \
                /set SO_PATTERN=%PR%; \
        /else \
                /set SO_NUMGROUPS=1%; \
        /endif%;\
        /if (%{SO_SHADE} =/ "vp") \
          /set SO_SHADE=very pale%;\
        /elseif (%{SO_SHADE} =/ "l") \
          /set SO_SHADE=light%;\
        /elseif (%{SO_SHADE} =/ "m") \
          /set SO_SHADE=medium%;\
        /elseif (%{SO_SHADE} =/ "d") \
          /set SO_SHADE=deep%;\
        /elseif (%{SO_SHADE} =/ "rd") \
          /set SO_SHADE=rich deep%;\
          /set CUT_SCALE=do%;\
        /elseif (%{SO_SHADE} =/ "p") \
                /if (%{SO_COLOR} =/ "white") \
                        /set SO_SHADE=pure%;\
                /elseif (%{SO_COLOR} =/ "black") \
                        /set SO_SHADE=pure%;\
                /else \
                        /set SO_SHADE=pale%;\
                /endif%;\
        /endif%;\
        /if (%{SO_CLARITY} =/ "p") \
                /set SO_CLARITY2=perfect%;\
                /set SO_CLARITY_LIST=perfect%;\
        /elseif (%{SO_CLARITY} =/ "vsf") \
                /set SO_CLARITY2=very slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "sf") \
                /set SO_CLARITY2=slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "f") \
                /set SO_CLARITY2=flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed%;\
        /elseif (%{SO_CLARITY} =/ "mf") \
                /set SO_CLARITY2=majorly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed|majorly flawed%;\
        /else \
              /echo -w -aBCcyan SPECIAL ORDER: Flaw match broken. %;\
        /endif%;\
        /eval /set _array_so_$[SO_NUM]_0=$[SO_PATTERN]%;\
        /eval /set _array_so_$[SO_NUM]_1=$[SO_SIZE]%;\
        /eval /set _array_so_$[SO_NUM]_2=$[SO_SHADE]%;\
        /eval /set _array_so_$[SO_NUM]_3=$[SO_COLOR]%;\
        /eval /set _array_so_$[SO_NUM]_4=$[SO_SHAPE]%;\
        /eval /set _array_so_$[SO_NUM]_5=$[SO_CLARITY2]%;\
        /eval /set _array_so_$[SO_NUM]_6=$[SO_MARKETER]%;\
        /eval /set _array_so_$[SO_NUM]_7=$[SO_VALUE]%;\
        /eval /set _array_so_$[SO_NUM]_8=$[SO_NUMGROUPS]%;\
        /eval /set _array_so_$[SO_NUM]_9=$[SO_CLARITY_LIST]%;\
        /eval /set _array_so_$[SO_NUM]_10=$[SO_NUMGROUPS] | $[SO_SIZE] | $[SO_PATTERN] | $[SO_SHADE] |$[SO_COLOR] | $[SO_SHAPE] | $[SO_CLARITY]  %;\
        /eval /set _array_so_$[SO_NUM]_11=$[SO_CLARITY]%;\
        /if (strlen({SO_ACCEPTFLAG})) \
          /if (!strlen({_array_so_accepted})) \
            /set _array_so_accepted=|%;\
            /addlist _array_so_accepted %{SO_NUM}%;\
          /else \
            /addlist _array_so_accepted %{SO_NUM}%;\
          /endif %;\
        /else \
          /addlist _array_so_list %{SO_NUM}%;\
        /endif

;; check if scanning for Special Order that have already been accepted.

/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'This terminal is totally dedicated to printing out work chits for specially ordered crystal.  At the touch of a button, the screen scrolls up to list the open orders*' so_trig_accept = \
        /repeat -1 1 /send -w scan accepted list


/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'* Orders Under Competition *' so_accept = \
        /set SO_ACCEPTFLAG=yes%;\
        /repeat -2 1 /unset SO_ACCEPTFLAG

;;; 9/13/2011 Fixed orderfill so it no longer shares variable names with the 
;;; SO chit code. This means SOs in the cut queue will not be mixed with 
;;; SO chits being handled by an alternate Sorter character.

;;; Kahlyla reminded me of a bug where SO's sometimes recut flaw acceptable to
;;; the SO. Recut VSF in a SO that needed MF or better.

/def -T"tiny.mush.cm.sing" orderfill = \
  /unset TEST_ORDERNUM%;\
  /set TEST_ORDERNUM=%{*}%;\
  /set FILLSO_NUM=%{*}%;\
  /unset RECUT_LIST%;\
  /unset CUT_NOTE%;\
  /unset CUT_SCALE%;\
  /eval /set FILLSO_SIZE=$[get_2array("so",$[FILLSO_NUM], 1)]%;\
  /eval /set FILLSO_SHADE=$[get_2array("so",$[FILLSO_NUM], 2)]%;\
  /eval /set FILLSO_COLOR=$[get_2array("so",$[FILLSO_NUM], 3)]%;\
  /eval /set FILLSO_SHAPE=$[get_2array("so",$[FILLSO_NUM], 4)]%;\
  /eval /set FILLSO_PATTERN=$[get_2array("so",$[FILLSO_NUM], 0)]%;\
  /eval /set FILLSO_NUMGROUPS=$[get_2array("so",$[FILLSO_NUM], 8)]%;\
  /eval /set FILLSO_CLARITY_LIST=$[get_2array("so",$[FILLSO_NUM], 9)]%;\
  /eval /set FILLSO_CLARITY=$[get_2array("so",$[FILLSO_NUM], 11)]%;\
  /if (!regmatch('[0-9]{4}',%{TEST_ORDERNUM}))%;\
    /_echo %;\
    /echo -w -aBCred SPECIAL ORDER: You didn't enter a proper special order number. The syntaxt is '/orderfill <SO Number>'. %;\
    /_echo %;\
  /elseif (%{FILLSO_SHADE}!/%{VEIN_SHADE})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_SHADE}" vein shade does not match the shade on Special Order: %{FILLSO_SHADE}.%;\
  /elseif (%{FILLSO_COLOR}!/%{VEIN_COLOR})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_COLOR}" vein color does not match the color on Special Order: %{FILLSO_COLOR}.%;\
  /else \
    /_echo %;\
    /echo -w -aBCcyan -p SPECIAL ORDER: The Special Order details match. If the vein is large enough, you can fill this order here. %{FILLSO_NUMGROUPS} x %{FILLSO_PATTERN} %{FILLSO_SIZE} %{FILLSO_SHAPE} %{FILLSO_CLARITY} for CREDITS: %{FILLSO_VALUE}%;\
    /test regmatch('(3 chord|4 chord|5 chord|3 row|4 row|5 row|octave|single)',"%{FILLSO_PATTERN}")%;\
    /let CUT_GROUP=%{P1}%;\
    /if (%{CUT_GROUP} =/ "octave") \
      /set CUT_SCALE=do mi so dx ti re fa la%;\
    /elseif (%{CUT_GROUP} =/ "3 chord") \
      /set CUT_SCALE=do mi so%;\
    /elseif (%{CUT_GROUP} =/ "4 chord") \
      /set CUT_SCALE=do mi so dx%;\
    /elseif (%{CUT_GROUP} =/ "5 chord") \
      /set CUT_SCALE=do mi so dx ti%;\
    /elseif (%{CUT_GROUP} =/ "3 row") \
      /set CUT_SCALE=do re mi%;\
    /elseif (%{CUT_GROUP} =/ "4 row") \
      /set CUT_SCALE=do re mi fa%;\
    /elseif (%{CUT_GROUP} =/ "5 row") \
      /set CUT_SCALE=do re mi fa so%;\
    /elseif (%{CUT_GROUP} =/ "single") \
      /set CUT_SCALE=do%;\
    /endif %;\
    /if (%{FILLSO_NUMGROUPS} =/ "2") \
    /set CUT_SCALE=%{CUT_SCALE} %{CUT_SCALE}%;\
    /endif %;\
    /repeat -3 -w 1 /so_loop %{CUT_SCALE}%;\
    /endif


;;;; 9/17/2011 fixed so_loop to make unsetting TEST_ORDERNUM
;;;; slow enough that the order number is added to the
;;;; list of accepted special orders.

/def so_loop = \
  /if (CUT_CARTON =~ "yes") \
    /beep 1 %;\
    /echo -w -arBCred SPECIAL ORDER: Cutting paused because you need a fresh carton. Type '/cut resume' when ready.%;\
    /repeat -w -130 1 /so_loop %{*} %;\
    /set CUT_PID=%?%;\
  /elseif ({#}) \
    /note %{1} %; \
    /set FILLSO_NOTE=%{1}%; \
    /send -w cut %{FILLSO_SHAPE} size=%{FILLSO_SIZE}%; \
    /shift %; \
    /repeat -w -130 1 /so_loop %{*} %; \
    /set CUT_PID=%?%; \
  /else \
    /if (strlen(%{RECUT_LIST})) \
      /echo -w -aBCcyan SPECIAL ORDER: Recutting flawed crystals now.%;\
      /repeat -2 -w 1 /so_loop %{TEMP_RECUT}%; \
      /unset RECUT_LIST%; \
    /else \
      /echo -w -aBCcyan SPECIAL ORDER: Special order %{TEST_ORDERNUM} is done.%;\
      /addlist _array_so_accepted %{TEST_ORDERNUM}%;\
      /quote -S /unset `/listvar -mglob -s FILLSO_* %;\
      /repeat -w -1 1 /unset TEST_ORDERNUM%;\
    /endif%;\
  /endif;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Special Order Handling
;;;
;;; Samples of in-game special orders
;;;
;;; #    PATTERN      SIZE  color       SHAPE         CLARITY  MARKETER    VALUE
;;; 3188 5 chord      vs    vp yellow    cylinder      p        Nathaniel   166
;;; 3060 2 x octave   s     d amethyst   octagon       p        Darby       9196
;;; 3167 3 row        s     d rose       pentagon      p        Nathaniel   163
;;; 3195 2 x Single   t     l green      cylinder      f        Nathaniel   129
;;;
;;; %P1=order number // %P2=pattern // %P3=size // %P4=shade // %P5=color // %P6=shape
;;; %P7=clarity //%P8= Marketer (not needed) %P9=value (only for sorter +mail)
;;; %P10=SO_NUMGROUPS

/set warn_curly_re=off

;;; Special Order help
;;;
;;;
;;;

/help_add /help_orders CrystalMUSH Special Orders

/def -i help_orders=\
  /_echo%;\
  /echo -aB CrystalMUSH Special Order Help: %;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def -T"tiny.mush.cm.*" -F orderhelp = \
  /_echo%;\
  /echo -aBCcyan This is the help for the CrystalMUSH Special Order Macros%;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def print_so_list = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {MATCH_COLOR} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /elseif (!strlen(%{MATCH}) & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def print_so_match = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {VEIN_COLOR} & {TEMP_SHADE} =/ {VEIN_SHADE} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0"))\
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def orderlist = \
  /let MATCH=%*%;\
  /if (regmatch((rose|blue|green|yellow|amethyst|black|white),{MATCH}) & (strlen({MATCH}))) \
    /set MATCH_COLOR=%{MATCH}%;\
  /endif %;\
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_list%;\
  /_echo %;\
  /unset MATCH%;\
  /unset MATCH_COLOR

/def ordermatch = \
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_match%;\
  /_echo

/def orderflush = \
  /_echo %;\ /echo -w -aBCcyan TFRC: Flushing the contents of the Special Order List%;\
/purge_array so

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Learn the the special order(s) from the chit or terminal
;;;

;; /def -F -p30 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9A-Za-z ]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \

/def -p100 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9a-zA-Z ]*[a-zA-Z]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \
      /set SO_NUM=%P1%;\
      /set SO_PATTERN=%P2%;\
      /set SO_SIZE=%P3%;\
      /set SO_SHADE=%P4%;\
      /set SO_COLOR=%P5%;\
      /set SO_SHAPE=%P6%;\
      /set SO_CLARITY=%P7%;\
      /set SO_MARKETER=%P8%;\
      /set SO_VALUE=%P9%;\
        /if (regmatch(' x ',%{P2})) \
                /set SO_NUMGROUPS=%PL%; \
                /set SO_PATTERN=%PR%; \
        /else \
                /set SO_NUMGROUPS=1%; \
        /endif%;\
        /if (%{SO_SHADE} =/ "vp") \
          /set SO_SHADE=very pale%;\
        /elseif (%{SO_SHADE} =/ "l") \
          /set SO_SHADE=light%;\
        /elseif (%{SO_SHADE} =/ "m") \
          /set SO_SHADE=medium%;\
        /elseif (%{SO_SHADE} =/ "d") \
          /set SO_SHADE=deep%;\
        /elseif (%{SO_SHADE} =/ "rd") \
          /set SO_SHADE=rich deep%;\
          /set CUT_SCALE=do%;\
        /elseif (%{SO_SHADE} =/ "p") \
                /if (%{SO_COLOR} =/ "white") \
                        /set SO_SHADE=pure%;\
                /elseif (%{SO_COLOR} =/ "black") \
                        /set SO_SHADE=pure%;\
                /else \
                        /set SO_SHADE=pale%;\
                /endif%;\
        /endif%;\
        /if (%{SO_CLARITY} =/ "p") \
                /set SO_CLARITY2=perfect%;\
                /set SO_CLARITY_LIST=perfect%;\
        /elseif (%{SO_CLARITY} =/ "vsf") \
                /set SO_CLARITY2=very slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "sf") \
                /set SO_CLARITY2=slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "f") \
                /set SO_CLARITY2=flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed%;\
        /elseif (%{SO_CLARITY} =/ "mf") \
                /set SO_CLARITY2=majorly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed|majorly flawed%;\
        /else \
              /echo -w -aBCcyan SPECIAL ORDER: Flaw match broken. %;\
        /endif%;\
        /eval /set _array_so_$[SO_NUM]_0=$[SO_PATTERN]%;\
        /eval /set _array_so_$[SO_NUM]_1=$[SO_SIZE]%;\
        /eval /set _array_so_$[SO_NUM]_2=$[SO_SHADE]%;\
        /eval /set _array_so_$[SO_NUM]_3=$[SO_COLOR]%;\
        /eval /set _array_so_$[SO_NUM]_4=$[SO_SHAPE]%;\
        /eval /set _array_so_$[SO_NUM]_5=$[SO_CLARITY2]%;\
        /eval /set _array_so_$[SO_NUM]_6=$[SO_MARKETER]%;\
        /eval /set _array_so_$[SO_NUM]_7=$[SO_VALUE]%;\
        /eval /set _array_so_$[SO_NUM]_8=$[SO_NUMGROUPS]%;\
        /eval /set _array_so_$[SO_NUM]_9=$[SO_CLARITY_LIST]%;\
        /eval /set _array_so_$[SO_NUM]_10=$[SO_NUMGROUPS] | $[SO_SIZE] | $[SO_PATTERN] | $[SO_SHADE] |$[SO_COLOR] | $[SO_SHAPE] | $[SO_CLARITY]  %;\
        /eval /set _array_so_$[SO_NUM]_11=$[SO_CLARITY]%;\
        /if (strlen({SO_ACCEPTFLAG})) \
          /if (!strlen({_array_so_accepted})) \
            /set _array_so_accepted=|%;\
            /addlist _array_so_accepted %{SO_NUM}%;\
          /else \
            /addlist _array_so_accepted %{SO_NUM}%;\
          /endif %;\
        /else \
          /addlist _array_so_list %{SO_NUM}%;\
        /endif

;; check if scanning for Special Order that have already been accepted.

/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'This terminal is totally dedicated to printing out work chits for specially ordered crystal.  At the touch of a button, the screen scrolls up to list the open orders*' so_trig_accept = \
        /repeat -1 1 /send -w scan accepted list


/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'* Orders Under Competition *' so_accept = \
        /set SO_ACCEPTFLAG=yes%;\
        /repeat -2 1 /unset SO_ACCEPTFLAG

;;; 9/13/2011 Fixed orderfill so it no longer shares variable names with the 
;;; SO chit code. This means SOs in the cut queue will not be mixed with 
;;; SO chits being handled by an alternate Sorter character.

;;; Kahlyla reminded me of a bug where SO's sometimes recut flaw acceptable to
;;; the SO. Recut VSF in a SO that needed MF or better.

/def -T"tiny.mush.cm.sing" orderfill = \
  /unset TEST_ORDERNUM%;\
  /set TEST_ORDERNUM=%{*}%;\
  /set FILLSO_NUM=%{*}%;\
  /unset RECUT_LIST%;\
  /unset CUT_NOTE%;\
  /unset CUT_SCALE%;\
  /eval /set FILLSO_SIZE=$[get_2array("so",$[FILLSO_NUM], 1)]%;\
  /eval /set FILLSO_SHADE=$[get_2array("so",$[FILLSO_NUM], 2)]%;\
  /eval /set FILLSO_COLOR=$[get_2array("so",$[FILLSO_NUM], 3)]%;\
  /eval /set FILLSO_SHAPE=$[get_2array("so",$[FILLSO_NUM], 4)]%;\
  /eval /set FILLSO_PATTERN=$[get_2array("so",$[FILLSO_NUM], 0)]%;\
  /eval /set FILLSO_NUMGROUPS=$[get_2array("so",$[FILLSO_NUM], 8)]%;\
  /eval /set FILLSO_CLARITY_LIST=$[get_2array("so",$[FILLSO_NUM], 9)]%;\
  /eval /set FILLSO_CLARITY=$[get_2array("so",$[FILLSO_NUM], 11)]%;\
  /if (!regmatch('[0-9]{4}',%{TEST_ORDERNUM}))%;\
    /_echo %;\
    /echo -w -aBCred SPECIAL ORDER: You didn't enter a proper special order number. The syntaxt is '/orderfill <SO Number>'. %;\
    /_echo %;\
  /elseif (%{FILLSO_SHADE}!/%{VEIN_SHADE})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_SHADE}" vein shade does not match the shade on Special Order: %{FILLSO_SHADE}.%;\
  /elseif (%{FILLSO_COLOR}!/%{VEIN_COLOR})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_COLOR}" vein color does not match the color on Special Order: %{FILLSO_COLOR}.%;\
  /else \
    /_echo %;\
    /echo -w -aBCcyan -p SPECIAL ORDER: The Special Order details match. If the vein is large enough, you can fill this order here. %{FILLSO_NUMGROUPS} x %{FILLSO_PATTERN} %{FILLSO_SIZE} %{FILLSO_SHAPE} %{FILLSO_CLARITY} for CREDITS: %{FILLSO_VALUE}%;\
    /test regmatch('(3 chord|4 chord|5 chord|3 row|4 row|5 row|octave|single)',"%{FILLSO_PATTERN}")%;\
    /let CUT_GROUP=%{P1}%;\
    /if (%{CUT_GROUP} =/ "octave") \
      /set CUT_SCALE=do mi so dx ti re fa la%;\
    /elseif (%{CUT_GROUP} =/ "3 chord") \
      /set CUT_SCALE=do mi so%;\
    /elseif (%{CUT_GROUP} =/ "4 chord") \
      /set CUT_SCALE=do mi so dx%;\
    /elseif (%{CUT_GROUP} =/ "5 chord") \
      /set CUT_SCALE=do mi so dx ti%;\
    /elseif (%{CUT_GROUP} =/ "3 row") \
      /set CUT_SCALE=do re mi%;\
    /elseif (%{CUT_GROUP} =/ "4 row") \
      /set CUT_SCALE=do re mi fa%;\
    /elseif (%{CUT_GROUP} =/ "5 row") \
      /set CUT_SCALE=do re mi fa so%;\
    /elseif (%{CUT_GROUP} =/ "single") \
      /set CUT_SCALE=do%;\
    /endif %;\
    /if (%{FILLSO_NUMGROUPS} =/ "2") \
    /set CUT_SCALE=%{CUT_SCALE} %{CUT_SCALE}%;\
    /endif %;\
    /repeat -3 -w 1 /so_loop %{CUT_SCALE}%;\
    /endif


;;;; 9/17/2011 fixed so_loop to make unsetting TEST_ORDERNUM
;;;; slow enough that the order number is added to the
;;;; list of accepted special orders.

/def so_loop = \
  /if (CUT_CARTON =~ "yes") \
    /beep 1 %;\
    /echo -w -arBCred SPECIAL ORDER: Cutting paused because you need a fresh carton. Type '/cut resume' when ready.%;\
    /repeat -w -130 1 /so_loop %{*} %;\
    /set CUT_PID=%?%;\
  /elseif ({#}) \
    /note %{1} %; \
    /set FILLSO_NOTE=%{1}%; \
    /send -w cut %{FILLSO_SHAPE} size=%{FILLSO_SIZE}%; \
    /shift %; \
    /repeat -w -130 1 /so_loop %{*} %; \
    /set CUT_PID=%?%; \
  /else \
    /if (strlen(%{RECUT_LIST})) \
      /echo -w -aBCcyan SPECIAL ORDER: Recutting flawed crystals now.%;\
      /repeat -2 -w 1 /so_loop %{TEMP_RECUT}%; \
      /unset RECUT_LIST%; \
    /else \
      /echo -w -aBCcyan SPECIAL ORDER: Special order %{TEST_ORDERNUM} is done.%;\
      /addlist _array_so_accepted %{TEST_ORDERNUM}%;\
      /quote -S /unset `/listvar -mglob -s FILLSO_* %;\
      /repeat -w -1 1 /unset TEST_ORDERNUM%;\
    /endif%;\
  /endif;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Special Order Handling
;;;
;;; Samples of in-game special orders
;;;
;;; #    PATTERN      SIZE  color       SHAPE         CLARITY  MARKETER    VALUE
;;; 3188 5 chord      vs    vp yellow    cylinder      p        Nathaniel   166
;;; 3060 2 x octave   s     d amethyst   octagon       p        Darby       9196
;;; 3167 3 row        s     d rose       pentagon      p        Nathaniel   163
;;; 3195 2 x Single   t     l green      cylinder      f        Nathaniel   129
;;;
;;; %P1=order number // %P2=pattern // %P3=size // %P4=shade // %P5=color // %P6=shape
;;; %P7=clarity //%P8= Marketer (not needed) %P9=value (only for sorter +mail)
;;; %P10=SO_NUMGROUPS

/set warn_curly_re=off

;;; Special Order help
;;;
;;;
;;;

/help_add /help_orders CrystalMUSH Special Orders

/def -i help_orders=\
  /_echo%;\
  /echo -aB CrystalMUSH Special Order Help: %;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def -T"tiny.mush.cm.*" -F orderhelp = \
  /_echo%;\
  /echo -aBCcyan This is the help for the CrystalMUSH Special Order Macros%;\
  /_echo To learn the special orders, look at any Special Order terminal or type 'scan all list' in your sled with a special order uplink installed.%;\
  /_echo If you're carrying one or more Special Order chits, you can also learn the specifications of those orders by simply looking at each chit.%;\
  /_echo Type '/orderfill <number>' to start automatically cutting a Special Order by number.%;\
  /_echo Type '/orderlist <color>' to list all the Special Orders of a particular color.%;\
  /_echo Type '/ordermatch' while in a vein to see special orders that match that color and shade.%;\
  /_echo Type '/orderflush' to empty the list of special orders (in case of problems).%;\
  /_echo

/def print_so_list = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {MATCH_COLOR} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /elseif (!strlen(%{MATCH}) & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0")) \
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def print_so_match = \
  /eval /set TEMP_SIZE=$[get_2array("so",$[TEMP_NUM], 1)]%;\
  /eval /set TEMP_SHADE=$[get_2array("so",$[TEMP_NUM], 2)]%;\
  /eval /set TEMP_COLOR=$[get_2array("so",$[TEMP_NUM], 3)]%;\
  /eval /set TEMP_SHAPE=$[get_2array("so",$[TEMP_NUM], 4)]%;\
  /eval /set TEMP_CLARITY=$[get_2array("so",$[TEMP_NUM], 11)]%;\
  /eval /set TEMP_VALUE=$[get_2array("so",$[TEMP_NUM], 7)]%;\
  /eval /set TEMP_PATTERN=$[get_2array("so",$[TEMP_NUM], 0)]%;\
  /eval /set TEMP_NUMGROUPS=$[get_2array("so",$[TEMP_NUM], 8)]%;\
  /eval /set TEMP_MARKETER=$[get_2array("so",$[TEMP_NUM], 6)]%;\
  /eval /set TEMP_FILLED=$[ismember($[TEMP_NUM],_array_so_accepted,1)]%;\
  /if ({TEMP_COLOR} =/ {VEIN_COLOR} & {TEMP_SHADE} =/ {VEIN_SHADE} & (ismember(%{TEMP_NUM},%{_array_so_accepted},1) =/ "0"))\
    /echo -w %{TEMP_NUM} %{TEMP_NUMGROUPS} x %{TEMP_PATTERN} %{TEMP_SIZE} %{TEMP_SHADE} %{TEMP_COLOR} %{TEMP_SHAPE} %{TEMP_CLARITY} PAY: %{TEMP_VALUE} Listed: %{TEMP_MARKETER}%;\
  /endif%;\

/def orderlist = \
  /let MATCH=%*%;\
  /if (regmatch((rose|blue|green|yellow|amethyst|black|white),{MATCH}) & (strlen({MATCH}))) \
    /set MATCH_COLOR=%{MATCH}%;\
  /endif %;\
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_list%;\
  /_echo %;\
  /unset MATCH%;\
  /unset MATCH_COLOR

/def ordermatch = \
  /_echo %;\ /echo -w -aBCcyan SPECIAL ORDER LIST%;\
  /foreach TEMP_NUM _array_so_list /print_so_match%;\
  /_echo

/def orderflush = \
  /_echo %;\ /echo -w -aBCcyan TFRC: Flushing the contents of the Special Order List%;\
/purge_array so

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Learn the the special order(s) from the chit or terminal
;;;

;; /def -F -p30 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9A-Za-z ]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \

/def -p100 -T"tiny.mush.cm.*" -mregexp -t"^([0-9]+) +([0-9a-zA-Z ]*[a-zA-Z]+) +(t|vs|s|ms|m|ml|l|vl) +(vp|p|l|m|d|rd) +([a-z]+) +([a-z]+) +(p|vsf|sf|f|mf) +([A-Za-z]+) +([0-9]+)" special_order_match = \
      /set SO_NUM=%P1%;\
      /set SO_PATTERN=%P2%;\
      /set SO_SIZE=%P3%;\
      /set SO_SHADE=%P4%;\
      /set SO_COLOR=%P5%;\
      /set SO_SHAPE=%P6%;\
      /set SO_CLARITY=%P7%;\
      /set SO_MARKETER=%P8%;\
      /set SO_VALUE=%P9%;\
        /if (regmatch(' x ',%{P2})) \
                /set SO_NUMGROUPS=%PL%; \
                /set SO_PATTERN=%PR%; \
        /else \
                /set SO_NUMGROUPS=1%; \
        /endif%;\
        /if (%{SO_SHADE} =/ "vp") \
          /set SO_SHADE=very pale%;\
        /elseif (%{SO_SHADE} =/ "l") \
          /set SO_SHADE=light%;\
        /elseif (%{SO_SHADE} =/ "m") \
          /set SO_SHADE=medium%;\
        /elseif (%{SO_SHADE} =/ "d") \
          /set SO_SHADE=deep%;\
        /elseif (%{SO_SHADE} =/ "rd") \
          /set SO_SHADE=rich deep%;\
          /set CUT_SCALE=do%;\
        /elseif (%{SO_SHADE} =/ "p") \
                /if (%{SO_COLOR} =/ "white") \
                        /set SO_SHADE=pure%;\
                /elseif (%{SO_COLOR} =/ "black") \
                        /set SO_SHADE=pure%;\
                /else \
                        /set SO_SHADE=pale%;\
                /endif%;\
        /endif%;\
        /if (%{SO_CLARITY} =/ "p") \
                /set SO_CLARITY2=perfect%;\
                /set SO_CLARITY_LIST=perfect%;\
        /elseif (%{SO_CLARITY} =/ "vsf") \
                /set SO_CLARITY2=very slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "sf") \
                /set SO_CLARITY2=slightly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed%;\
        /elseif (%{SO_CLARITY} =/ "f") \
                /set SO_CLARITY2=flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed%;\
        /elseif (%{SO_CLARITY} =/ "mf") \
                /set SO_CLARITY2=majorly flawed%;\
                /set SO_CLARITY_LIST=perfect|very slightly flawed|slightly flawed|flawed|majorly flawed%;\
        /else \
              /echo -w -aBCcyan SPECIAL ORDER: Flaw match broken. %;\
        /endif%;\
        /eval /set _array_so_$[SO_NUM]_0=$[SO_PATTERN]%;\
        /eval /set _array_so_$[SO_NUM]_1=$[SO_SIZE]%;\
        /eval /set _array_so_$[SO_NUM]_2=$[SO_SHADE]%;\
        /eval /set _array_so_$[SO_NUM]_3=$[SO_COLOR]%;\
        /eval /set _array_so_$[SO_NUM]_4=$[SO_SHAPE]%;\
        /eval /set _array_so_$[SO_NUM]_5=$[SO_CLARITY2]%;\
        /eval /set _array_so_$[SO_NUM]_6=$[SO_MARKETER]%;\
        /eval /set _array_so_$[SO_NUM]_7=$[SO_VALUE]%;\
        /eval /set _array_so_$[SO_NUM]_8=$[SO_NUMGROUPS]%;\
        /eval /set _array_so_$[SO_NUM]_9=$[SO_CLARITY_LIST]%;\
        /eval /set _array_so_$[SO_NUM]_10=$[SO_NUMGROUPS] | $[SO_SIZE] | $[SO_PATTERN] | $[SO_SHADE] |$[SO_COLOR] | $[SO_SHAPE] | $[SO_CLARITY]  %;\
        /eval /set _array_so_$[SO_NUM]_11=$[SO_CLARITY]%;\
        /if (strlen({SO_ACCEPTFLAG})) \
          /if (!strlen({_array_so_accepted})) \
            /set _array_so_accepted=|%;\
            /addlist _array_so_accepted %{SO_NUM}%;\
          /else \
            /addlist _array_so_accepted %{SO_NUM}%;\
          /endif %;\
        /else \
          /addlist _array_so_list %{SO_NUM}%;\
        /endif

;; check if scanning for Special Order that have already been accepted.

/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'This terminal is totally dedicated to printing out work chits for specially ordered crystal.  At the touch of a button, the screen scrolls up to list the open orders*' so_trig_accept = \
        /repeat -1 1 /send -w scan accepted list


/def -F -p10 -T"tiny.mush.cm.*" -mglob -t'* Orders Under Competition *' so_accept = \
        /set SO_ACCEPTFLAG=yes%;\
        /repeat -2 1 /unset SO_ACCEPTFLAG

;;; 9/13/2011 Fixed orderfill so it no longer shares variable names with the 
;;; SO chit code. This means SOs in the cut queue will not be mixed with 
;;; SO chits being handled by an alternate Sorter character.

;;; Kahlyla reminded me of a bug where SO's sometimes recut flaw acceptable to
;;; the SO. Recut VSF in a SO that needed MF or better.

/def -T"tiny.mush.cm.sing" orderfill = \
  /unset TEST_ORDERNUM%;\
  /set TEST_ORDERNUM=%{*}%;\
  /set FILLSO_NUM=%{*}%;\
  /unset RECUT_LIST%;\
  /unset CUT_NOTE%;\
  /unset CUT_SCALE%;\
  /eval /set FILLSO_SIZE=$[get_2array("so",$[FILLSO_NUM], 1)]%;\
  /eval /set FILLSO_SHADE=$[get_2array("so",$[FILLSO_NUM], 2)]%;\
  /eval /set FILLSO_COLOR=$[get_2array("so",$[FILLSO_NUM], 3)]%;\
  /eval /set FILLSO_SHAPE=$[get_2array("so",$[FILLSO_NUM], 4)]%;\
  /eval /set FILLSO_PATTERN=$[get_2array("so",$[FILLSO_NUM], 0)]%;\
  /eval /set FILLSO_NUMGROUPS=$[get_2array("so",$[FILLSO_NUM], 8)]%;\
  /eval /set FILLSO_CLARITY_LIST=$[get_2array("so",$[FILLSO_NUM], 9)]%;\
  /eval /set FILLSO_CLARITY=$[get_2array("so",$[FILLSO_NUM], 11)]%;\
  /if (!regmatch('[0-9]{4}',%{TEST_ORDERNUM}))%;\
    /_echo %;\
    /echo -w -aBCred SPECIAL ORDER: You didn't enter a proper special order number. The syntaxt is '/orderfill <SO Number>'. %;\
    /_echo %;\
  /elseif (%{FILLSO_SHADE}!/%{VEIN_SHADE})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_SHADE}" vein shade does not match the shade on Special Order: %{FILLSO_SHADE}.%;\
  /elseif (%{FILLSO_COLOR}!/%{VEIN_COLOR})\
    /echo -w -aBCred SPECIAL ORDER: The "%{VEIN_COLOR}" vein color does not match the color on Special Order: %{FILLSO_COLOR}.%;\
  /else \
    /_echo %;\
    /echo -w -aBCcyan -p SPECIAL ORDER: The Special Order details match. If the vein is large enough, you can fill this order here. %{FILLSO_NUMGROUPS} x %{FILLSO_PATTERN} %{FILLSO_SIZE} %{FILLSO_SHAPE} %{FILLSO_CLARITY} for CREDITS: %{FILLSO_VALUE}%;\
    /test regmatch('(3 chord|4 chord|5 chord|3 row|4 row|5 row|octave|single)',"%{FILLSO_PATTERN}")%;\
    /let CUT_GROUP=%{P1}%;\
    /if (%{CUT_GROUP} =/ "octave") \
      /set CUT_SCALE=do mi so dx ti re fa la%;\
    /elseif (%{CUT_GROUP} =/ "3 chord") \
      /set CUT_SCALE=do mi so%;\
    /elseif (%{CUT_GROUP} =/ "4 chord") \
      /set CUT_SCALE=do mi so dx%;\
    /elseif (%{CUT_GROUP} =/ "5 chord") \
      /set CUT_SCALE=do mi so dx ti%;\
    /elseif (%{CUT_GROUP} =/ "3 row") \
      /set CUT_SCALE=do re mi%;\
    /elseif (%{CUT_GROUP} =/ "4 row") \
      /set CUT_SCALE=do re mi fa%;\
    /elseif (%{CUT_GROUP} =/ "5 row") \
      /set CUT_SCALE=do re mi fa so%;\
    /elseif (%{CUT_GROUP} =/ "single") \
      /set CUT_SCALE=do%;\
    /endif %;\
    /if (%{FILLSO_NUMGROUPS} =/ "2") \
    /set CUT_SCALE=%{CUT_SCALE} %{CUT_SCALE}%;\
    /endif %;\
    /repeat -3 -w 1 /so_loop %{CUT_SCALE}%;\
    /endif


;;;; 9/17/2011 fixed so_loop to make unsetting TEST_ORDERNUM
;;;; slow enough that the order number is added to the
;;;; list of accepted special orders.
;;;; 10/27/2011 Added in check for pause/resume SO cutting

/def so_loop = \
  /if (CUT_CARTON =~ "yes") \
    /beep 1 %;\
    /echo -w -arBCred SPECIAL ORDER: Cutting paused because you need a fresh carton. Type '/cut resume' when ready.%;\
    /repeat -w -130 1 /so_loop %{*} %;\
    /set CUT_PID=%?%;\
  /elseif ({#}) \
    /note %{1} %; \
    /set FILLSO_NOTE=%{1}%; \
    /send -w cut %{FILLSO_SHAPE} size=%{FILLSO_SIZE}%; \
    /shift %; \
    /repeat -w -130 1 /so_loop %{*} %; \
    /set CUT_PID=%?%; \
  /else \
    /if (strlen(%{RECUT_LIST})) \
      /echo -w -aBCcyan SPECIAL ORDER: Recutting flawed crystals now.%;\
      /repeat -2 -w 1 /so_loop %{TEMP_RECUT}%; \
      /unset RECUT_LIST%; \
    /else \
      /echo -w -aBCcyan SPECIAL ORDER: Special order %{TEST_ORDERNUM} is done.%;\
      /addlist _array_so_accepted %{TEST_ORDERNUM}%;\
      /quote -S /unset `/listvar -mglob -s FILLSO_* %;\
      /repeat -w -1 1 /unset TEST_ORDERNUM%;\
    /endif%;\
  /endif