//Stand At Mortain module, Drawn Out scenario, Long Shot complex //wargame module designed by Paul Rohrbaugh, distr by Against The Odds games mag //elements used without permission //adaptation & freeware applet code copyright 2008 by Droll import java.awt.*; //incorpg Graphics class import java.awt.event.*; //incorpg KeyListener/Adapter,ActionListener/Event classes import javax.swing.Timer; public class mrtX0Ap extends Panel{ int x1=1,x2,x3,x4,x5,y1=1,y2,y3,y4,y5; //var lvl 1 routines' constants static final int Sho4th=1,UseOpt=2,BegTrn=3,BegRnd=4,PikUnt=5,OprExe=6,EndGam=7; //var lvl 2 routines' constants static final int MacPik=1,UsrPik=2,OprMov=3,OprAtk=4; //var lvl 3 routines' constants static final int ChgBd=1,AtkVs=2; static final int Neg=-1,Nah=0,X=10,C=100,M=1000,Asc0=+'0'; //note shorthand for (int)'0' static final Color StdHue[]={ Color.black,Color.magenta,Color.red,Color.orange,Color.yellow, Color.green,Color.cyan,Color.blue,Color.lightGray,Color.white }; //StdHue[] static final Color NewHue[]={ //pot use in hue() fnc mth new Color(200,200,100).brighter() //bright khaki }; //NewHue[] int hues[]={0,0,7,9,0,7,0,5,6,9,0,0,9,8,5,6,3,4,0,0,0,2,2,2}; //hue() fnc's indirect ref sto static final int BdBkg=1,BdBdr=2,BrfFgd=3,BrfBkg=4,LblFgd=5,LblBkg=6, UsBkg=7,GerBkg=8,Un1Bkg=9,Un2Bkg=X,Un1Fgd=11,Un2Fgd=12, MapBkg=13,ForBkg=14,HilBkg=15,VlgBkg=16,CtyBkg=17, MapFgd=18,ForFgd=19,HilFgd=20,VlgFgd=21,CtyFgd=22,RoaFgd=23; Font ltr,lbl; //& FontMetrics class instance ltrSiz obj int ltrPt,lblPt,typHt; Timer bli; int newUnt,srcUnt,oprUnt,basUnt,tgtUnt,atkSrc,atkTgt,newSid; //vals= ary elm#s, tho sid dta codes= 1,2.. int atkCnt,atkStr,adjBon,tnkBon,terBon,airBon,sidTot,sidTol,oppTot,oppTol; int exiCnt,exiReq=5,rndCnt,trnCnt,trnMax=6; static final int Mac=0,Usr=1; //controller desig static final int Emy=2,Aly=3,Any=4,Set=5,Out=10,Map=15; //nxtUnt() args (incl Mac & Usr) static final int Fwd=5; //isBy() arg (incl Emy & Aly) static final int StkAct=6,StkMax=2; //unit stacking limit in hex static final int Tgr=2,Aty=7,Air=8; //unit types static final int Mov=6,Fir=7,Hlt=8,Siz=9,Atk=X; //act, inp, untOpts 1..6= mov dir int srcTyp,untOpt,sptCap,airCoo,trnSpt; boolean isAll,isTgr,isCov,isHit; int bdWd,bdHt,ioWd,ioHt,zonWd,lblWd,lblHt,bdrWd=1; static final boolean isEup=true; //even hex cols shift up vs normal down int mapWd,mapHt,mapTop,mapBtm,mapLft,mapTopMar,mapLftMar; int srcCoo,tgtCoo,stkCoo,sltRow,leaCol,lodCol,etyCol; int aoColWd=99,aoRowHt=99,eqRows; static final int Ope=0,Fst=1,Hil=2,Vlg=3,Cty=4; //map terrain types //hexAsp= 100* [tan(30 deg) or 1/sqr(3)= .57]: hexside-to-height ratio at 1:1 display fmt int hlfHexSid=7,hlfHexHt,hexSid,hexWd,hexHt,minTopMar,minLftMar,hexAsp=57; int losDst,losStp,losRis,losRun,losDrp,losTri,losRol; int topHexCol=1,topHexRow=1,mapColWd=9,mapRowHt=6; static final int Red=0,Bla=1,Act=2; //crdCnt suit specs (incls Any abv) char crd$,rndCrd$; //'A'..'M'=Hearts,'N'..'Z'=Diamonds,'a'..'m'=Spades,'n'..'z'=Clubs int hasAct,allAct,actVal,actCnt,rnkVal,rndVal,dlrTop,dlrSiz; boolean isMac,isDon,isAi; //isAi=false->2 player game //utility vars char a$,A$; boolean isa1,isb1,isc1,isd1,isa2,isb2,isc2,isa3,isb3,isA4,isB4,isA5,isB5,isC5, isA6,isB6,isC6,isD6,isA7,isB7,isC7,isA8,isB8,isA9; int a1,b1,c1,d1,e1,f1,g1,h1; int a2,b2,c2,d2,e2,f2,g2,h2; int a3,b3; int A3,B3,C3,D3,E3; int A4,B4,C4,D4,E4,F4,G4,H4,I4; int A5,B5,C5,D5,E5,F5,G5,H5,I5,J5,K5,L5,M5,N5,O5; int A6,B6,C6,D6,E6,F6,G6,H6; int A7,B7,C7,D7,E7,F7,G7,H7,I7,J7,K7,L7; int A8,B8,C8,D8,E8,F8,G8,H8,I8,J8,K8,L8,M8,N8,O8,P8,Q8,R8; int A9,B9,C9,D9,E9,F9,G9,H9,I9; int A0; StringBuffer a1$=new StringBuffer(); StringBuffer b1$=new StringBuffer(); StringBuffer a2$=new StringBuffer(); StringBuffer a3$=new StringBuffer(); StringBuffer A5$=new StringBuffer(); StringBuffer A7$=new StringBuffer(); StringBuffer B7$=new StringBuffer(); StringBuffer A6$=new StringBuffer(); StringBuffer A8$=new StringBuffer(); StringBuffer A9$=new StringBuffer(); StringBuffer A0$=new StringBuffer(); StringBuffer inp$=new StringBuffer(); //KeyListener user inp $ StringBuffer die$=new StringBuffer(); //dic() dice result listg $ StringBuffer dlr$=new StringBuffer(); //card deck seq of crd$s listg $ StringBuffer sym$=new StringBuffer(); //card type ("AS","JD",etc.) StringBuffer whyEnd$=new StringBuffer(); //endGam() reason msg //small util int arys int Z5Siz=X,Z5[]=new int[Z5Siz+1]; //tgtCnt() unts ary static final int RdyElm=5; int Z6Siz=StkMax<<2,Z6[]=new int[Z6Siz+1]; //cooOcc() unts ary static final int Rng2=X; //eq/ rel to max #unts per side int Z8Siz=Rng2<<1,Z8[]=new int[Z8Siz+1]; //isBy() unts ary int aiOfn[]=new int[3]; //~max #sides+1: sides' mac ai offensive indicator quants //single z1$[] array with int divider indexes; data$'s fmt= delimited with commas static final char Div$=','; int begElm,endElm,elmNum,begDiv,endDiv; int xsA,xsB,aoMap,untPoo,infCat,sptCat,sidPoo,untGrp,dtaEnd,arySiz=40; StringBuffer z1$[]=new StringBuffer[arySiz+1]; //untPoo & untGrp's field ref constants static final int BasId=1, //ie. between beginning & 1st comma pos BasTyp=2,BasSt1=3,BasSt2=4,BasSym=5, //untPoo fields UntSid=1,UntTyp=2,UntCoo=3,UntOgn=4,UntStp=5,UntAct=6,UntDsg=7, //untGrp fields SidId=1,SidVal=2,SidCtl=3; //sidPoo fields char key1$,key2$,key3$,key4$,key5$; boolean isKey,isLin; int inpVal,txtX,txtY,txtTyp,argLg,txtCodLg=3; StringBuffer lin$=new StringBuffer(); //performance opts boolean isRun,isBrf; //auto exe fnc cap, wo inp int runStp=3; //0= run to end, 1= pause at turn, 2= pause at round, 3=pause at event int untBox=1; //thicker unit counter outlines public static void main(String args[]){ Frame f=new Frame(); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); }; //windowClosing( }); //f.addWindowListener( mrtX0Ap p=new mrtX0Ap(); p.setSize(1000,1000); f.add(p); f.pack(); //` p.init(); //rev as mrtX0Ap() constructor mth f.setSize(335,240); f.setResizable(true); f.setVisible(true); //paint() run now automatically on startup } //main( mrtX0Ap(){ //constructor mth bli=new Timer(C,new ActionListener(){ public void actionPerformed(ActionEvent e){ go(); } //actionPerformed mth }); //Timer class bli obj this.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e){ //prov for (Apple numpad) Enter keys key5$=e.getKeyChar(); if(key5$=='\n') keyIn(); } //keyPressed mth public void keyTyped(KeyEvent e){ //all other keys key5$=e.getKeyChar(); if(key5$!='\n') keyIn(); } //keyTyped mth }); //KeyAdapter class/ addKeyListener args //now loading main dta strings array z1$[] //note: z1$[0] is left unused - locElm(), etc. may rtn 0 as a "not found" //init all StringBuffer elms for(a1=1;a1<=arySiz;a1++) //z1$[0] remains null z1$[a1]=new StringBuffer(); a1=1; xsA=a1++; //transient string elm var usage xsB=a1++; //persistent (during inputs) string elm var usage aoMap=a1; //map hex terrain eq(a1++,"0,1,0,0,0,0,0,0,0"); //row 1 eq(a1++,"0,225,3234,0,2,0,0,0,0"); //row 2 eq(a1++,"225,0,034,025,026,015,026,015,025"); //row 3 eq(a1++,"0,025,42356,414,0,0,0,1,0"); //row 4 eq(a1++,"025,0,0,034,1,1,1,1,1"); //row 5 eq(a1++,"0,0,0,0,1,0,1,0,1"); //row 6 untPoo=a1; eq(a1++,"Armor Rgt,0,42,21,0"); eq(a1++,"Lt Armor Rgt,1,32,11,0"); eq(a1++,"Hv Tank Bn (Tiger),2,-2,0,0"); eq(a1++,"Tank Dest Bn,3,41,21,0"); infCat=a1; eq(a1++,"Antitank Bn,4,41,21,1"); eq(a1++,"Infantry Rgt,5,24,12,2"); eq(a1++,"Lt Infantry Rgt,6,23,12,2"); sptCat=a1; eq(a1++,"Artillery spt,7,3,0,3"); eq(a1++,"Air opns,8,4,0,4"); sidPoo=a1; eq(a1++,"US,1,0"); eq(a1++,"GER,2,0"); untGrp=a1; eq(a1++,"1,5,1101,1101,1,0,117/ 30"); eq(a1++,"1,5,1102,1102,1,0,119/ 30"); eq(a1++,"1,5,1103,1103,1,0,120/ 30"); eq(a1++,"1,3,1104,1104,1,0,743 TD"); eq(a1++,"1,4,1105,1105,1,0,823 AT"); eq(a1++,"1,0,1201,1201,1,0,CCA/ 3"); eq(a1++,"1,0,1202,1202,1,0,CCB/ 3"); eq(a1++,"1,0,1203,1203,1,0,CCR/ 3"); eq(a1++,"1,7,1204,1204,1,0,off board"); eq(a1++,"1,8,1205,1205,1,0,off board"); eq(a1++,"2,0,2101,2101,1,0,1/ 2/ 2 SS"); eq(a1++,"2,0,2102,2102,1,0,2/ 2/ 2 SS"); eq(a1++,"2,1,2103,2103,1,0,STG 17 SS"); eq(a1++,"2,2,2104,2104,1,0,102"); eq(a1++,"2,6,2201,2201,1,0,1/ 2/ 2 SS"); eq(a1++,"2,6,2202,2202,1,0,2/ 1/ 2 SS"); eq(a1++,"2,6,2203,2203,1,0,37/ 17 SS"); eq(a1++,"2,6,2204,2204,1,0,38/ 17 SS"); dtaEnd=a1; //1st empty ary elm$ bdSiz(); hexFit(); //paint() runs now automatically on startup } //constructor mth public void paint(Graphics g){ this.requestFocus(); //permit keybd detect by KeyListener ~upd to this.requestFocusInWindow() reTrd(); } //paint mth - will automatically restore keybd focus, if lost void reTrd(){ shoBd(); shoMap(); shoFrc(); if(x5>0){ if(y5>1) y5--; } else if(x4>0){ if(y4>1) y4--; } else if(x3>0){ if(y3>1) y3--; } else if(x2>0){ if(y2>1) y2--; } else if(y1>1) y1--; go(); } //reTrd mth void keyIn(){ isKey=true; Graphics g=getGraphics(); //clear lin$ (prompt+input): FontMetrics ltrSiz=g.getFontMetrics(ltr); A8=ltrSiz.stringWidth(str(lin$).substring(txtCodLg)); g.setColor(hue(BrfBkg)); g.fillRect(txtX,txtY-typHt*3/4,A8,typHt-1); if(isLin){ if(key5$=='\n' || key5$=='\b' && inp$.length()==argLg){ isLin=false; eq(lin$,str(lin$).substring(argLg)); if(txtTyp==4) inpVal=str(lin$).equals("")?0:Integer.parseInt(str(lin$)); //Enter alone= 0 } //if(key5$=='\n' else{ if(key5$=='\b') inp$.setLength(Math.max(argLg,inp$.length()-1)); else if(txtTyp!=4 || "0123456789".indexOf(key5$)>=0 || key5$=='-' && inp$.length()==argLg) inp$.append(key5$); eq(lin$,inp$); g.setColor(hue(BrfFgd)); g.setFont(ltr); g.drawString(str(lin$).substring(txtCodLg),txtX,txtY); } //else(key5$=='\n' } //if(isLin if(txtTyp==2) inpVal=key5$=='\n'?0:+key5$-Asc0; key1$=key2$=key3$=key4$='?'; if(x5==0) if(x4>0) key4$=key5$; else if(x3>0) key3$=key5$; else if(x2>0) key2$=key5$; else key1$=key5$; if(!isLin) go(); } //keyIn mth void go(){ //director/ switchboard routine: all keybd inp (and repaint()) is sent here - //these are those routines that accept key input //var lvl 2 routines (note: ordering of x3..x1 cond hierarchy is significant) if(x3==ChgBd) chgBd(); else if(x3==AtkVs) atkVs(); else if(x2==MacPik) macPik(); else if(x2==UsrPik) usrPik(); else if(x2==OprMov) oprMov(); else if(x2==OprAtk) oprAtk(); else //var lvl 1 routines if(x1==Sho4th) sho4th(); else if(x1==UseOpt) useOpt(); else if(x1==BegTrn) begTrn(); else if(x1==BegRnd) begRnd(); else if(x1==PikUnt) pikUnt(); else if(x1==OprExe) oprExe(); else endGam(); } //go mth - keybd inp is accepted/ listened for here; at called rout's rtn //var lvl 1 routines void sho4th(){ if(x1!=Sho4th) y1=1; Graphics g=getGraphics(); switch(y1){ case 1: x1=Sho4th; y1++; case 2: a1=mapLft+mapWd/4; //title bkg b1=3*hexSid; c1=mapWd/2+hexSid; d1=mapHt-2*b1; g.setColor(StdHue[9]); g.fillRect(a1,b1,c1,d1); ltr=new Font("SanSerif",Font.BOLD,hexWd); g.setFont(ltr); g.setColor(StdHue[8]); g.drawString(ctrStr("STAND AT",ltr,c1),a1+C9+2,b1+d1/3); //C9 of ctrStr g.setColor(StdHue[0]); g.drawString("STAND AT",a1+C9,b1+d1/3); g.setColor(StdHue[8]); g.drawString(ctrStr("MORTAIN",ltr,c1),a1+C9+2,b1+d1-d1/8); g.setColor(StdHue[7]); g.drawString("MORTAIN",a1+C9,b1+d1-d1/8); g.setColor(StdHue[9]); //freaking/ stencilled ltrs fx g1=hexSid; for(e1=a1+g1;e1g1-20) f1--; } //for(h1=b1+X; g.setColor(StdHue[7]); g.drawRect(a1,b1,c1,d1); e1=hues[BrfFgd]; hues[BrfFgd]=4; //`f1=mapHt; mapHt+=2; //incr vert txt adjs txt("1(3The wave of the"); txt("1)3future is coming"); txt("1*3and there is"); txt("1+3no fighting"); txt("1,3it."); hues[BrfFgd]=e1; //`mapHt=f1; txt("223hit a key"); return; } //if(isa1 case 5: if(isa1){ y1-=2; //addl y1-- by reTrd() reTrd(); return; } //if(isa1 isa1=key1$=='*'; y1++; case 6: y1++; if(isa1){ g.setColor(hue(BdBkg)); g.fillRect(0,0,ioWd,mapHt); g.setColor(hue(BdBdr)); g.drawRect(0,0,ioWd,mapHt); ltr=new Font("SanSerif",Font.BOLD,ltrPt-2); g.setFont(ltr); a1=mapHt; mapHt-=2; txt("1%1Game for 1 or 2 player(s) vs computer or opponent."); txt("1&1For playtest comments visit playhob.com."); txt("1'1Files arc: mrtX0.zip - contains all files below."); txt("1(1Rules doc: mrtX0rul.rtf. Game pgm: mrtX0Ap.java (source);"); txt("1)1mrtX0Ap.class (byte code), mrtX0Ap$1/2/3.class (keyLis/ Timer)."); mapHt+=3; txt("1*1Program's operation modifies no files."); txt("1+1Playtesters are appreciated but not compensated."); txt("1,1OK to alter the code for your own use, at your own risk."); mapHt+=3; txt("1-1Paul Rohrbaugh's 2006 design for Against The Odds"); txt("1.1(atomagazine.com), not approved by either: elements"); txt("1/1used without permission. Copyright 2008 by Droll"); mapHt=a1; ltr=new Font("SanSerif",Font.PLAIN,ltrPt); g.setFont(ltr); //carries over to io font txt("223hit a key"); return; } //if(isa1 case 7: if(isa1){ y1-=4; //addl y1-- by reTrd() reTrd(); return; } //if(isa1 y1++; case 8: shoMap(); useOpt(); } //switch(y1 } //sho4th mth void useOpt(){ if(x1!=UseOpt) y1=1; switch(y1){ case 1: x1=UseOpt; for(a1=sidPoo;a10) dtaIn(a1,UntOgn,(wrdOut(a1,UntOgn).charAt(0)=='+'?"+":"")+wrdOut(a1,UntCoo)); dlrShf(); y1++; case 4: y1++; if(!isBrf && runStp==1){ txt("011"); txt("211hit a key for turn "+trnCnt); return; } //if(!isBrf && case 5: isCov=false; trnSpt=airCoo=hasAct=rndCnt=0; shoMap(); //rmv any airCoo mkrs shoFrc(); begRnd(); } //switch(y1 } //begTrn mth void begRnd(){ if(x1!=BegRnd) y1=1; switch(y1){ case 1: x1=BegRnd; rndCnt++; for(a1=untGrp;a10 && valOut(a1,UntCoo)M) dtaIn(a1,UntOgn,(A$=='+'?"+":"")+wrdOut(a1,UntCoo)); //A$ of valOut() y1++; case 2: txt("011"); txt("133"+crdSym(drwCrd())+" ("+(dlrSiz-dlrTop+1)+" cards remaining)"); y1++; case 3: y1++; if(rnkVal<1){ isa1=rnkVal<0; isb1=hasAct=trnMax; if(!isa1 && isb1) eq(a1$,(hasAct>0?"only "+wrdOut(sidPoo-1+hasAct,SidId):"neither")+" side activated."); txt("111"+(isa1?"Deck exhausted.":"Joker drawn"+(isb1?", but "+a1$:"."))); if(isBrf){ txt("221 "+(!isa1 && isb1?"Redrawing.":(isc1?"Game over.":"New turn."))); return; } //if(isBrf } //if(rnkVal<1 case 4: rndVal=rnkVal; if(rndVal<1){ if(!isa1 && isb1){ y1-=2; //redraw begRnd(); } //if(!isa1 && else if(isc1){ rndCnt--; //retain final rnd# pikUnt(); } //if(isc1 else begTrn(); return; } //if(rndVal<1 rndCrd$=crd$; actVal=rndVal>X?StkAct:rndVal+1>>1; newSid=sidPoo+(rndCrd$<'a'?0:1); isMac=valOut(newSid,SidCtl)==Mac; isBrf=!isMac || !isRun; sptCap=trnSpt<1 && newSid==sidPoo?(rndVal>11 || (rndVal&1)<1?Aty:Air):0; y1++; case 5: txt("111 "+(trnCnt+rndCnt<3?"Play begins with ":"") +wrdOut(newSid,SidId)+" side's round. trn "+trnCnt+", rnd "+rndCnt); isa1=actVal==StkAct; a1=isa1?1:actVal; eq(b1$," call "+wrdOut(untPoo+sptCap,BasId)+'.'); eq(a1$,(isMac?"Computer":"Player") +" may activate "+a1+" unit"+(a1>1?"s":"") +(isa1?" or map hex stack":"") +(sptCap>0?", or"+(!isa1?str(b1$):""):".")); if(isa1 && sptCap>0) txt("131 "+b1$); txt("133"+sym$); txt("121 "+a1$); if(isRun && runStp<2) bli.restart(); y1++; if(isBrf || runStp==2 || bli.isRunning()){ txt("236"); return; } //if(isBrf || case 6: if(bli.isRunning()) //~or just stop wo if() bli.stop(); for(a1=untGrp;a10) dtaIn(a1,UntAct,"0"); y1++; case 7: actCnt=stkCoo=0; if(hasAct=trnMax && rndVal<1; //may be reached at begRnd() or atkVs() isb1=nxtUnt(Emy+Map)sidPoo; isb1=isb1 && rsvCnt(sidPoo+1-(newSid-sidPoo))<1 //acting side wins || exiCnt>=exiReq //occur during GER rnd || isc1 && isb1 && (isBy(203,Aly+Fwd) || C8/C==1); //~opt spl vc: C8 of isBy() if(isa1 || isb1){ isDon=true; //flg for game end after board situation review isMac=false; //allow review regardless of actual ctlr if(!isb1) newSid=sidPoo; //US wins } //if(isa1 || y1++; case 2: txt("011"); y1++; if(isa1 || isb1){ eq(whyEnd$,isb1?"Victory conditions achieved":"Turn limit expired"); //~elab txt("111 "+whyEnd$+" - game over!"); txt("221 Review final situation, then End."); return; } //if(isa1 || case 3: untOpt=Nah; y1++; if(isMac) macPik(); else usrPik(); return; case 4: if(untOpt==Hlt && trnCnt<1 && locElm(untGrp,UntCoo,"110")>0){ //untOpt of mac/usrPik() y1--; txt("211 All 5 US setup units must be placed on map."); return; } //if(untOpt==Hlt && y1++; case 5: if(untOpt==Hlt) if(trnCnt<1) begTrn(); //end US setup else if(isDon) endGam(); else begRnd(); else oprExe(); } //switch(y1 } //pikUnt mth void oprExe(){ if(x1!=OprExe) y1=1; switch(y1){ case 1: x1=OprExe; srcUnt=oprUnt; basUnt=pri(srcUnt); srcCoo=valOut(srcUnt,UntCoo); srcTyp=valOut(srcUnt,UntTyp); y1++; case 2: y1++; txt("011"); if(untOpt=sptCat) untOpt=Fir; //was chg'd to Atk in oprAtk() isa1=isa1 && trnCnt>0 && untOpt0 && C6>0){ //unacted unts in hex: _6s of cooOcc() isd1=srcTyp==Tgr; e1=C6; for(c1=1;c1<=e1;c1++){ a1=Z6[RdyElm+c1]; d1=valOut(a1,UntTyp); //~?need a1>=untGrp safety chk isb1=isb1 || d1==Tgr; if(d1==Tgr || isd1 && (e1==1 || c1==2 && isb1)) dtaIn(a1,UntAct,"-1"); //mrk waivered } //for(c1=1; isc1=isd1 && e1>1 && !isb1; } //if(cooOcc(srcCoo)>0 && dtaIn(srcUnt,UntAct,""+b1); //rcl sta } //if(srcCoo0 && D6>1) //_6s of cooOcc() for(c1=1;c1<=D6;c1++){ a1=Z6[c1]; if(valOut(a1,UntOgn)>M && (srcTyp==Tgr || valOut(a1,UntTyp)==Tgr && F6<3)){ dtaIn(srcUnt,UntAct,"-1"); //tmp mrk waivered til blw isb1=srcTyp==Tgr; //msg Tgr free activ isd1=!isb1; //msg coloc free activ } //if(valOut(a1,UntOgn)>M && } //for(c1=1; y1++; case 4: //msg waiver or get inp for Tgr activn -> 2 coloc unts activn waiver y1++; b1=valOut(srcUnt,UntAct); if(isb1 || isc1 || isd1){ if(isc1 && !isMac) txt("1211) "+wrdOut(Z6[RdyElm+1],UntDsg) +' '+wrdOut(pri(A9),BasId).substring(0,6) //A9 of wrdOut() +" 2) "+wrdOut(Z6[RdyElm+2],UntDsg) +' '+wrdOut(pri(A9),BasId).substring(0,6)); eq(a1$,(b1<0?"activated":"may activate")+" without cost."); eq(a1$,isb1?"Tiger tank unit "+a1$ :(isd1 && (!isc1 || isMac)?"Unit colocated with Tiger "+a1$ //Tgr- conferred waivers :"Pick unit colocated with Tiger for activation waiver:")); if(isBrf){ txt("211"+a1$); return; } //if(isBrf } //if(isb1 || case 5: //chk inp for Tgr- conferred waiver if(isc1){ txt("011"); a1=isMac || inpVal<1 || inpVal>2?ran(2):inpVal; dtaIn(Z6[RdyElm+a1],UntAct,"-1"); //mrk waivered } //if(isc1 y1++; case 6: if(actVal==StkAct && stkCoo<1){ stkCoo=srcCoo>M?tgtCoo:srcCoo; actVal=StkMax-(srcCoo>M?1:0); } //if(actVal==StkAct && a1=basUnt=0) //not a waiver actCnt+=a1; c1=untOptsidPoo; etyCol=isb2?mapColWd:topHexCol; if(stkCoo>0) //can any unt activ? isc2=cooOcc(stkCoo)>0 && (C6>0 || isB6); //_6s of cooOcc() else{ isc2=actCnt0){ a2=newUnt; //newUnt of nxtUnt() do isc2=valOut(nxtUnt(Aly+Set),UntAct)<0; //chk if actv waiver while(!isc2 && a2!=newUnt); } //if(!isc2 } //else(stkCoo>0 if(!isc2) //chk activ pts lft untOpt=atkTgt>0?Atk:Hlt; if(untOpt<1){ sltRow=a2=g2=0; //ini row most clear of US unts leaCol=X; //ini col of fwdmost GER unt e2=valOut(sidPoo,SidVal); for(b2=5;b2>0;b2--){ c2=0; for(d2=untGrp;d20) if(valOut(d2,UntSid)==e2) c2+=Math.abs(h2-b2); else if(b2==5){ if(f2g2) g2=f2-leaCol; } //for(d2=untGrp; if(c2>a2){ a2=c2; sltRow=b2; } //if(c2>a2 } //for(b2=5; lodCol=g2<2?0:leaCol; //GER Line Of Departure col } //if(untOpt<1 y2++; case 2: if(trnCnt<1 && !isb2){ //US setup: tac= pref stks, col>2 (N-S road) col<7 (vs ety fir), road/ter hex? while(locElm(untGrp,UntCoo,"110")>0){ a2=elmNum; if(cooOcc((nxtUnt(Aly+Map)>0 && ran(X)<5?valOut(newUnt,UntCoo) //newUnt of nxtUnt() :cnvCoo(M+C*(ran(4)+2)+ran(3)+ran(3)-1)))0 untOpt=Hlt; y2+=5; macPik(); return; } //if(trnCnt<1 && y2++; case 3: y2++; if(untOpt<1 && !isb2 && sptCap>0 && trnSpt==0 && actCnt<1 && (isa2 || actVal<=ran(2)+1)){ //US OBA use atkTgt=nxtUnt(Emy+Set+Map); if(atkTgt>0){ atkSrc=srcUnt=locElm(untGrp,UntTyp,""+sptCap); isCov=sptCap==Air && ran(X)<4; untOpt=Fir; if(isBrf){ txt("211 "+wrdOut(pri(atkSrc),BasId)+(isCov?" covering":" attacking")); return; } //if(isBrf } //if(atkTgt>0 } //if(untOpt<1 && if(untOpt<1) a2=srcUnt=nxtUnt(Aly+Set+Map); //set cyc beg unt ptr case 4: if(untOpt<1){ //pik unt for opr newUnt=srcUnt; isc2=nxtUnt(Aly+Set+Map)>0; if(isc2){ b2=newUnt; //pref actv of 2nd lvl unts: newUnt of nxtUnt() while(b2!=a2 && valOut(b2,UntStp)!=1) b2=nxtUnt(Aly+Set+Map); srcUnt=newUnt; //newUnt of nxtUnt() srcCoo=valOut(srcUnt,UntCoo); //txt("021"); txt("121"+wrdOut(srcUnt,UntDsg)+" @"+cnvCoo(srcCoo)); //~test ln } //if(isc2 else if(atkTgt>0) untOpt=Atk; else{ y2+=2; //skip to rsv ety chk macPik(); return; } //else(atkTgt>0 } //if(untOpt<1 if(untOpt<1 && (valOut(srcUnt,UntAct)<0?-C9-1:C9)<1){ //C9 of valOut() if(atkTgt>0){ isc2=chkFir(srcUnt,atkTgt); if(isc2) untOpt=Fir; } //if(atkTgt>0 ~} req by nxt else else{ b2=nxtUnt(Emy+Set+Map); do{ c2=nxtUnt(Emy+Set+Map); }while(c2>0 && !(c2==b2 || chkFir(srcUnt,c2))); isc2=c2>0 && chkFir(srcUnt,c2); isc2=isc2 && (!isb2 || isa2 || srcCoo/C>1); //GER priority to exit if(isc2){ atkTgt=c2; atkSrc=srcUnt; untOpt=Fir; } //if(isc2 } //else(atkTgt>0 } //if(untOpt<1 if(untOpt==Fir && atkSrc>0){ atkSrc=0; tgtCoo=valOut(atkTgt,UntCoo); //txt("031"); txt("131"+wrdOut(atkTgt,UntDsg)+" @"+cnvCoo(tgtCoo)); //~test ln terBon=(hexTer(tgtCoo)+2)/3; atkCnt=atkStr=0; adjBon=Neg; //ini "all atkg unts adjacent" val tnkBon=airBon=0; //ini Tigers atkg val, local air suppr } //if(untOpt==Fir && if(untOpt<1 && atkTgt>0) if(srcUnt!=a2){ macPik(); //calls this case again return; } //if(srcUnt!=a2 else untOpt=Atk; //no more joining unts firing y2++; case 5: //moves isc2=rsvCnt(newSid)<1; b2=C8; //C8 of rsvCnt() isc2=isc2 || cooOcc(C*etyCol+sltRow+1)>0 && !isA6; if(untOpt<1 && (isa2 || isc2) && (!isb2 || srcCoo/C>lodCol && b2>=exiReq)){ isc2=isb2; b2=0; //ini #unts in col 1 if(isc2 && srcCoo/C<2){ //exi map now? b2++; c2=0; //ini #of others at stp 2 newUnt=srcUnt; while(nxtUnt(Aly+Map)!=srcUnt && H4/C<2){ //_4s of nxtUnt() b2++; if(F4>1) c2++; } //while(nxtUnt(Aly+Map)!=srcUnt && isc2=b2+exiCnt>=exiReq && (c2<1 || valOut(srcUnt,UntStp)>1); } //if(isc2 && if(isc2 || !isb2 && leaCol2 && srcCoo%C<4) c2++; d2=valOut(srcUnt,UntOgn); isc2=toOk(srcUnt,wayHex(srcCoo,c2)); e2=B5; //_5s of toOk() isc2=isc2 && (!isb2 || b2+exiCnt>=exiReq || D5>0 && D5+E5>3 && hexDst(e2,d2)>hexDst(srcCoo,d2) && (tgtCnt(newSid)>4 || D5>4)); //D5 of tgtCnt() if(isc2 && isb2==(isBy(e2,Emy)?1:D8)>f2){ //D8 of isBy() f2=D8; untOpt=c2; //~for US, hold at fort hex in rng } //if(isc2 && } //for(c2=1; } //if(isc2 || if(untOpt<1 && tgtCnt(newSid)1){ //I8 of isBy() c2=I8; for(b2=1;b2<7;b2++) //chk for bak out hex if(toOk(srcUnt,wayHex(srcCoo,b2)) && D5>0 && !isBy(B5,Emy)) //_5s of toOk() if(I80 && (!isb2 || srcCoo/C>lodCol)){ //~don't lv rgh ter if adj to clr ter isc2=trnCnt>trnMax-2 || crdCnt(13,isb2?Bla:Red)>0 && E8>60; //E8 of crdCnt() for(c2=1;c2<7;c2++) if(toOk(srcUnt,wayHex(srcCoo,c2)) && D5>0 && (B5>102 || cooOcc(103)>0 && E6!=newSid) //_5s of toOk(), E6 of cooOcc() && (isBy(B5,Emy) || hexDst(C8,B5)2 || E9==2 && !chkFir(srcUnt,Z8[Rng2+1]))){ //E9 of hexDst() untOpt=c2; break; } //if(toOk(srcUnt,wayHex(srcCoo, } //if(isa2 && if(untOpt<1 && srcUnt!=a2){ y2--; macPik(); return; } //if(untOpt<1 && y2++; case 6: if(untOpt<1 && (trnCnt>1 || isb2) && actVal>actCnt && stkCoo<1 //rsv unt map ety && (!isb2 || trnCnt>1 || actVal>4 || crdCnt(13,Act)>0 && E8<70) //E8 of crdCnt() && rsvCnt(newSid)>0){ //~?(actVal>actCnt || [Tgr rsv or Tgr prev ety this rd]) see cooOcc() blw b2=ran(B8); //_8s of rsvCnt() srcUnt=Z8[b2]; if(srcUnt==Z8[0] && B8>1) //non-Tgr default srcUnt=Z8[b2==B8?1:b2+1]; e2=ran(X)<7?Z8[0]:0; //pref rsv Tgr ety opt blw b2=C*etyCol; c2=d2=isb2 && sltRow>0?sltRow:ran(3)+1; while(isHex(b2+d2+1) && cooOcc(C9)>0 && (!isA6 || E6!=newSid)) //C9 of isHex(), _6s of cooOcc() d2+=c2>3?-1:1; //~?[prev ety this rd] if(isHex(b2+d2+1)){ untOpt=d2; if(e2>0 && F6>0) srcUnt=e2; } //if(isHex(b2+d2+1 } //if(untOpt<1 && if(!isa2 && untOpt<1){ isa2=true; //beg 2nd pass y2-=3; macPik(); return; } //if(untOpt<1 && if(untOpt==Atk) srcUnt=oprUnt; if(untOpt<1 || srcUnt<1) untOpt=Hlt; y2++; if(isBrf && untOpt==Hlt){ txt("211end round"); return; } //if(isBrf && case 7: if(untOpt0) //tgt/atk'g in progress srcUnt=nxtUnt((atkSrc>0?Emy:Aly)+Set+Map); //Set incl not prior tgt this rnd y2++; case 2: newUnt=srcUnt; //replace ptr for nxtUnt() on cur focus unt do //next (focus) unit in check cycle isb2=nxtUnt(isAll?Any:(atkSrc>0?Emy+Set+Map:(atkTgt>0?Aly+Set+Map:Aly+Set)))>0; //!isAll -> skip acted unts while(isb2 && !isAll //when checking "rdy", skip nonphasing unts: && (newSid==sidPoo //non- setup unts, excluded spt unts, unavail US reserve unts && (valOut(newUnt,UntTyp)>=Aty && C9!=sptCap //newUnt of nxtUnt() || trnCnt<2 && valOut(newUnt,UntCoo)>1200 && C9<1204) //C9 of valOut() || newSid>sidPoo && valOut(newUnt,UntCoo)>M && C9<1200)); //exited GER unts if(!isb2 && nxtUnt(Any)>0) isAll=true; //no unacted phasing unts to highlight (focus) srcUnt=newUnt; //newUnt of nxtUnt() basUnt=pri(srcUnt); srcCoo=valOut(srcUnt,UntCoo); srcTyp=valOut(srcUnt,UntTyp); a2=valOut(srcUnt,UntAct); b2=sid(srcUnt); y2++; case 3: shoUnt(-srcUnt); //csr on focus unt txt("011"); if(atkSrc+atkTgt>0) txt("126atk= "+(atkTgt>0?atkStr-(terBon+airBon+adjBon+tnkBon) :(valOut(atkSrc,UntTyp)>=Aty?valOut(pri(atkSrc),BasSt1):0))); else if(!isDon && srcCoo0?'+':'-')+']'); isa2=!isDon && b2==newSid && atkSrc<1 //opr Ok flg- own side, not targeting: elmNum of sid() && a2<1 //further action allowed && (srcTypactCnt || a2<0 || srcCoo>M) //both avail options req activation cost, unless waivered && (stkCoo<1 || stkCoo==srcCoo || srcCoo>M) //in case of one stack activ && (srcCoo1200 && srcCoo<1204 && trnCnt>1 //3 reserve units only after trn 1 || srcCoo>=1204); //off bd spt & GER if(!isDon){ txt("121 " +(atkSrc+atkTgt>0?(atkSrc>0?"*Targeting.*":"*Attacking.*") :(!isb2?"*No unacted unit.*" :(isa2 && actCnt>=actVal && a2>=0?"*No activ pts.*" :(isa2 && basUnt0 && srcCoo=sptCat && sptCap>0) && trnCnt>0?"7) fire":""))); txt("133"+(trnCnt>0?crdSym(rndCrd$)+" (" +(stkCoo>0?(stkCoo0?"draw":(atkSrc>0?"halt":"quit")))); //Hlt cst txt("1259) size"); //Siz cst txt("131 0) chkg "+(isAll?"all":(atkSrc>0?"tgt ":(atkTgt>0?"fir ":"rdy "))+wrdOut(b2,SidId))); txt("234 trn "+trnCnt+", rnd "+rndCnt); return; case 4: if(inpVal==Siz){ chgBd(); return; //y2-- in reTrd() will resume at case 3: } //if(inpVal==Siz shoUnt(cooOcc(srcCoo)); //rmv csr if on ~just (srcUnt) to lv btm unt of stk sho'g if(inpVal==Hlt && atkSrc>0){ //break off tgt'g atkSrc=inpVal=0; isCov=false; } //if(inpVal==Hlt && if(inpVal==Fir) isa2=atkSrc>0 && srcCooSiz){ if(inpVal==0){ //key2$=='0' isAll=!isAll; y2-=isAll?1:2; } //if(inpVal==0 else y2-=!isa2 && inpVal>0 && inpVal0?Atk:inpVal; if(untOptsidPoo; //GER side mov y2++; case 2: if(srcCoo>M){ a2=untOpt+(isEup && (topHexCol&1)>0?1:0); //ety row isa2=a2<=topHexRow+mapRowHt-1; etyCol=srcCoo>2*M?mapColWd:topHexCol; a2=C*etyCol+a2; } //if(srcCoo>M else{ a2=wayHex(srcCoo,untOpt); if(isb2 && D9M isa2=isa2 && (stkCoo<1 || stkCoo==srcCoo || stkCoo==a2 && srcCoo>M) && toOk(srcUnt,a2); isa2=isa2 && (actVal>actCnt || valOut(srcUnt,UntAct)<0 || isb2 && valOut(srcUnt,UntOgn)>M //else chk rsv ety Tgr activ waiver && (srcTyp==Tgr || isTgr && valOut(Z6[G6],UntOgn)>M && F6<2)); //_6s, isTgr of toOk() if(isa2){ tgtCoo=a2; movUnt(srcUnt,tgtCoo); if(isb2 && tgtCoo>M) exiCnt++; } //if(isa2 y2++; case 3: y2++; if(!isMac && !isa2){ shoUnt(-oprUnt); //csr on focus unt eq(a2$,true?"Can't move there" :"Can't do that (unspc'd error)"); txt("211 [ "+a2$+". ]"); return; } //if(!isMac && if(isa2 && isMac && isBrf){ txt("221Move from "+(srcCoo>M?"off board":""+cnvCoo(srcCoo)) +" to "+cnvCoo(a2)+'.'); return; } //if(isa2 && case 4: isa2=isa2 || isMac; //mrk Mac- ctl unt acted even if mov not made x2=0; go(); } //switch(y2 } //oprMov mth void oprAtk(){ //uses: if(x2!=OprAtk) y2=1; switch(y2){ case 1: x2=OprAtk; isa2=true; //opr Ok/ err flg a2$.setLength(0); //ini err msg y2++; case 2: if(untOpt==Fir && atkTgt0){ atkTgt=srcUnt; //falls thru to nxt case tgtCoo=srcCoo; terBon=(hexTer(tgtCoo)+2)/3; srcUnt=atkSrc; //swap: for chkFir(), UntAct mod, nxtUnt() chg or not srcTyp=valOut(srcUnt,UntTyp); srcCoo=valOut(srcUnt,UntCoo); basUnt=pri(srcUnt); atkCnt=atkStr=0; adjBon=Neg; //ini "all atkg unts adjacent" val tnkBon=airBon=0; //ini Tigers atkg val, local air suppr } //if(atkSrc>0 else{ atkSrc=srcUnt; //prep for tgt'g at usrPik() isa2=false; //don't mrk acted on rtn to oprExe() (but sho no err msg blw) } //else(atkSrc>0 y2++; case 3: y2++; if(!isa2 && srcTyp==Air){ //mac unused case txt("211 Choose 0) air strike or 1) air cover"); return; } //if(!isa2 && case 4: if(!isa2 && srcTyp==Air) //mac unused case, but for isb2 set isCov=inpVal==1; isb2=basUnt0) //try join atk if(isCov){ trnSpt=Air; airCoo=tgtCoo; shoMap(); shoFrc(); atkSrc=atkTgt=0; //no longer tgt'g or joining isCov=false; isa2=true; //mrk acted on rtn to oprExe() } //if(isCov else{ isa2=chkFir(srcUnt,atkTgt); if(isa2){ //~?mac msg if(!isb2 || E6>1) //E6 of chkFir() adjBon=0; if(isb2 && airCoo>0 && sid(srcUnt)>sidPoo && hexDst(srcCoo,airCoo)<2) airBon=1; atkCnt++; isc2=pri(atkTgt)0) //atkSrc,Tgt kept exclusive as atkTgt cond used in abv case atkTgt=0; //still tgt'g } //else(isa2 } //else(isCov y2++; case 6: y2++; if(untOpt==Atk){ atkVs(); return; } //if(untOpt==Atk case 7: if(untOpt==Atk){ //atk end chk if(!isb2){ //spt typ atk on stk of unts in hex newUnt=atkTgt; //rpl ptr for nxtUnt() do{ newUnt++; if(newUnt>=dtaEnd) newUnt=untGrp; }while(newUnt!=tgtUnt && (valOut(newUnt,UntStp)<1 || valOut(newUnt,UntCoo)!=tgtCoo)); if(newUnt!=tgtUnt){ atkTgt=newUnt; y2--; oprAtk(); return; } //if(newUnt!=tgtUnt trnSpt=srcTyp; } //if(!isb2 atkTgt=0; //no longer joining } //if(untOpt==Atk y2++; case 8: y2++; if(!isMac && !isa2 && atkTgt>0){ shoUnt(-srcUnt); //csr on focus unt if(a2$.length()<1) a2$.append("Can't do that (unspc'd error)"); else eq(a2$,"Can't fire there: "+a2$); txt("211 [ "+a2$+". ]"); return; } //if(!isMac && case 9: x2=0; go(); } //switch(y2 } //oprAtk mth //var lvl 3 routines void chgBd(){ if(x3!=ChgBd) y3=1; switch(y3){ case 1: x3=ChgBd; y3++; case 2: y3++; txt("011"); txt("111Choose size for gameboard"); //~ txt("131 (hlfHexSid<-8 disables thicker unit outlines)"); txt("421 new hlfHexSid (now= "+hlfHexSid+"): "); return; case 3: isa3=untBox<2; //is isb3=inpVal<-8 || inpVal==0 && isa3; //to be a3=inpVal==0?hlfHexSid:Math.min(20,Math.max(2,Math.abs(inpVal))); b3=hlfHexSid; hlfHexSid=a3; untBox=isb3?1:(a3+1)/5; x3=0; bdSiz(); //setSize() repaint()s unless inpVal=hlfHexSid in appletviewer hexFit(); if(a3==b3) reTrd(); } //switch(y3 } //chgBd mth void atkVs(){ //uses: atkTgt, atkStr if(x3!=AtkVs) y3=1; switch(y3){ case 1: x3=AtkVs; isHit=false; a3=terBon+airBon+adjBon+tnkBon; eq(a3$,"Attack"+(a3!=0?" ("+(a3>0?"+":"")+a3+") ":"")+" of " +atkStr+" vs "+wrdOut(atkTgt,UntDsg)+" @"+cnvCoo(tgtCoo)); y3++; case 2: txt("011"); if(atkStr<1 || atkStr-a3<1){ //sole Tgr rej eq(sym$,"none"); y3+=3; atkVs(); return; } //if(atkStr<1 txt("133"+crdSym(drwCrd())); isa3=rnkVal<0 || rnkVal==0 && hasAct>=allAct; //rnkVal of crdSym() isb3=rnkVal>10 || rnkVal==0 && hasActoprExe()->pikUnt() vic cnd chk return; } //if(isa3 if(isb3 && (isMac || inpVal!=1)){ y3-=2; atkVs(); return; } //if(isb3 && addTo(atkTgt,UntAct,Atk); //flg as been tgt this rnd isHit=!isb3 && atkStr>=rnkVal+a3; //isHit=true; //~test ln if(isHit){ addTo(atkTgt,UntStp,1); isa3=D7>2 || valOut(pri(atkTgt),BasTyp+D7)<1; //D7 of addTo() if(isa3){ //or just movUnt(atkTgt,isa3?0:tgtCoo); to elim or lose step movUnt(atkTgt,0); //rmv from play dtaIn(atkTgt,UntStp,"0"); //elim flg } //if(isa3 } //if(isHit y3++; case 5: shoUnt(atkTgt); //if reduced or missed y3++; txt("111 "+a3$); txt("133"+sym$); if(isBrf){ txt("221 "+(isHit?"Hits: target "+(isa3?"eliminated.":"reduced."):"Misses.")); return; } //if(isBrf case 6: shoUnt(cooOcc(tgtCoo)); //dpy top stk unt x3=0; go(); } //switch(y3 } //atkVs mth //var lvl 3 subroutines int nxtUnt(int val){ //Mac=0,Usr=1,Emy=2,Aly=3,Any=4,Set=5,Out=10,Map=15 (see cooOcc() for hex) A3=val; //passed thru to locUnt() B3=locUnt(A3); //=0 if none if(B3>=untGrp) newUnt=B3; return B3; } //nxtUnt fnc mth - rtns B3 (=newUnt if nonzero) & locUnt() rtn vars void movUnt(int elm,int to){ A3=elm; B3=to; //0= rmv unt from play C3=valOut(A3,UntCoo); //lv top of stk >2 unts, mrk a remaining unt as stk top if(cooOcc(C3)==A3 && D6>2) //_6s of cooOcc() dtaIn(Z6[2],UntOgn,"+"+valOut(Z6[2],UntOgn)); if(B6!=A3 && D6==2) //lv btm of 2 unt stk, rmv stk top mkr from remaining unt dtaIn(B6,UntOgn,""+valOut(B6,UntOgn)); if(B3>0 && cooOcc(B3)>0) //ent occ hex, mrk mov'g unt as stk top dtaIn(B6,UntOgn,""+valOut(B6,UntOgn)); //rmv '+' if any: B6 of cooOcc() dtaIn(A3,UntOgn,(B3>0 && B6>0?"+":"")+valOut(A3,UntOgn)); dtaIn(A3,UntCoo,""+B3); hexClr(C3); shoUnt(A3); if(B3==0) //keep end coo dta if elim (UntStp gets flg 0) dtaIn(A3,UntCoo,""+C3); } //movUnt mth //var lvl 4 subroutines int locUnt(int val){ A4=val; //Mac=0,Usr=1,Emy=2,Aly=3,Any=4,Set=5,Out=10,Map=15 isA4=isB4=false; if(A4>=Map){ isA4=true; A4-=Map; } //if(A4>=Map G4=A4>=Out?A4-Out:A4>=Set?A4-Set:A4; //can't be both rdy & dest E4=newUnt=dtaEnd) E4=untGrp-B4++; else{ F4=valOut(E4,UntStp); isB4=A4>=Out?true:F4>0; if(isB4){ if(G4==Any && (A4>=Out || A4=Set && A40?H4==stkCoo:actCnt=Set && I4=valOut(E4,UntSid); D4=locElm(sidPoo,SidVal,""+I4); if(isB4 && G4=dtaEnd while(B4<3 && !isB4); if(B4>2) E4=0; return E4; } //locUnt fnc mth - rtns ~ void hexClr(int at){ //refresh single hex (req some surrounding hexes too) dpy A4=at; if(cooOcc(A4)>0 && D6>1){ //if stk rem, no action req - _6s of cooOcc() shoUnt(B6); return; } //if(cooOcc(A4)>0 && Graphics g=getGraphics(); B4=A4/C; C4=A4%C; isA4=((isEup?B4:B4+1)&1)>0; //~Mortain mdl mod if(A4>M || B4==topHexCol || B4==topHexCol+mapColWd-1 //if lv wing/ edge hex || !isA4 && C4==topHexRow || isA4 && C4==topHexRow+mapRowHt-1){ g.setColor(hue(A4>M?(A4>2*M?GerBkg:UsBkg):MapBkg)); g.fillRect(hexCtr(A4)-hexWd/2,D9-hexHt/2,hexWd,hexHt); //D9 of hexCtr() } //if(A4>M for(D4=0;D4<7;D4++){ if(isHex(wayHex(A4,D4))) shoHex(F9); //F9 of wayHex() if(D4==2) D4+=2; } //for(D4=0; for(D4=B4-2;D4<=B4+2;D4++) for(E4=C4-1;E4<=C4+1;E4++) if((Math.abs(D4-B4)!=1 || E4-C4!=((B4&1)<<1)-1) && isHex(C*D4+E4) && cooOcc(C9)>0) //C9 of isHex() shoUnt(B6); //B6 of cooOcc() } //hexClr mth void shoFrc(){ //dpy all unts vis to vuSid for(A4=untGrp;A4M || cooOcc(C9)==A4) //C9 of valOut() shoUnt(A4); } //shoFrc mth //var lvl 5 subroutines void shoUnt(int elm){ A5=elm; isA5=A5<0; //flg to sho highlight frame around unit A5=Math.abs(A5); if(A5=dtaEnd || valOut(A5,UntStp)<1) return; G5=valOut(A5,UntCoo); if(G51; //stack in hex: D6 of cooOcc() G5=hexWd; H5=hexHt-1; if(hlfHexSid>3) H5-=hlfHexSid>>1; D5=B5-(G5>>1); //unt top lft corner coos E5=C5-(H5>>1); if(isB5){ J5=hexHt-1-H5>>1; E5-=J5; } //if(isB5 Graphics g=getGraphics(); I5=valOut(A5,UntSid); g.setColor(hue(GerBkg+I5)); if(isB5) g.fillRect(D5,E5,G5,H5+2*J5); g.fillRect(D5,E5,G5,H5); G5--; //note discrepancy between Java fill & draw dims H5--; g.setColor(hue(Un2Bkg+I5)); if(isB5) for(I5=0;I51) //A9$ of wrdOut() A5$.append('.').append(A9$.charAt(1)); else if(F5==8) A5$.append("/+"); K5=E5+H5-hlfHexSid/3; N5=ltrPt; //sto brf pt siz fitStr(str(A5$),lblPt,G5-2); g.setFont(ltr); g.drawString(ctrStr(str(A5$),ltr,G5),D5+C9,K5); //C9 of ctrStr if(hlfHexSid>4) //~?rpl w ctrStr() using BOLD g.drawString(str(A5$),D5+C9+1,K5); ltrPt=N5; //rcl brf pt siz fitStr("1",ltrPt,C); N5=G5/2; //sho cat sym O5=H5/4; M5=N5/Math.max(1,O5); //~?nec safety for /0 J5=B5-N5/2; if(F5==7) N5/=2; if(I5O5/6 && N5==G5/2){ N5/=3; J5+=N5+1; } //if(F5==4 && if(I5sidPoo || D5sidPoo && (D50 && valOut(G5,UntAct)0 && valOut(H5,UntAct)0 && if(isA5) B5++; } //if(valOut(G5,UntSid)==N5 else E5++; isA5=false; //rtn flg for any atkr vs F5 of sam cla F5=G5=0; for(H5=1;H5<=C5;H5++){ isB5=false; //hldr for isA5 J5=L5=0; //ini comb atk str, #atkrs, vs pot F5 M5=1; //ini adjBon for(K5=untGrp;K50 && valOut(K5,UntAct)1) //E6 of chkFir() M5=0; isC5=pri(Z5[H5])0 && A5>sidPoo && hexDst(valOut(K5,UntCoo),airCoo)<2) J5--; if(J5+M5>G5){ isA5=isB5; F5=Z5[H5]; G5=J5+M5; O5=L5; } //if(J5>G5 } //if(valOut(K5,UntSid)==N5 && } //for(H5=1; H5=O5; return B5; } //tgtCnt mth - rtns B5 (#fr unts acq tgts), C5 (#sep en tgts), D5 (#fr map unts), //E5 (#en map unts), F5 (tgt elm w most atkrs), G5 (atk str vs F5), H5 (#atkrs vs F5) //isA5 (F5 & any atkr sam cla), Z5[] (tgt elm lst) //var lvl 6 subroutines void bdSiz(){ //uses: hlfHexSid hexSid=hlfHexSid<<1; hexWd=hexSid+hlfHexSid; hlfHexHt=C*(hexSid+1)/hexAsp>>1; if(hlfHexSid==2 || hlfHexSid==3) hlfHexHt--; hexHt=hlfHexHt<<1; ltrPt=Math.max(hlfHexHt,1); ltr=new Font("SanSerif",Font.PLAIN,ltrPt); typHt=ltrPt+1; ioHt=3*typHt; lblWd=hexSid+(hexSid<7?1:0); lblPt=Math.max(lblWd*3/4,1); lbl=new Font("SanSerif",Font.PLAIN,lblPt); lblHt=lblPt; minLftMar=lblWd; minTopMar=lblHt; mapWd=hexWd*mapColWd+hlfHexSid+1+minLftMar+2*bdrWd; A6=mapRowHt; if(isEup) A6--;; mapHt=hexHt*A6+hlfHexHt+1+minTopMar+2*bdrWd; bdWd=mapWd; bdWd+=5*hexWd; //~Mortain mdl mod mapLft=bdWd-mapWd>>1; //~Mortain mdl mod bdHt=mapHt+ioHt+2; ioWd=bdWd; zonWd=ioWd/6; setSize(bdWd+1,bdHt+1); //only affects appletviewer(?) when args chgd(?) } //bdSiz mth void shoBd(){ //paint()-external graphics mth call forces complete redraw in AWT; // vs only clipping regions previously obscured by other windows Graphics g=getGraphics(); g.setColor(hue(BdBkg)); g.fillRect(0,0,bdWd,bdHt); g.setColor(hue(UsBkg)); g.fillRect(0,0,mapLft,mapHt); g.setColor(hue(GerBkg)); g.fillRect(mapLft+mapWd,0,mapLft,mapHt); g.setColor(hue(BrfBkg)); g.fillRect(0,mapHt,ioWd,ioHt+2); g.setColor(hue(BdBdr)); g.drawRect(0,0,bdWd,bdHt); g.drawRect(0,mapHt,ioWd,ioHt+2); } //shoBd mth void shoMap(){ Graphics g=getGraphics(); g.setColor(hue(MapBkg)); g.fillRect(mapLft,mapTop,mapWd,mapHt); g.setColor(hue(BdBdr)); g.drawRect(mapLft,mapTop,mapWd,mapHt); B6=topHexCol+mapColWd-1; D6=topHexRow+mapRowHt-eqRows-1; //eqRows of hexFit() if(isEup) D6=topHexRow+mapRowHt-1; for(A6=topHexCol;A6<=B6;A6++) for(C6=topHexRow;C6<=D6;C6++) if(isHex(C*A6+C6)) shoHex(C9); //C9 of isHex() hexLbl(); } //shoMap mth int cooOcc(int at){ //is apl to both on- & off- bd coos A6=at; for(B6=0;B6<=Z6Siz;B6++) Z6[B6]=0; B6=untGrp; C6=D6=F6=0; isB6=isTgr=false; //waivered unt in hex flg, Tigers in hex flg ~Mortain mdl mod while(B60){ B6=elmNum; //elmNum of locElm() if(valOut(B6,UntStp)>0){ //not elim Z6[++D6]=B6; if(!isTgr && valOut(B6,UntTyp)==Tgr){ isTgr=true; G6=D6; } //if(!isTgr && if(valOut(B6,UntAct)>=0 && C9<1) //unacted & unwaivered: C9 of valOut() Z6[++C6+RdyElm]=B6; isB6=isB6 || C9<0; //coloc unacted & waivered } //if(valOut(B6,UntStp)>0 B6++; } //while(B6M) F6++; if(B6>1 && A9$.charAt(0)=='+'){ //mak stk top unt 1st in ary: A9$ of valOut() E6=Z6[B6]; Z6[B6]=Z6[1]; Z6[1]=E6; } //if(if(B6>1 && } //for(B6=1; B6=Z6[1]; if(B6>0) E6=sid(B6); isA6=D6-(isTgr?1:0)=sptCat) return isA6; E6=hexDst(C6,D6); //if(true) return isA6; //~test ln if(E6>3 || E6>2 && hexTer(C6)!=Hil){ A6$.append("tgt out of range"); return isA6=false; } //if(E6>3 || if(E6<2) return isA6; losIni(C6,D6); isB6=isA9; //flg for vertex- joining LOS: isA9 of losIni() for(F6=1;F6Ope:false; if(isB6 && (F6&1)>0){ H6=wayHex(losHex(F6+1),7-hexWay(losHex(F6-1),G6)); //alt vtx-join hex isD6=isHex(H6)?hexTer(H6)>Ope:false; isC6=isC6 || isD6; } //if(isB6 && if(isC6){ isA6=false; A6$.append("line of sight blocked"); break; } //if(isC6 } //for(F6=1; return isA6; } //chkFir mth - rtns isA6 (1st unt may fire at 2nd) //var lvl 7 subroutines void shoHex(int at){ A7=at; E7=hexCtr(A7); F7=D9; //D9 of hexCtr() Graphics g=getGraphics(); B7=hexTer(A7); eq(A7$,str(A8$).substring(1)); //A8$ of hexTer() g.setColor(hue(MapBkg+B7)); //fill in background color G7=E7-hlfHexSid; H7=F7-hlfHexHt; I7=E7+hlfHexSid; J7=F7+hlfHexHt; for(C7=0;C70){ for(I7=0;I70 if(airCoo>0 && hexDst(airCoo,A7)<2){ g.setColor(StdHue[2]); G7=E7-C7; H7=F7-C7; if(E9<1){ //E9 of hexDst() g.drawLine(E7,H7,E7,F7+C7); g.drawLine(G7,F7,E7+C7,F7); } //if(E9<1 D7=C7/2; g.drawOval(G7,H7,C7*2,C7*2); g.drawOval(G7+D7,H7+D7,C7,C7); g.setColor(StdHue[9]); g.drawOval(--G7,--H7,C7*2+2,C7*2+2); g.drawOval(G7+D7,H7+D7,C7+2,C7+2); } //if(airCoo>0 && I7=A7$.length(); //show roads if(I7>0){ for(J7=0;J7<2;J7++){ for(C7=0;C7>1); H7=F7+(D9-F7>>1); //D9 of hexCtr() isB7=E7==G7; g.setColor(hue(MapBkg)); for(L7=-K7+J7;L7<=K7-J7;L7++) if(isB7) g.drawLine(E7+L7,F7,G7+L7,H7); else g.drawLine(E7,F7+L7,G7,H7+L7); if(J7<1){ g.fillRect(G7-K7/2,H7-K7/2,K7,K7+1); isC7=I7<3 && (D7==3 || D7==4) && str(A7$).indexOf("34")<0; if(isC7) g.fillOval(E7-K7+1,F7-K7+1,K7-1<<1,K7-1<<1); g.setColor(hue(RoaFgd)); if(isC7) g.drawOval(E7-K7,F7-K7,K7<<1,K7<<1); if(isB7) g.drawLine(E7-K7,F7,G7-K7,H7); else g.drawLine(E7,F7-K7,G7,H7-K7); if(isB7) g.drawLine(E7+K7,F7,G7+K7,H7); else g.drawLine(E7,F7+K7,G7,H7+K7); } //if(J7<1 } //while(C71 } //shoHex mth int sid(int elm){ A7=elm; return locElm(sidPoo,SidVal,wrdOut(A7,UntSid)); } //sid mth - rtns sidPoo elmNum of locElm void addTo(int elm,int nth,int num){ A7=elm; B7=nth; C7=num; D7=valOut(A7,B7)+C7; dtaIn(A7,B7,""+D7); } //addTo mth void shoWay(){ A7=mapHt; //sto mapHt+=bdrWd; txt("116 3"); txt("136 4"); mapHt+=typHt/2; txt("116 1 5"); txt("126 2 6"); mapHt-=typHt/3; txt("126 *"); mapHt=A7; //rcl } //shoWay mth //var lvl 8 subroutines void txt(String dta$){ eq(lin$,dta$); eq(inp$,lin$); //note: lin$ & inp$ passed thru KeyListener argLg=lin$.length(); //note: argLg & txtTyp passed thru KeyListener txtTyp=dig(lin$,0); B8=dig(lin$,1); C8=dig(lin$,2); Graphics g=getGraphics(); txtX=(C8-1)*zonWd+bdrWd+1; txtY=mapHt+B8*(typHt-1)-typHt/4+3+bdrWd; if(txtTyp==0){ //clear rect space //clear from desig zone right & down to btm of area txtX--; txtY-=(typHt+1)*3/4; C8=ioHt-(B8-1)*typHt-1; B8=ioWd-txtX; g.setColor(hue(BrfBkg)); g.fillRect(txtX,txtY,B8,C8); return; } //if(txtTyp==0 else{ g.setColor(hue(BrfFgd)); g.setFont(ltr); g.drawString(str(lin$).substring(txtCodLg),txtX,txtY); if(txtTyp==5){ //display in pseudo bold type g.drawString(str(lin$).substring(txtCodLg),txtX+1,txtY); txtTyp=1; } //if(txtTyp==5 } //else (txtTyp==0 isKey=false; if(txtTyp==2){ key5$=key4$=key3$=key2$=key1$='0'; inpVal=0; //ini for KeyListener } //if(txtTyp==2 else if(txtTyp>2) isLin=true; //decl as false, & leaves keyTyped() false } //txt mth int rsvCnt(int elm){ //~Mortain mdl mod A8=elm; //elm in sidPoo for sid being chkd for(B8=0;B8<=Z8Siz;B8++) Z8[B8]=0; B8=C8=0; //ini #unts waitg ety, #unts left E8=valOut(A8,SidVal); for(D8=untGrp;D80 && valOut(D8,UntSid)==E8 && valOut(D8,UntTyp)1200){ Z8[++B8]=D8; if(F8==Tgr) Z8[0]=D8; } //if(valOut(D8,UntCoo)>1200 } //if(valOut(D8,UntSid)==E8 && return B8; } //rsvCnt mth - rtns B8 (elm sid's #unts waitg ety), C8 (#unts left), Z8[0] (Tgr unt in rsv) void dtaIn(int elm,int nth,String ins$){ eq(A8$,ins$); nthDiv(elm,nth); //note ini asgn: A9=elm; B9=nth insStr(z1$[A9],begDiv,endDiv,A8$); } //dtaIn mth int pri(int elm){ //db ary chk suite: has() - pri() - locElm() - val/wrdOut() - nthDiv() A8=elm; return locElm(untPoo,BasTyp,wrdOut(A8,UntTyp)); } //pri mth - rtns elmNum of locElm int hexTer(int at){ if(!isHex(at)) return A8=Neg; eq(A8$,wrdOut(aoMap-1+B9,A9)); //_9s of isHex() return A8=dig(A8$,0); } //hexTer fnc mth - rtns A8 hex bkg, A8$ hex obj lst int locElm(int elm,int nth,String obj$){ //db ary chk suite: pri() - locElm() - val/wrdOut() - nthDiv() begElm=elm; C8=nth; eq(A8$,obj$); //may be "" due to .startsWith() blw elmNum=0; //default val for none found endElm=(begElm>=untGrp?dtaEnd :(begElm>=sidPoo?untGrp :sidPoo))-1; //for begElm>=untPoo for(B8=begElm;B8<=endElm;B8++){ if(wrdOut(B8,C8).startsWith(str(A8$))){ elmNum=B8; break; } //if(wrdOut(B8,C8).startsWith( } //for(B8=begElm; return elmNum; } //locElm mth - rtns elmNum ~?endElm void hexFit(){ //uses: hlfHexSid,hexAsp,mapWd/Ht,minLftMar/TopMar,bdrWd, //aoColWd/RowHt,mapColWd/RowHt,topHexCol/HexRow mapColWd=(mapWd-hlfHexSid-1-minLftMar-2*bdrWd)/hexWd; mapColWd=Math.min(mapColWd,aoColWd); //clip right map edge at col aoColWd mapRowHt=(mapHt-hlfHexHt-1-minTopMar-2*bdrWd)/hexHt; eqRows=mapHt-minTopMar-2*bdrWd-mapRowHt*hexHt>hlfHexHt?-1:0; if(isEup) mapRowHt++; topHexCol=Math.min(topHexCol,aoColWd-mapColWd+1); //adj col numbering for clipping topHexCol=Math.max(topHexCol,1); if(topHexRow+mapRowHt>=aoRowHt) //clip lower map edge at row aoRowHt if((topHexCol&1)>0) if(eqRows==0){ mapRowHt--; eqRows--; } //if(eqRows==0 else eqRows=0; topHexRow=Math.min(topHexRow,aoRowHt-mapRowHt+1); //adj row numbering for clipping topHexRow=Math.max(topHexRow,1); mapLftMar=Math.max(minLftMar,(mapWd-2*bdrWd-mapColWd*hexWd-hlfHexSid)/2); mapTopMar=Math.max(minTopMar,(mapHt-2*bdrWd-mapRowHt*hexHt+hlfHexHt*eqRows)/2); } //hexFig mth - rtns: hlfHexHt,hexSid/Ht,mapColWd/RowHt,eqRows, //topHexCol/Row,mapLftMar/TopMar void hexLbl(){ //uses: hlfHexSid/Ht,hexSidmapLft/Top,mapColWd/RowHt, //mapTopMar/lftMar,topHexCol/Row,lblHue Graphics g=getGraphics(); g.setFont(lbl); g.setColor(hue(LblFgd)); //label cols (across top of map) E8=hlfHexSid*3/4; A8=mapLft+bdrWd+mapLftMar+hexSid-E8; for(F8=0;F8<=mapColWd-1;F8++){ B8=A8+F8*hexWd; C8=mapTopMar+(F8&1)*hlfHexHt; if(isEup) C8=mapTopMar+(F8+1&1)*hlfHexHt; G8=F8+topHexCol; G8+=X; //~Mortain mdl mod eq(A8$,"0"+G8); g.drawString(str(A8$).substring(A8$.length()-2),B8,C8); } //for(F8=0; //label rows (down left side of map) D8=topHexCol&1; A8=mapTop+bdrWd+mapTopMar+hlfHexHt*(D8+1)-hlfHexHt/4; D8=(1-D8)*eqRows; if(isEup) D8=1; E8=mapLft+mapLftMar-2*E8; for(F8=0;F8<=mapRowHt-1-D8;F8++){ B8=A8+F8*hexHt; eq(A8$,"0"+(F8+topHexRow)); g.drawString(str(A8$).substring(A8$.length()-2),E8,B8); } //for(F8=0; } //hexLbl mth boolean isBy(int at,int val){ //~note GER Fwd=col A8=at; B8=val; //Emy, +Fwd K8=B8>=Fwd?B8-Fwd:B8; isA8=false; //ini rtn flg for(J8=0;J8<=Z8Siz;J8++) Z8[J8]=0; C8=D8=M; //ini closest qual hex, dst G8=valOut(K8==Emy?sidPoo+1-(newSid-sidPoo):newSid,SidVal); H8=I8=0; //ini Z8[] idx vars for(J8=untGrp;J80 && valOut(J8,UntSid)==G8 && valOut(J8,UntTyp)sidPoo))){ //C9 of valOut() E8=C9; F8=hexDst(A8,E8); if(F8=+'a') A8$.append((char)A8); dlrSiz=A8$.length()-2; //=53 (4 suits+ Joker) dlr$.setLength(0); //dealer deck's card seq for(A8=dlrSiz;A8>=1;A8--){ dlr$.append(A8$.charAt(ran(A8))); insStr(A8$,B9,B9+1,""); //B9 of ran() } //for(A8=dlrSiz; dlrTop=1; //nxt crd to be dealt= 1st (leftmost) in dlr$ return; } //dlrShf mth - rtns dlr$, dlrTop for 1st drw int crdCnt(int num,int val){ A8=num; //crd vals <= to be counted (C*m+n= rng <=m & >=n) B8=val; //Red, Bla or Any suits to be counted, or Act= ratio activ pts G8=1; if(A8>C){ //sep rng lims G8=A8%C; A8/=C; } //if(A8>C C8=D8=0; isA8=false; for(E8=dlrTop-1;E8=G8 && rnkVal<=A8){ //rnkVal, A$ of crdVal() if(B8==Act){ F8=rnkVal>X?StkMax:rnkVal+1>>1; if(A$>'Z') D8+=F8; else C8+=F8; } //if(B8==Act else if(B8==Any || A$>'Z'==(B8==Bla)) C8++; }else if(rnkVal==0) isA8=true; //Joker in deck E8=C*C8/Math.max(1,B8==Act?D8:dlrSiz-dlrTop+(isA8?0:1)); return C8; } //crdCnt mth - rtns //var lvl 9 subroutines char drwCrd(){ return crd$=dlrTop>dlrSiz?(char)(+'A'-2):dlr$.charAt(dlrTop++-1); } //drwCrd mth - rtns crd$, dlrTop for next drw StringBuffer crdSym(char c$){ A$=c$; sym$.setLength(0); if(crdVal(A$)==10) //A$ unchgd by crdVal() sym$.append('1'); sym$.append("X0A234567890JQK".charAt(rnkVal+1)); //rnkVal, A9 of crdVal() sym$.append("X0HDSC".charAt(rnkVal<1?rnkVal+1:A9/13+2)); return sym$; } //crdSym mth - rtns sym$ ("XX"= no card, "00"=joker, "AH".."AC", "2H", etc.) & see crdVal() int crdVal(char c$){ A$=c$; A9=A$-(A$>'Z'?'a'-'Z'-1:0)-'A'; //=+A$-(A$>'Z'?+'a'-+'Z'-1:0)-+'A' return rnkVal=A9%13+1; } //crdVal mth - rtns rnkVal (-1=no card, 0=joker, A=1..K=13) int cnvCoo(int at){ A9=at; B9=at/C; C9=at%C; B9+=A9>M?-X:X; if((B9&1)>0) C9+=A9>M?1:-1; return A9=C*B9+C9; } //cnvCoo mth - rtns translated map coo: 1101<=>102 int hexCtr(int at){ //uses: hlf/hexHt,hexSid/Wd,mapLft/Top(Mar),topHexCol/Row,bdrWd A9=at/C; B9=at%C; if(A9<11){ //~Mortain mdl lim: cols 0..10 req (for road extensions) F9=B9-topHexRow; if((topHexCol&1)>0) //adj for rows' col shift in nonstatic scrn edge arrangemt G9=A9+1&1; else G9=-(A9&1); D9=mapTopMar+mapTop+bdrWd+F9*hexHt+G9*hlfHexHt+hlfHexHt; //ctr pt Y of map hex if(isEup) D9-=hlfHexHt; E9=A9-topHexCol; C9=mapLftMar+mapLft+bdrWd+E9*hexWd+hexSid; //ctr pt X of map hex } //if(A9<11 else{ E9=A9%X; //~Mortain mdl mod C9=(A9>20?mapLft+mapWd:0)+hexWd/2+E9*hexWd/6+bdrWd; if(E9>1) C9+=hexWd; //ctr pt X of wing space E9=(mapHt-5*hexHt)/6; D9=B9*(hexHt+E9)-hlfHexHt+mapTop+bdrWd; //ctr pt Y of wing space } //else(A9<11 return C9; //ctr pt X of unt loc } //hexCtr mth rtns C9, w D9 avail (scrn Hor,Ver pix coo) boolean isHex(int at){ A9=at/C; B9=at%C; C9=at; isA9=!(A9<1 || A9>mapColWd || B9<1 || B9>mapRowHt); if(isEup) isA9=isA9 && (A9&1)!=B9 && mapRowHt*(A9+1&1)!=B9; return isA9; } //isHex mth int wayHex(int at,int to){ //to (way)= 0..6 A9=at/C; B9=at%C; C9=to; if(C9<1) return F9=C*A9+B9; D9=A9+(C9<3?-1:C9>4?1:0); //cnv way to coo F9=C9-1&1; G9=A9&1; E9=B9+F9-G9; if(C9-G9==3) E9+=(F9<<1)-1; return F9=C*D9+E9; } //wayHex mth - rtns coo int hexWay(int at,int to){ //at,to must be adjacent hexes A9=at/C; B9=at%C; C9=to/C; D9=to%C; return E9=7+(C9-A9<<2)+(D9-B9)+(A9&1)>>1; } //hexWay mth - rtns side #1..6 dir from at to to int losIni(int at,int to){ //hex LOS protractor: comprising sbrs losIni() & losHex() // slope calc type = rise/run corrected for row height offset // note LOS algorithm's trend when vertex joining / side splitting = // always choose higher-numbered questionable coord //nb. LOS impl copyright reg 9/26/94 by H. Trump: used under license losDst=hexDst(at,to); losRun=C9-A9; //_9s of hexDst() losDrp=(B9<<1)-(A9&1); losRis=(D9<<1)-(losDrp+(C9&1)); losTri=A9*losDst+(losDst>>1); losRol=losRis<0?losDst-1:0; isA9=F9==0 && (I9&1)<1 || E9==I9<<1; //set flg for vertex- joining LOS return losStp=1; //ini as 1st LOS hex } //losIni fnc mth int losHex(int num){ //interpolate hex col & row at step - uses: all los_ vars of losIni() losStp=num; //losHex(0)=ori hex, 1=1st los hex adj to ori, ..losDst=tgt hex A9=(losStp*losRun+losTri)/losDst; B9=A9&1; B9=((losStp*losRis-losRol)/losDst+losDrp+(B9^1)>>1)+B9; //or ..+1-B9>>.. //nb. row comp dsn & LOS impl copyright reg 9/26/94 by H. Trump: used under license return C9=C*A9+B9; } //losHex fnc mth int hexDst(int at,int to){ //map distance by shortest contiguous hex path // tracking type (if outside diagonal wedge)= trace col to intersecting diag, then trace diag A9=at/C; B9=at%C; C9=to/C; D9=to%C; E9=I9=Math.abs(C9-A9); //I9 used at losIni() F9=D9-B9; if(F9==0) return E9; G9=A9&1; H9=Neg; if(F9>0){ G9=G9^1; //or =1-G9 H9=1; } //if(F9>0 G9=H9*(E9+G9>>1); if(Math.abs(F9)>Math.abs(G9)) E9+=Math.abs(F9-G9); return E9; } //hexDst fnc mth int valOut(int elm,int nth){ //db ary chk suite: pri() - locElm() - val/wrdOut() - nthDiv() A$=wrdOut(elm,nth).charAt(0); //A9,B9 of nthDiv() return C9="+-0123456789".indexOf(A$)<0?0 :Integer.parseInt(str(A9$).substring(A$=='+'?1:0)); //A9$ of wrdOut() } //valOut mth String wrdOut(int elm,int nth){ //db ary chk suite: pri() - locElm() - val/wrdOut() - nthDiv() nthDiv(elm,nth); //note ini asgns: A9=elm, B9=num eq(A9$,str(z1$[A9]).substring(begDiv,endDiv)); return str(A9$); } //wrdOut mth void nthDiv(int elm,int nth){ //db ary chk suite: pri() - locElm() - val/wrdOut() - nthDiv() A9=elm; B9=nth; begDiv=0; for(C9=B9;C9>0;C9--){ endDiv=str(z1$[A9]).indexOf(Div$,begDiv); if(C9>1) if(endDiv==-1) ;//note error of nth>#Divs else begDiv=endDiv+1; } //for(C9=B9; if(endDiv==-1) endDiv=z1$[A9].length(); } //nthDiv mth - 1st field nth= 1 int ran(int num){ A9=num; if(A9<2) //+ or 0 only return B9=A9; B9=(int)(A9*Math.random()); return ++B9; //=(int)Math.floor(A9*Math.random()+1) } //ran mth - rtns: B9= rdm int in rng 1..A9 int dig(StringBuffer dta$,int loc){ return dig(str(dta$),loc); //note ini asgn: A9$=dta$, A9=loc } //dig mth w StringBuffer arg int dig(String dta$,int loc){ eq(A9$,dta$); A9=loc; return B9=+A9$.charAt(A9)-Asc0; } //dig mth w String arg String ctrStr(String dta$,Font fnt,int val){ A9=val; //fit wd Graphics g=getGraphics(); FontMetrics ltrSiz=g.getFontMetrics(fnt); B9=ltrSiz.stringWidth(dta$); C9=(A9-B9)>>1; //lft/rht spc return dta$; } //ctrStr mth void fitStr(String dta$,int num,int val){ eq(A9$,dta$); A9=num; //max Pt siz: -num= Bold B9=val; //fit wd Graphics g=getGraphics(); ltrPt=Math.abs(A9)+1; do{ ltr=new Font("SanSerif",A9>0?Font.PLAIN:Font.BOLD,--ltrPt); FontMetrics ltrSiz=g.getFontMetrics(ltr); C9=ltrSiz.stringWidth(dta$); }while(C9>B9); D9=(B9-C9)>>1; //lft/rht spc } //fitStr mth //var lvl 0 subroutines Color hue(int val){ A0=val; return hues[A0] String utilities: void insStr(StringBuffer sbj$,int at,StringBuffer ins$){ insStr(sbj$,at,at,ins$); } //insStr mth void insStr(StringBuffer sbj$,int at,String ins$){ insStr(sbj$,at,at,ins$); } //insStr mth void insStr(StringBuffer sbj$,int at,int to,StringBuffer ins$){ insStr(sbj$,at,to,str(ins$)); } //insStr mth void insStr(StringBuffer sbj$,int at,int to,String ins$){ eq(A0$,sbj$); eq(sbj$,str(A0$).substring(0,at) +ins$+str(A0$).substring(to)); } //insStr mth void eq(int elm,StringBuffer obj$){ eq(z1$[elm],obj$); } //eq mth w int (array elm) arg void eq(StringBuffer sbj$,StringBuffer obj$){ eq(sbj$,str(obj$)); } //eq mth w StringBuffer arg void eq(int elm,String obj$){ eq(z1$[elm],obj$); } //eq mth w int (array elm) arg void eq(StringBuffer sbj$,String obj$){ sbj$.setLength(0); sbj$.append(obj$); } //eq mth w String arg String str(StringBuffer sbj$){ //When used without assigning= a String var, doesn't alloc mry to copy Buffer, //just refs existing Buffer (per API detail: Implementation advice) for efficiency. return sbj$.toString(); } //str fnc mth - cnv bfr to str: allows for str-only opns on bfr contents } //Applet's cla