Monday 27 June 2011

Baan Tic-Tac-Toe Game


Need a break while working......Try this.

A Tic-Tac-Toe game developed in baan. It has basically two mode:-
i) Two player mode(Game between two players on same bshell and pid, by sharing the control).
ii) Lan mode(Game between two players on different bshell).

"For Lan Play just create a directory as tictac in $BSE/tmp"


This game is currently under development, but it is in playable condition.


|******************************************************************************
|* Tic Tac Toe game
|* Shashank. S. Shrivastava
|* 23-06-11 [09:07]
|******************************************************************************
|* Script Type: 3gl
|******************************************************************************
long main.win, menu.win, grap.win, list.win, ctrl.win, fp
long mode, ply1.win, ply2.win, tick1.win, tick2.win
long arr.X.O(16), cpu.x, cpu.y
string filename(100)
domain tcbool player1, lan.started, skip.lines, my.lan.turn
string string.p1(10), string.p2(10), box.filled(100)
string ply1.name(12), ply2.name(30)
string opponent1(30), opponent2(30)
string win.array(4,8)
domain tcbool blocked

#define COMMAND.ABORT 10
#define COMMAND.EXIT 11
#define COMMAND.FIRST 20
#define COMMAND.LAST 21
#define COMMAND.PREV 22
#define COMMAND.NEXT 23
#define GAME.START 24
#define ABOUT.GAME 25
#define GAME.HELP 26
#define TWO.PLAYER 27
#define CPU.VS.PLAYER 28
#define LAN.PLAY 29
#define LAN.PLAY.INIT 30
#define LAN.PLAY.JOIN 31
#define GAME.DIM 300
#define GAME.MAX.DIM 450
#pragma used dll ottdllbw
#pragma used dll ottdllinputstr
function main()
{
win.array(1,1) = "123"
win.array(1,2) = "456"
win.array(1,3) = "789"
win.array(1,4) = "147"
win.array(1,5) = "258"
win.array(1,6) = "369"
win.array(1,7) = "159"
win.array(1,8) = "357"

main.win = create.object( DsCmwindow, 0,
DsNtitle, "TIC-TAC-TAO",
DsNprocessgroup, get.pgrp(pid),
DsNminWidth, GAME.MAX.DIM,
DsNmaxWidth, GAME.MAX.DIM,
DsNminHeight, GAME.DIM+2,
DsNmaxHeight, GAME.DIM+2)
menu.win = create.pulldown.menu(main.win)
change.object( main.win, DsNbarMenu, menu.win )
create.game.control.window(main.win)
create.game.window(main.win)
update.object(grap.win)
update.object(main.win)
capture.event()
}
function create.game.control.window(long mwin)
{
ctrl.win = create.object( DsCgwindow, mwin,
DsNwidth, GAME.MAX.DIM-GAME.DIM-10,
DsNheight, GAME.DIM/4,
DsNx, GAME.DIM+5,
DsNy, 0,
DsNborderWidth, 2)
ply1.win = create.sub.object(ctrl.win, DsCgpText ,
DsNx, (GAME.MAX.DIM-GAME.DIM-10)/3,
DsNy, (GAME.DIM/4)/3,
DsNwidth, 80,
DsNgcForeground, 44800)
ply2.win = create.sub.object(ctrl.win, DsCgpText ,
DsNx, (GAME.MAX.DIM-GAME.DIM-10)/3,
DsNy, (GAME.DIM/4)*2/3,
DsNwidth, 80,
DsNgcForeground, RGB.BLACK)
update.object(ctrl.win)
}
function create.current.ply.mark(long mwin, double y, string name1(20), string name2(20) )
{
if mode = 1 or mode = 2 then
tt.user(name1, name1)
tt.user(name2, name2)
endif
tick1.win = create.sub.object (mwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, (GAME.MAX.DIM-GAME.DIM-10)/9,
DsNxn, (GAME.MAX.DIM-GAME.DIM-10)/8,
DsNyo, (GAME.DIM/4)/y-5,
DsNyn, (GAME.DIM/4)/y+1,
DsNgcForeground, 44800)
tick2.win = create.sub.object (mwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, (GAME.MAX.DIM-GAME.DIM-10)/8,
DsNxn, (GAME.MAX.DIM-GAME.DIM-10)/6,
DsNyo, (GAME.DIM/4)/y+1,
DsNyn, (GAME.DIM/4)/y-10,
DsNgcForeground, 44800)
change.sub.object(ctrl.win, ply1.win ,
DsNstring, name1,
DsNgcForeground, ((y=3.0)?44800 : RGB.BLACK))
change.sub.object(ctrl.win, ply2.win ,
DsNstring, name2,
DsNgcForeground, ((y=1.5)?44800 : RGB.BLACK))
}
function long create.pulldown.menu(long mwin)
{
long barmenu, size
string menudata(1) based
alloc.mem(menudata, 3000)
size = 1
store.long(1, menudata(size)) | version is 1
size = size + 4
store.long(20, menudata(size)) | menu contains 20 entries
size = size + 4
| create the File submenu
write.menu.entry(menudata, size, 1, 0, "&File", 0)
write.menu.entry(menudata, size, 2, COMMAND.EXIT, "E&xit Alt+F4", 0)

write.menu.entry(menudata, size, 1, 0, "&Start Game", 0)
write.menu.entry(menudata, size, 2, TWO.PLAYER, "&Two Player Game", 0)
write.menu.entry(menudata, size, 2, CPU.VS.PLAYER, "&Player vs CPU", 0)
write.menu.entry(menudata, size, 2, LAN.PLAY.INIT, "&Initiate LAN Play", 0)
write.menu.entry(menudata, size, 2, LAN.PLAY.JOIN, "&Join LAN Play", 0)

| create the View submenu
write.menu.entry(menudata, size, 1, 0, "&Help", 0)
write.menu.entry(menudata, size, 2, GAME.HELP, "HELP", 0)
write.menu.entry(menudata, size, 2, -1, "-", 0) | separator
write.menu.entry(menudata, size, 2, ABOUT.GAME, "About Game", 0)
barmenu = create.object(DsCbarMenu, mwin,
DsNmenuData, menudata, size-1,
DsNsetState, DSRAISE)
return(barmenu)
}
function write.menu.entry(ref string menudata(), ref long size,
long level, long id, const string name(), long flags)
{
store.long(level, menudata(size))
size = size + 4
store.long(id, menudata(size))
size = size + 4
menudata(size) = name
size = size + len(name)
store.byte(0, menudata(size)) | terminate string with 0 char.
size = size + 1
store.long(flags, menudata(size))
size = size + 4
}
function create.game.window(ref long mwin)
{
long x.line, y.line, i
grap.win = create.object( DsCgwindow, mwin,
DsNwidth, GAME.DIM,
DsNheight, GAME.DIM,
DsNgridHeight, 10,
DsNgridWidth, 10,
DsNgridColor, 6054755,
DsNeventMask, EVTALLEVENTMASK)
for i = 1 to 2
x.line = create.sub.object (grap.win, DsCgpLine,
DsNgcLineWidth, 2,
DsNxo, (GAME.DIM/3)*i,
DsNxn, (GAME.DIM/3)*i,
DsNyo, 0,
DsNyn, GAME.DIM)
y.line = create.sub.object (grap.win, DsCgpLine,
DsNgcLineWidth, 2,
DsNxo, 0,
DsNxn, GAME.DIM,
DsNyo, (GAME.DIM/3)*i,
DsNyn, (GAME.DIM/3)*i)
endfor

}
function create.O(ref long gwin, long x, long y)
{
arr.X.O(1) = arr.X.O(1) + 1
arr.X.O(arr.X.O(1)) = create.sub.object (gwin, DsCgpArc,
DsNangle, 0,
DsNgcLineWidth, 3,
DsNheight, 70,
DsNwidth, 70,
DsNx, x-36,
DsNy, y-36,
DsNrotation, 360,
DsNgcForeground, 7433637)
}
function create.X(ref long gwin, long x, long y)
{
arr.X.O(1) = arr.X.O(1) + 1
arr.X.O(arr.X.O(1)) = create.sub.object (gwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, x-35,
DsNxn, x+35,
DsNyo, y-35,
DsNyn, y+35,
DsNgcForeground, 255)
arr.X.O(1) = arr.X.O(1) + 1
arr.X.O(arr.X.O(1)) = create.sub.object (gwin, DsCgpLine,
DsNgcLineWidth, 3,
DsNxo, x-35,
DsNxn, x+35,
DsNyo, y+35,
DsNyn, y-35,
DsNgcForeground, 255)
}
function capture.event()
{
long event(EVTMAXSIZE)
long timer_id
string.p1 = ""
string.p2 = ""
player1 = TRUE
box.filled = ""
mode = -1
while TRUE
if pending.events() > 0 then
next.event(event)
on case evt.type(event)
case EVTBUTTONRELEASE:
if my.lan.turn or mode = 0 or mode = 3 then
on case evt.button.button( event )
case EVTBUTTON1:
game.play(get.x.value(evt.button.x( event )),
get.y.value(evt.button.y( event )))
if mode = 3 then
player1 = FALSE
player.vs.computer()
game.play(cpu.x, cpu.y)
player1 = TRUE
endif
break
endcase
endif
| if evt.button.return(event) = ABORT.BUTTON then
| end()
| endif
break
case EVTKEYPRESS:
on case evt.keypress.key(event)
case KEY_ESC:
| message("Thank You!!")
end()
break
case COMMAND.ABORT:
| message("Thank You!!!!")
end()
break
case 55:
game.play(50,50)
break
case 56:
game.play(150,50)
break
case 57:
game.play(250,50)
break
case 52:
game.play(50,150)
break
case 53:
game.play(150,150)
break
case 54:
game.play(250,150)
break
case 49:
game.play(50,250)
break
case 50:
game.play(150,250)
break
case 51:
game.play(250,250)
break
endcase
break
case EVTBUTTONSELECT:
if ( evt.button.return(event) = COMMAND.ABORT ) then
return
endif
break
case EVTMENUSELECT:
on case evt.menu.return(event)
case TWO.PLAYER:
mode = 0
box.filled = ""
string.p1 = ""
string.p2 = ""
player1 = TRUE
refresh.game.window()
break
case CPU.VS.PLAYER:
mode = 3
box.filled = ""
string.p1 = ""
string.p2 = ""
player1 = TRUE
refresh.game.window()
break
case LAN.PLAY.INIT:
mode = 1
skip.lines = 0
lan.started = FALSE
refresh.game.window()
filename = strip$(bse.tmp.dir$())&"/tictac/"&dte$()&"."&logname$
fp = seq.open(filename, "w+")
seq.puts("1", fp)
seq.close(fp)
invite.a.player()
break
case LAN.PLAY.JOIN:
mode = 2
skip.lines = 0
refresh.game.window()
search.game()
break
case GAME.HELP:
message("HE HE TIC-TAC-TAO KHELNA NAHI AATA\n Ha hA He hE....\nClick ok for Googglliinngg")
app_start( "iexplore.exe http://en.wikipedia.org/wiki/Tic-tac-toe", "", "", "", "" )
break
case ABOUT.GAME:
message("MADE BY SHASHNAK S S")
break
case COMMAND.EXIT:
| message("Thank You!!")
end()

endcase
endcase
if mode = 1 or mode = 2 then
read.lan.file(filename)
endif
else
if mode = 1 or mode = 2 then
read.lan.file(filename)
endif
endif
endwhile
}
function long get.y.value(long y)
{
long temp.val
temp.val = (y/100)
on case temp.val
case 0:
y = (50)
break
case 1:
y = (150)
break
case 2:
y = (250)
endcase
return(y)
}
function long get.x.value(long x)
{
long temp.val
temp.val = (x/100)
on case temp.val
case 0:
x = (50)
break
case 1:
x = (150)
break
case 2:
x = (250)
endcase
return(x)
}
function get.index(long x, long y)
{
long index
on case str$(x)&str$(y)
case "5050":
index = 1
break
case "15050":
index = 2
break
case "25050":
index = 3
break
case "50150":
index = 4
break
case "150150":
index = 5
break
case "250150":
index = 6
break
case "50250":
index = 7
break
case "150250":
index = 8
break
case "250250":
index = 9
break
endcase
if player1 then
string.p1 = string.p1&str$(index)
else
string.p2 = string.p2&str$(index)
endif
}
function domain tcbool check.win(string text(10))
{
if pos(text, "1") > 0 and pos(text, "2") > 0 and pos(text, "3") > 0 then
return(TRUE)
endif
if pos(text, "4") > 0 and pos(text, "5") > 0 and pos(text, "6") > 0 then
return(TRUE)
endif
if pos(text, "7") > 0 and pos(text, "8") > 0 and pos(text, "9") > 0 then
return(TRUE)
endif
if pos(text, "1") > 0 and pos(text, "4") > 0 and pos(text, "7") > 0 then
return(TRUE)
endif
if pos(text, "2") > 0 and pos(text, "5") > 0 and pos(text, "8") > 0 then
return(TRUE)
endif
if pos(text, "3") > 0 and pos(text, "6") > 0 and pos(text, "9") > 0 then
return(TRUE)
endif
if pos(text, "1") > 0 and pos(text, "5") > 0 and pos(text, "9") > 0 then
return(TRUE)
endif
if pos(text, "3") > 0 and pos(text, "5") > 0 and pos(text, "7") > 0 then
return(TRUE)
endif
return(FALSE)
}
function game.play(long x, long y)
{
long file.id

if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if pos(box.filled, ","&str$(x)&str$(y)&",") = 0 then
get.index(x, y)
if mode = 0 then
if player1 then
create.X(grap.win, x,y)
else
create.O(grap.win, x,y)
endif
endif
if mode = 3 then
if player1 then
create.X(grap.win, x,y)
else
create.O(grap.win, x,y)
endif
endif
if mode = 1 then
create.X(grap.win, x,y)
endif
if mode = 2 then
create.O(grap.win, x,y)
endif
update.object(grap.win)
box.filled = box.filled&","&str$(x)&str$(y)&","
if mode = 1 or mode = 2 then
file.id = seq.open(filename, "a+")
seq.puts(str$(x)&"."&str$(y), file.id)
seq.close(file.id)
endif
if player1 then
if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
endif
player1 = FALSE
else
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
endif

player1 = TRUE
endif
update.game.status()
else
Message("Not allowed")
endif
endif
endif
}
function search.game()
{
long dir.id, file.id, a
string game.filename(200), value(10)
dir.id = dir.open(strip$(bse.tmp.dir$())&"/tictac/")
if dir.id <= 0 then message("Unable to find tic-tac-tao network") endif repeat game.filename = dir.entry( dir.id, TFILE, a, a, a ) if not isspace(game.filename) then file.id = seq.open(strip$(bse.tmp.dir$())&"/tictac/"&game.filename, "r") if file.id < 1 then else seq.gets(value, 1024, file.id) if strip$(value) = "1" then if pos(game.filename, ".") > 0 then
opponent1 = logname$
opponent2 = game.filename(pos(game.filename, ".")+1)
if ask.enum("tcgenquest", tcyesno.yes, "Request to play with "&opponent2) = tcyesno.yes then
seq.close(file.id)
file.id = seq.open(strip$(bse.tmp.dir$())&"/tictac/"&game.filename, "w+")
seq.puts("2", file.id)
seq.puts(logname$, file.id)
seq.close(file.id)
filename = strip$(bse.tmp.dir$())&"/tictac/"&game.filename
skip.lines = 1
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
endif
create.current.ply.mark(ctrl.win, 1.5, opponent1, opponent2)
update.object(ctrl.win)
endif
endif
endif
endif
seq.close(file.id)
value = "0"
endif
until (isspace(game.filename))
}
function read.lan.file(string game.filename(100))
{
long lan.file.id, i
string value(20)

lan.file.id = seq.open(game.filename, "r")
if lan.file.id < 1 then message("Disconnected from partner") mode = -1 refresh.game.window() else seq.gets(value, 1024, lan.file.id) if mode = 1 then if strip$(value) = "2" and skip.lines < 2 then seq.gets(value, 1024, lan.file.id) if ask.enum("tcgenquest", tcyesno.yes, "Approve request of "&value&" to play.") = tcyesno.yes then opponent1 = logname$ opponent2 = value | destroy.object(ctrl.win) destroy.sub.object(ctrl.win, tick1.win) destroy.sub.object(ctrl.win, tick2.win) create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2) update.object(ctrl.win) lan.started = TRUE skip.lines = 2 my.lan.turn = TRUE endif player1 = TRUE else if skip.lines >= 2 then
for i = 1 to skip.lines
seq.gets(value, 1024, lan.file.id)
endfor
if seq.gets(value, 1024, lan.file.id) = 0 then
my.lan.turn = TRUE
skip.lines = skip.lines + 2
if pos(value,".") <> 0 then
player1 = FALSE
get.index(lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
create.O(grap.win, lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
box.filled = box.filled&","&str$(lval(value(1;pos(value,".")-1)))&str$(lval(value(pos(value,".")+1)))&","
update.object(grap.win)
if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
endif
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
endif
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
if player1 then
create.current.ply.mark(ctrl.win, (mode = 1)?3.0:1.5, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, (mode = 1)?1.5:3.0, opponent1, opponent2)
endif
endif
update.object(ctrl.win)
endif
player1 = TRUE
endif
endif
endif
else
for i = 1 to skip.lines
seq.gets(value, 1024, lan.file.id)
endfor
if seq.gets(value, 1024, lan.file.id) = 0 then
my.lan.turn = TRUE
skip.lines = skip.lines + 2
if pos(value,".") <> 0 then
player1 = TRUE
get.index(lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
create.X(grap.win, lval(value(1;pos(value,".")-1)),lval(value(pos(value,".")+1)))
box.filled = box.filled&","&str$(lval(value(1;pos(value,".")-1)))&str$(lval(value(pos(value,".")+1)))&","
update.object(grap.win)
player1 = FALSE
if check.win(string.p1) then
message(opponent1&" Won the game.\n CONGRATULATIONS")
mode = -1
else
if len(strip$(string.p1)) = 5 then
message("Its a ...TIE...")
mode = -1
endif
endif
if check.win(string.p2) then
message(opponent2&" Won the game.\n CONGRATULATIONS")
mode = -1
endif
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
if player1 then
create.current.ply.mark(ctrl.win, (mode = 1)?3.0:1.5, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, (mode = 1)?1.5:3.0, opponent1, opponent2)
endif
update.object(ctrl.win)
endif
endif
endif
endif
endif
seq.close(lan.file.id)
value = "0"
}
function refresh.game.window()
{
long i
if mode = 1 then
shell("mkdir "&strip$(bse.tmp.dir$())&"/tictac/", 0)
shell("rm "&strip$(bse.tmp.dir$())&"/tictac/*."&logname$, 0)
endif
if tick1.win <> 0 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
endif
box.filled = ""
string.p1 = ""
string.p2 = ""
opponent1 = ""
opponent2 = ""
player1 = TRUE
my.lan.turn = FALSE
tick1.win = 0
tick2.win = 0
if mode = 0 then
opponent1 = "Player 1"
opponent2 = "Player 2"
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
endif
if mode = 3 then
tt.user(logname$, opponent1)
opponent2 = "CPU"
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
endif
if mode = 1 or mode = 2 then
opponent1 = logname$
opponent2 = ""
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
endif
for i = 2 to arr.X.O(1)
destroy.sub.object(grap.win, arr.X.O(i))
endfor
set.mem(arr.X.O, 0)
arr.X.O(1) = 1
update.object(grap.win)
update.object(ctrl.win)
}
function update.game.status()
{
if mode = 0 or mode = 1 or mode = 2 or mode = 3 then
destroy.sub.object(ctrl.win, tick1.win)
destroy.sub.object(ctrl.win, tick2.win)
if mode = 1 or mode = 2 then
my.lan.turn = FALSE
if player1 then
create.current.ply.mark(ctrl.win, (mode = 1)?3.0:1.5, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, (mode = 1)?1.5:3.0, opponent1, opponent2)
endif
else
if player1 then
create.current.ply.mark(ctrl.win, 3.0, opponent1, opponent2)
else
create.current.ply.mark(ctrl.win, 1.5, opponent1, opponent2)
endif
endif
update.object(ctrl.win)
endif
}
function player.vs.computer()
{
blocked = FALSE
on case len(string.p1)
case 1:
if pos(string.p1, "1") > 0 or pos(string.p1, "3") > 0 or pos(string.p1, "7") > 0 or pos(string.p1, "9") > 0 then
read.cpu.x.y("5")
endif
if pos(string.p1, "5") > 0 then
read.cpu.x.y("1")
endif
if pos(string.p1, "2") > 0 or pos(string.p1, "4") > 0 or pos(string.p1, "6") > 0 or pos(string.p1, "8") > 0 then
read.cpu.x.y("5")
endif
break
case 2:
check.for.2(string.p1, string.p2)
if not blocked then
if string.p1(1;1) = "1" or string.p1(1;1) = "3" or string.p1(1;1) = "9" or string.p1(1;1) = "7" then
if string.p1(2;1) = "9" or string.p1(2;1) = "7" or string.p1(2;1) = "3" or string.p1(2;1) = "1" then
read.cpu.x.y("2")
blocked = TRUE
endif
if string.p1(2;1) = "6" or string.p1(2;1) = "4" then
read.cpu.x.y("2")
blocked = TRUE
endif
if string.p1(2;1) = "8" or string.p1(2;1) = "2" then
read.cpu.x.y("6")
blocked = TRUE
endif
else
if string.p1(1;1) = "4" or string.p1(1;1) = "6" then
if string.p1(2;1) = "9" or string.p1(2;1) = "7" then
read.cpu.x.y("8")
blocked = TRUE
endif
if string.p1(2;1) = "3" or string.p1(2;1) = "1" then
read.cpu.x.y("2")
blocked = TRUE
endif
endif
if string.p1(1;1) = "2" or string.p1(1;1) = "8" then
if string.p1(2;1) = "9" or string.p1(2;1) = "3" then
read.cpu.x.y("6")
blocked = TRUE
endif
if string.p1(2;1) = "7" or string.p1(2;1) = "1" then
read.cpu.x.y("4")
blocked = TRUE
endif
endif
if not blocked then
fill.for.2()
endif
if not blocked then
check.for.2(string.p2, string.p1)
endif
endif
endif
break
case 3:
check.for.2(string.p1, string.p2)
if not blocked then
check.for.2(string.p2, string.p1)
endif
if not blocked then
fill.for.2()
endif
break
case 4:
check.for.2(string.p1, string.p2)
if not blocked then
check.for.2(string.p2, string.p1)
endif
if not blocked then
fill.for.2()
endif
break
endcase
}
function check.for.2(string local.string1(10), string local.string2(10))
{
long local.i
string temp.win.array(4)
for local.i = 1 to 8
temp.win.array = win.array(1,local.i)
if find.block.pos.for.cpu(local.string1,
local.string2,
temp.win.array(1;1),
temp.win.array(2;1),
temp.win.array(3;1)) then
return
endif
if find.block.pos.for.cpu(local.string1,
local.string2,
temp.win.array(2;1),
temp.win.array(3;1),
temp.win.array(1;1)) then
return
endif
if find.block.pos.for.cpu(local.string1,
local.string2,
temp.win.array(1;1),
temp.win.array(3;1),
temp.win.array(2;1)) then
return
endif
endfor

if len(local.string1) < len(local.string2) then for local.i = 1 to 8 temp.win.array = win.array(1,local.i) if find.win.pos.for.cpu(local.string1, local.string2, temp.win.array(1;1), temp.win.array(2;1), temp.win.array(3;1)) then return endif if find.win.pos.for.cpu(local.string1, local.string2, temp.win.array(2;1), temp.win.array(3;1), temp.win.array(1;1)) then return endif if find.win.pos.for.cpu(local.string1, local.string2, temp.win.array(1;1), temp.win.array(3;1), temp.win.array(2;1)) then return endif endfor endif } function long read.index(long x, long y) { long index on case str$(x)&str$(y) case "5050": index = 1 break case "15050": index = 2 break case "25050": index = 3 break case "50150": index = 4 break case "150150": index = 5 break case "250150": index = 6 break case "50250": index = 7 break case "150250": index = 8 break case "250250": index = 9 break endcase return(index) } function fill.for.2() { if pos(string.p1, "2") > 0 and pos(string.p1, "4") > 0 then
read.cpu.x.y("1")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif if pos(string.p1, "4") > 0 and pos(string.p1, "8") > 0 then
read.cpu.x.y("7")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif if pos(string.p1, "6") > 0 and pos(string.p1, "8") > 0 then
read.cpu.x.y("9")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif if pos(string.p1, "2") > 0 and pos(string.p1, "6") > 0 then
read.cpu.x.y("3")
if pos(string.p2, str$(read.index(cpu.x, cpu.y))) < 1 then blocked = TRUE return endif endif } function invite.a.player() { string login.id(16), command.string(100) if ask.enum("tcgenquest", tcyesno.yes, "Invite Specific person to play") = tcyesno.yes then input.string("Invite Person by Baan Login ID", "Baan Login ID", 16, 16, login.id) command.string = "bshcmd6.1 -u1 -w1 -M ""Hello"" `ps -eaf | grep bshell | grep "&login.id &" | awk '{ print $2 }'`" shell(command.string , 64) endif } function domain tcbool find.block.pos.for.cpu(string local.string1(10), string local.string2(10), string a(1), string b(1), string c(1)) { if pos(local.string1, a) > 0 and pos(local.string1, b) > 0 then
read.cpu.x.y(c)
if pos(local.string2, c) < 1 then blocked = TRUE return(TRUE) endif endif return(FALSE) } function domain tcbool find.win.pos.for.cpu(string local.string1(10), string local.string2(10), string a(1), string b(1), string c(1)) { if pos(local.string2, a) < 1 and pos(local.string2, b) < 1 and pos(local.string2, c) < 1 then if pos(local.string1, a) > 0 or pos(local.string1, b) > 0 or pos(local.string1, c) > 0 then
if pos(local.string1, a) < 1 then read.cpu.x.y(a) blocked = TRUE return(TRUE) endif if pos(local.string1, b) < 1 then read.cpu.x.y(b) blocked = TRUE return(TRUE) endif if pos(local.string1, c) < 1 then read.cpu.x.y(c) blocked = TRUE return(TRUE) endif endif endif return(FALSE) } function read.cpu.x.y(string c(1)) { on case lval(c) case 1: cpu.x = 50 cpu.y = 50 break case 2: cpu.x = 150 cpu.y = 50 break case 3: cpu.x = 250 cpu.y = 50 break case 4: cpu.x = 50 cpu.y = 150 break case 5: cpu.x = 150 cpu.y = 150 break case 6: cpu.x = 250 cpu.y = 150 break case 7: cpu.x = 50 cpu.y = 250 break case 8: cpu.x = 150 cpu.y = 250 break case 9: cpu.x = 250 cpu.y = 250 break endcase }



:) Just copy and run as 3gl and enjoy!!!!!!!


Add Indicator to baan sessions(Coloring Baan Sessions)



Many times while working on complex environment like opening sessions on multiple companies, taking multiple login on same systems, etc results in confusion of the present window refers to login or company.

And for this we always wanted some indication on each baan session to let us know the server, company and the user.

How we can achieve it?

One answer to it is by marking each session by a small color window displaying the server, company and the user.

And here is the way to get it.

*) First on all it is needed to identify the processes which are alive or running. It can be done using the pstat(...) funtion. And to dynamically update the running processes it has to be looped at regular interval.

e.g.

while true
temp.proc.id = pstat( proc.id, progname, info )
        proc.id = temp.proc.id
endwhile

It will give us all the running processes one by one.



**) Secondly, to draw the indicator(Color object) for the processes the main window id related to that process is needed. It can be fetched by using function ps.mwin(info) for the specific process used in pstat(process, program name, information).
      Once the main window id is fetched, we need to inherit its properties to be able to draw additional object on it. To inherit use function inherit.object(process, window id). After this draw a small graphical object using create.object(....) and the text object of it using create.sub.object(...).
     Repeat it for all the processes and the required will be done.

e.g.
mwin = ps.mwin(info)
inherit.object(proc.id, mwin)

get.object  (mwin,  DsNwidth, width, 1024)
text.string = toupper$(hostname$())&"("&edit$(get.compnr(), "999")&")-"&logname$
obj.id(procid) = create.object(DsCgwindow,mwin,
DsNx, width-text.leng*8, DsNy, 0,
DsNheight, 10, DsNwidth, text.leng*8,
DsNbackground, color.id, DsNborderColor,color.id ) subobj.id(procid) = create.sub.object(obj.id(procid), DsCgpText , 
DsNx, 0,  DsNy, 9, 
DsNwidth, text.leng*8, 
DsNstring, text.string, 
DsNgcForeground, RGB.WHITE)

update.object(obj.id(procid))

***) When we do this it happens that the main and child windows are not destroyed when we exit the session so for that we need to kill / destroy the main window. It is done using destroy.object(...).

e.g.

if mwin <> 0 then
destroy.object(mwin)
endif
if cwin <> 0 then
destroy.object(cwin)
endif


:) Just do these and enjoy!!!!!!!

Two tables combined display or maintain session.



Can we build a maintain or display session which works on 2 main tables?

Yes, we can and the answer is out here.

Every maintain or display session has four sets of queries to fetch the records from the database.
1) Query the first set.
2) Query the next set.
3) Query the previous set.
4) Query the last set.

These queries can be seen by pressing the key combination <Ctrl> <Shift> <8>.
Now how to modify it to make use of it to incorporate two or more tables.
All the above set of four queries have fixed sql ids linked to them (Like in case of dynamic Sql), we just need to assign the new query to them which make use of two or more tables.

The fixed Sql ids linked to above queries are:-
1) g.sql.first.id  for the first set.
2) g.sql.next.id  for the next set.
3) g.sql.prev.id  for the prev set.
4) g.sql.last.id  for the last set.
Just modify the queries like below:-

g.sql.first.id = sql.parse("select table1.*, table2.* from table1, table2 where <condition you like> order by <your choice>")

g.sql.first.id = sql.parse("select table1.*, table2.* from table1, table2 where <condition you like> order by <your choice> desc")

In case of display session it will work perfectly without any modification.
But in case of maintain session you will have to do some extra coding for assigning values and writing data of extra table to data base.(By using db.update, db.delete and db.insert without commit in main table io sections)

:) Just Modify these and enjoy!!!!!!!

Changing the order in which standard baan displays the records.


At times in baan we get struck up in showing records in a display session or maintain in a special way of sorting.(Simplest case is to display records in descending order).


The answer to this is out here.
Every maintain or display session has four sets of queries to fetch the records from the database.
1) Query the first set.
2) Query the next set.
3) Query the previous set.
4) Query the last set.

These queries can be seen by pressing the key combination <Ctrl> <Shift> <8>.
Now how to modify it to make use of it.
All the above set of four queries have fixed sql ids linked to them (Like in case of dynamic Sql), we just need to assign   the new query to them.

The fixed Sql ids are:-
1) g.sql.first.id  for the first set.
2) g.sql.next.id  for the next set.
3) g.sql.prev.id  for the prev set.
4) g.sql.last.id  for the last set.

:) Just Modify these and enjoy!!!!!!!