using Gtk; using System; public class Worms:TerrPlugin{ mutable host:TerrHost; public Host:TerrHost { set { host=value; } } mutable nr:int; //settings mutable sMode=0; //single worm mode mutable sJump=5000; mutable sMoves=2000000; //multiple worms mode mutable sWorms=500; mutable sColMin=0.0; mutable sColMax=300.0; mutable sLengthMin=10; mutable sLengthMax=500; mutable sOverlay=false; //------------------------------------------------------------------------------------------------------------- public Register(n:int):void{ nr=n; def mItem=MenuItem("worms"); host.MGener.Append(mItem); mItem.Activated+=EventHandler(optionsWin); } //------------------------------------------------------------------------------------------------------------- public Run():void{ host.Start(nr); def r=Random(); def map=host.HMap; def sizeX=map.SizeX; def sizeY=map.SizeY; for (mutable x=0; xdouble; repeat (sWorms){ def col=r.Next(sColMin:>int,sColMax:>int); def length=r.Next(sLengthMin,sLengthMax); mutable x=r.Next(sizeX); mutable y=r.Next(sizeY); for (mutable i=0; i when (y>0) y--; | 1 => when (y when (x>0) x--; | 3 => when (x Console.WriteLine("hmm, it seems that a very weird error occurred..."); } if (!sOverlay) map[x,y]=col else map[x,y]+=col; } host.ProgBar.FractionAddResp(progStep); } } else { mutable x=r.Next(sizeX); mutable y=r.Next(sizeY); map[x,y]++; def tmpFract=sMoves/100; for (mutable i=0; i when (y>0) y--; | 1 => when (y when (x>0) x--; | 3 => when (x Console.WriteLine("hmm, it seems that a very weird error occurred..."); } map[x,y]+=1; when (i%tmpFract==0) host.ProgBar.FractionAddResp(0.01); } } host.Update(); } //------------------------------------------------------------------------------------------------------------- private optionsWin(_o:object,_e:EventArgs):void{ def win=Window("worms"); win.BorderWidth=5; def tips=Tooltips(); def whole=VBox(false,10); win.Add(whole); def sett=VBox(false,10); whole.PackStart(sett); def mode0VBox=VBox(false,10); def wormsHBox=HBox(false,10); mode0VBox.PackStart(wormsHBox); def wormsLab=Label("worms:"); wormsHBox.PackStart(wormsLab); def wormsSpin=SpinButton(0.0,100000.0,1.0); wormsHBox.PackStart(wormsSpin); tips.SetTip(wormsSpin,"number of worms",""); wormsSpin.Value=sWorms; wormsSpin.ValueChanged+=fun(_) { sWorms=wormsSpin.ValueAsInt; } def colMinSpin=SpinButton(0.0,sColMax,0.1); def colMaxSpin=SpinButton(sColMin,1000.0,0.1); def colMinHBox=HBox(false,10); mode0VBox.PackStart(colMinHBox); def colMinLab=Label("colour min.:"); colMinHBox.PackStart(colMinLab); colMinHBox.PackStart(colMinSpin); tips.SetTip(colMinSpin,"minimal colour of the worm",""); colMinSpin.Value=sColMin; colMinSpin.ValueChanged+=fun(_){ sColMin=colMinSpin.Value; colMaxSpin.Adjustment=Adjustment(sColMax,sColMin,1000.0,0.1,10.0,0); } def colMaxHBox=HBox(false,10); mode0VBox.PackStart(colMaxHBox); def colMaxLab=Label("colour max.:"); colMaxHBox.PackStart(colMaxLab); colMaxHBox.PackStart(colMaxSpin); tips.SetTip(colMaxSpin,"maximal colour of the worm",""); colMaxSpin.Value=sColMax; colMaxSpin.ValueChanged+=fun(_){ sColMax=colMaxSpin.Value; colMinSpin.Adjustment=Adjustment(sColMin,0.0,sColMax,0.1,10.0,0); } def overlayHBox=HBox(false,10); mode0VBox.PackStart(overlayHBox); def overlayLab=Label("overlay:"); overlayHBox.PackStart(overlayLab); def overlayChck=CheckButton("off"); overlayHBox.PackStart(overlayChck); overlayChck.Toggled+=fun(_){ if (overlayChck.Label=="off") { sOverlay=true; overlayChck.Label="on"; } else { sOverlay=false; overlayChck.Label="off"; } } def mode1VBox=VBox(false,10); def movesHBox=HBox(false,10); mode1VBox.PackStart(movesHBox); def movesLab=Label("moves:"); movesHBox.PackStart(movesLab); def movesSpin=SpinButton(0.0,100000000,1.0); movesHBox.PackStart(movesSpin); tips.SetTip(movesSpin,"number of moves of the worm",""); movesSpin.Value=sMoves; movesSpin.ValueChanged+=fun(_) { sMoves=movesSpin.ValueAsInt; } def jumpHBox=HBox(false,10); mode1VBox.PackStart(jumpHBox); def jumpLab=Label("plotter jump:"); jumpHBox.PackStart(jumpLab); def jumpSpin=SpinButton(0.0,100000,1.0); jumpHBox.PackStart(jumpSpin); tips.SetTip(jumpSpin,"1/(probability of worm jump)",""); jumpSpin.Value=sJump; jumpSpin.ValueChanged+=fun(_) { sJump=jumpSpin.ValueAsInt; } def modes=array["multiple worms","single worm"]; def modeHBox=HBox(false,10); def modeLab=Label("mode:"); modeHBox.PackStart(modeLab); def modeBox=ComboBox.NewText(); modeHBox.PackStart(modeBox); foreach (i in modes) modeBox.AppendText(i); modeBox.Active=sMode; modeBox.Changed+=fun(_){ sMode=modeBox.Active; if (sMode==0) { mode1VBox.HideAll(); mode0VBox.ShowAll(); win.ReshowWithInitialSize(); } else { mode0VBox.HideAll(); mode1VBox.ShowAll();win.ReshowWithInitialSize();} } sett.PackStart(modeHBox); sett.PackStart(mode0VBox); sett.PackStart(mode1VBox); def buttBox=HBox(false,10); whole.PackStart(buttBox); def aboutButt=Button("about"); buttBox.PackStart(aboutButt); aboutButt.Clicked+=EventHandler(aboutButtHandler); def cancelButt=Button("cancel"); buttBox.PackStart(cancelButt); cancelButt.Clicked+=fun(_) { win.Destroy(); } def okButt=Button("ok"); buttBox.PackStart(okButt); okButt.Clicked+=fun(_) { Run(); win.Destroy(); } win.ShowAll(); if (sMode==0) mode1VBox.HideAll() else mode0VBox.HideAll(); win.ReshowWithInitialSize(); } //------------------------------------------------------------------------------------------------------------- private aboutButtHandler(_o:object,_e:EventArgs):void{ def dial=MessageDialog(null,DialogFlags.Modal,MessageType.Info,ButtonsType.Ok,"worms plugin 0.3:0.3 by caminoix, 10.07.2006\n\nfor more information on the algorithm please see\nhttp://terraineer.sourceforge.net/plugins/worms.php"); _=dial.Run(); dial.Destroy(); } }