From ea0324e71666d9a185a7cb89abafe2e9dc8acd4e Mon Sep 17 00:00:00 2001 From: depyraken Date: Sat, 2 Apr 2016 18:11:08 +0200 Subject: [PATCH] refactor into function calls to avoid stack overflow --- primitives/newbieland/fisherman.primitive | 78 ++++++++++++----------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/primitives/newbieland/fisherman.primitive b/primitives/newbieland/fisherman.primitive index 92abf55..2bd2f6c 100644 --- a/primitives/newbieland/fisherman.primitive +++ b/primitives/newbieland/fisherman.primitive @@ -1757,49 +1757,53 @@ ()setNamedEntityProp($BCVar, "param2", ""); // } - // $botEid, $playerEid - BCaddPlayer(){ - BCP = 0; - $ttt = "v0 = " + v0; - ()phraseEndSystemMsg(0, "shout", $ttt); - $ttt = "boteid2 = " + $botEid; - ()phraseEndSystemMsg(0, "shout", $ttt); - $ttt = "botFamily2 = " + $botFamily; - ()phraseEndSystemMsg(0, "shout", $ttt); - - switch(v0){ - case 0:{ // No one is fishing - v0 = 1; // P1 is now fishing - v1 = 0; // etat initial < 1000, fishing >= 1000 + NoOneIsFishing(){ + v0 = 1; // P1 is now fishing + v1 = 0; // etat initial < 1000, fishing >= 1000 $ttt = "boteid3 = " + $botEid; ()phraseEndSystemMsg(0, "shout", $ttt); $ttt = "botFamily3 = " + $botFamily; - ()phraseEndSystemMsg(0, "shout", $ttt); - ()setNamedEntityProp($botEid, "state", $botFamily); // botFamily requirement - BCP = 1; + ()phraseEndSystemMsg(0, "shout", $ttt); + ()setNamedEntityProp($botEid, "state", $botFamily); // botFamily requirement + BCP = 1; + BuildPlayerSlot(); + } + + P1AlreadyFishing(){ + $BCVar = $botEid + "_P11"; + ($BCP)getNamedEntityProp($BCVar, "state"); + if($BCP != $playerEid){ + v0 = 3; // P1 and P2 are now fishing + BCP = 2; + v2 = 0; // etat initial < 1000, fishing >= 1000 BuildPlayerSlot(); } - case 1:{ // P1 is fishing - $BCVar = $botEid + "_P11"; - ($BCP)getNamedEntityProp($BCVar, "state"); - if($BCP != $playerEid){ - v0 = 3; // P1 and P2 are now fishing - BCP = 2; - v2 = 0; // etat initial < 1000, fishing >= 1000 - BuildPlayerSlot(); - } + } + + P2AlreadyFishing(){ + $BCVar = $botEid + "_P21"; + ($BCP)getNamedEntityProp($BCVar, "state"); + if($BCP != $playerEid){ + v0 = 3; // P1 and P2 are now fishing + BCP = 1; + v1 = 0; // etat initial < 1000, fishing >= 1000 + ()phraseEndSystemMsg(0, "shout", "2 => 1 => avant"); + BuildPlayerSlot(); + ()phraseEndSystemMsg(0, "shout", "2 => 1 => apres"); } - case 2:{ // P2 is fishing - $BCVar = $botEid + "_P21"; - ($BCP)getNamedEntityProp($BCVar, "state"); - if($BCP != $playerEid){ - v0 = 3; // P1 and P2 are now fishing - BCP = 1; - v1 = 0; // etat initial < 1000, fishing >= 1000 - ()phraseEndSystemMsg(0, "shout", "2 => 1 => avant"); - BuildPlayerSlot(); - ()phraseEndSystemMsg(0, "shout", "2 => 1 => apres"); - } + } + + // $botEid, $playerEid + BCaddPlayer(){ + BCP = 0; + switch(v0){ // No one is fishing + NoOneIsFishing() + } + case 1:{ // P1 is already fishing + P1AlreadyFishing(); + } + case 2:{ // P2 is already fishing + P2AlreadyFishing(); } case 3: // P1 and P2 are already fishing ()phraseEndSystemMsg(0, "shout", "TOO_MANY_PLAYERS_ARE_FISHING");