<% 'move.asp 'The purpose of this file is to set the player's coordinates and the ResultID in the User's table. 'This file receives the variables dx and dy from the .asp files named the appropriate direction. user = session("user") msg = "" & request.cookies("msg") 'construct message with apostrophes msg = replace(msg, "'", "''") 'get stats getstats = conn.execute("SELECT Energy, Character, Trade, HomeTileID, X, Y, Pass, Ally FROM Users WHERE Username ='"&user&"'") energy = getstats(0) charval = getstats(1)*1000 trade = getstats(2) homeID = getstats(3) px = getstats(4) py = getstats(5) passing = getstats(6) allying = getstats(7) 'variables for passing dim ax(3), ay(3) 'moving ends passing-ready state, allying-ready state if passing then conn.execute("UPDATE Users SET Pass=no WHERE Username='"&user&"'") if allying then conn.execute("UPDATE Users SET Ally=no WHERE Username='"&user&"'") 'check if user tried to move into the void if px+dx < -distToEdge or px+dx > distToEdge or py+dy < -distToEdge or py+dy > distToEdge then 'we want to set the ResultID to 2 conn.execute("UPDATE Users SET ResultID=2 WHERE Username='" & user & "'") conn.close response.redirect("overview.asp") end if 'we need to get an ADO recordset from the server's database for the new tile. tileID = (py+dy+distToEdge) * worldwidth + (px+dx+distToEdge) + 1 set tileRecordset = conn.execute("SELECT State, Owner, Occupant FROM tg WHERE ID="&tileID) tilestate = tileRecordSet(0) owner = "" & tileRecordSet(1) occupant = "" & tileRecordSet(2) purestate = tilestate - int(tilestate/1000)*1000 'we also need a recordset for the old tile. tileIDold = (py+distToEdge) * worldwidth + (px+distToEdge) + 1 set tileRecordSet = conn.execute("SELECT State, Owner FROM tg WHERE ID="&tileIDold) tilestateold = tileRecordSet(0) pureold = tilestateold if tilestateold >= 1000 then pureold = tilestateold-charval ownerold = tileRecordSet(1) 'can't move sideways onto guarded tile if (tilestate = 20 and dy <> 0 or tilestate = 21 and dx <> 0) and owner<>user then conn.execute("UPDATE Users SET ResultID=61 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'can't move sideways off of guarded tile if (pureold = 20 and dy <> 0 or pureold = 21 and dx <> 0) and ownerold<>user then conn.execute("UPDATE Users SET ResultID=62 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'road movement road = false if ((1<=tilestate and tilestate<=21) or (500<=tilestate and tilestate<=503)) and ((1<=pureold and pureold<=21) or (500<=pureold and pureold<=503)) then road = true if dx<>0 and (tilestate=21 or pureold=21) or dy<>0 and (tilestate=20 or pureold=20) then road = false 'town movement if (500 <= tilestate) and (tilestate <= 503) and (not(owner = user)) then 'send message to town, highest precedence if msg <> "" then response.cookies("msg")="" set msgcnt = conn.execute("SELECT COUNT(*) FROM z_msg_"&owner) set msgmax = conn.execute("SELECT MAX(ID) FROM z_msg_"&owner) msgmaxint = msgmax(0) if not isnumeric(msgmaxint) then msgmaxint=0 if msgcnt(0) >= 10 then conn.execute("UPDATE Users SET ResultID=77, ResultText='"&owner&"' WHERE Username='"&user&"'") elseif energy < 4 then conn.execute("UPDATE Users SET ResultID=76, ResultText='"&owner&"' WHERE Username='"&user&"'") else pos = Instr(1, msg, "<") if pos <> 0 then conn.execute("UPDATE Users SET ResultID=82 WHERE Username='"&user&"'") else SQL = "INSERT INTO z_msg_"&owner&"(ID, MSG, Sender) VALUES ("&(msgmaxint+1)&", " SQL = SQL + "'" & msg & "'" & ", " & "'" & user & "'" & ")" conn.execute("UPDATE Users SET Energy="&(energy-4)&", ResultID=78, ResultText='"&owner&"' WHERE Username='"&user&"'") conn.execute("UPDATE Users SET NewMsg=yes WHERE Username='"&owner&"'") conn.execute("INSERT INTO Msgs(Sender, Recipient, Msg) VALUES ('"&user&"', '"&owner&"', '"&msg&"')") conn.execute(SQL) end if end if 'ally with town elseif allying then set allyownerRS = conn.execute("SELECT Username FROM Users WHERE HomeTileID="&tileID) allyowner = allyownerRS(0) 'already have some ally status? set allyRS = conn.execute("SELECT State FROM z_ally_"&user&" WHERE Username='"&allyowner&"'") if not (allyRS.eof and allyRS.bof) then conn.execute("UPDATE Users SET ResultID=97, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'have you traded with him? set allyRS2 = conn.execute("SELECT Amount FROM z_trade_"&user&" WHERE ID="&tileID) if allyRS2.bof and allyRS.eof then conn.execute("UPDATE Users SET ResultID=98, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if if allyRS2(0) <> 3 then conn.execute("UPDATE Users SET ResultID=98, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'enough resources? if energy < 50 then conn.execute("UPDATE Users SET ResultID=99, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'OK, set up alliance. conn.execute("INSERT INTO z_ally_"&user&"(Username, State) VALUES ('"&allyowner&"', 72)") conn.execute("INSERT INTO z_ally_"&allyowner&"(Username, State) VALUES ('"&user&"', 172)") conn.execute("UPDATE Users SET Energy="&(energy-50)&", ResultID=94, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.execute("UPDATE Users SET NewAlly=yes WHERE Username='"&allyowner&"'") 'pass town elseif passing then 'roads don't connect? (guard) if dy <> 0 and (pureold = 20) or dx <> 0 and (pureold = 21) then conn.execute("UPDATE Users SET ResultID=90 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if cx = px+dx cy = py+dy if dx=-1 then ax(0)=cx:ay(0)=cy+1:ax(1)=cx-1:ay(1)=cy:ax(2)=cx:ay(2)=cy-1:dirs="VHV" if dy=-1 then ax(0)=cx-1:ay(0)=cy:ax(1)=cx:ay(1)=cy-1:ax(2)=cx+1:ay(2)=cy:dirs="HVH" if dx= 1 then ax(0)=cx:ay(0)=cy-1:ax(1)=cx+1:ay(1)=cy:ax(2)=cx:ay(2)=cy+1:dirs="VHV" if dy= 1 then ax(0)=cx+1:ay(0)=cy:ax(1)=cx:ay(1)=cy+1:ax(2)=cx-1:ay(2)=cy:dirs="HVH" i = 0 found = false do while i < 3 if -distToEdge <= ax(i) and ax(i) <= distToEdge and -distToEdge <= ay(i) and ay(i) <= distToEdge then XYToID ax(i), ay(i) cid = xy_id set passRS = conn.execute("SELECT State, Owner FROM tg WHERE ID="&xy_id) cstate = passRS(0) cowner = passRS(1) if i <> 1 and dirs="HVH" or i = 1 and dirs="VHV" then badguardstate = 21 else badguardstate = 20 if (1 <= cstate and cstate <= 15 or cstate = 20 or cstate = 21 or 500 <= cstate and cstate <= 503 and cowner = user) and cstate <> badguardstate then found = true foundx = ax(i) foundy = ay(i) i = 3 end if end if i = i + 1 loop 'other side not clear? if not found then conn.execute("UPDATE Users SET ResultID=91 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'enough resources? if energy < 2 then conn.execute("UPDATE Users SET ResultID=93 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'OK, take resources conn.execute("UPDATE Users SET Energy="&energy-2&" WHERE Username='"&user&"'") 'pass conn.execute("UPDATE Users SET X="&foundx&", Y="&foundy&" WHERE Username='"&user&"'") conn.execute("UPDATE tg SET State="&pureold&", Occupant='' WHERE ID="&tileIDold) if 500 <= cstate and cstate <= 503 then conn.execute("UPDATE tg SET State="&cstate&", Occupant='"&user&"' WHERE ID="&cid) else conn.execute("UPDATE tg SET State="&cstate+charval&", Occupant='"&user&"' WHERE ID="&cid) end if 'trade with town elseif trade then 'get owner of town set tradeownerRS = conn.execute("SELECT Username FROM Users WHERE HomeTileID="&tileID) tradeowner = tradeownerRS(0) set tradeRS = conn.execute("SELECT Amount FROM z_trade_"&user&" WHERE ID="&tileID) 'no previous relation to town if (tradeRS.eof and tradeRS.bof) then '2 for you... conn.execute("INSERT INTO z_trade_"&user&"(ID, Amount) VALUES ("&tileID&", 2)") 'and 1 for him! conn.execute("INSERT INTO z_trade_"&tradeowner&"(ID, Amount) VALUES ("&homeID&", 1)") 'set incomes set incomeRS = conn.execute("SELECT SUM(Amount) FROM z_trade_"&user) income = incomeRS(0) conn.execute("UPDATE Users SET Income="&income&", ResultID=32, ResultText='"&tradeowner&"' WHERE Username='"&user&"'") set incomeRS = conn.execute("SELECT SUM(Amount) FROM z_trade_"&tradeowner) income = incomeRS(0) conn.execute("UPDATE Users SET Income="&income&" WHERE Username='"&tradeowner&"'") 'town's owner has traded with you before elseif tradeRS(0) = 1 then 'give you 3 instead of 1 conn.execute("UPDATE z_trade_"&user&" SET Amount=3 WHERE ID="&tileID) 'give him 3 instead of 2 conn.execute("UPDATE z_trade_"&tradeowner&" SET Amount=3 WHERE ID="&homeID) 'set incomes set incomeRS = conn.execute("SELECT SUM(Amount) FROM z_trade_"&user) income = incomeRS(0) conn.execute("UPDATE Users SET Income="&income&", ResultID=32, ResultText='"&tradeowner&"' WHERE Username='"&user&"'") set incomeRS = conn.execute("SELECT SUM(Amount) FROM z_trade_"&tradeowner) income = incomeRS(0) conn.execute("UPDATE Users SET Income="&income&" WHERE Username='"&tradeowner&"'") 'already traded with this town else conn.execute("UPDATE Users SET ResultID=34, ResultText='"&tradeowner&"' WHERE Username='"&user&"'") end if 'walked into another's town else conn.execute("UPDATE Users SET ResultID=7, ResultText='"&owner&"' WHERE Username='"&user&"'") end if 'passable tile or your town elseif tilestate <= 503 then 'error if not enough energy if road and (energy < 1) then conn.execute("UPDATE Users SET ResultID=10 WHERE Username='"&user&"'") elseif (not road) and (energy < 3) then conn.execute("UPDATE Users SET ResultID=11 WHERE Username='"&user&"'") else 'success! Move the user's database position conn.execute("UPDATE Users SET X="&px+dx&", Y="&py+dy&" WHERE Username='" & user & "'") 'set energy energytax = 3 if road then energytax = 1 SQL = "UPDATE Users SET Energy="&energy-energytax&" WHERE Username='"&user&"'" conn.execute(SQL) 'change the tile states too 'change old if not a town tile if not((500 <= tilestateold) and (tilestateold <= 503)) then conn.execute("UPDATE tg SET State="&tilestateold-charval&" WHERE ID="&tileIDold) end if 'change new tile if not a town tile if not((500 <= tilestate) and (tilestate <= 503)) then conn.execute("UPDATE tg SET State="&tilestate+charval&" WHERE ID="&tileID) end if 'change occupant of tiles conn.execute("UPDATE tg SET Occupant='' WHERE ID="&tileIDold) conn.execute("UPDATE tg SET Occupant='"&user&"' WHERE ID="&tileID) 'let you know if you broke your trade route if (not road) and trade then conn.execute("UPDATE Users SET Trade=no, ResultID=31 WHERE Username='"&user&"'") end if 'non-passable tile elseif tilestate < 1000 then conn.execute("UPDATE Users SET ResultID=1 WHERE Username='"&user&"'") 'move into a player else 'ally with town if allying then allyowner = occupant set allyIDRS = conn.execute("SELECT HomeTileID FROM Users WHERE Username='"&allyowner&"'") allytargethomeID = allyIDRS(0) 'already have some ally status? set allyRS = conn.execute("SELECT State FROM z_ally_"&user&" WHERE Username='"&allyowner&"'") if not (allyRS.eof and allyRS.bof) then conn.execute("UPDATE Users SET ResultID=97, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'have you traded with him? set allyRS2 = conn.execute("SELECT Amount FROM z_trade_"&user&" WHERE ID="&allytargethomeID) if allyRS2.bof and allyRS.eof then conn.execute("UPDATE Users SET ResultID=98, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if if allyRS2(0) <> 3 then conn.execute("UPDATE Users SET ResultID=98, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'enough resources? if energy < 50 then conn.execute("UPDATE Users SET ResultID=99, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'OK, set up alliance. conn.execute("INSERT INTO z_ally_"&user&"(Username, State) VALUES ('"&allyowner&"', 72)") conn.execute("INSERT INTO z_ally_"&allyowner&"(Username, State) VALUES ('"&user&"', 172)") conn.execute("UPDATE Users SET Energy="&(energy-50)&", ResultID=94, ResultText='"&allyowner&"' WHERE Username='"&user&"'") conn.execute("UPDATE Users SET NewAlly=yes WHERE Username='"&allyowner&"'") 'passing elseif passing then 'other player not on road? if not (1 <= purestate and purestate <= 15 or purestate = 20 or purestate = 21) then conn.execute("UPDATE Users SET ResultID=92 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'roads don't connect? (guard) if dy <> 0 and (purestate = 20 or pureold = 20) or dx <> 0 and (purestate = 21 or pureold = 21) then conn.execute("UPDATE Users SET ResultID=90 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if cx = px+dx cy = py+dy if dx=-1 then ax(0)=cx:ay(0)=cy+1:ax(1)=cx-1:ay(1)=cy:ax(2)=cx:ay(2)=cy-1:dirs="VHV" if dy=-1 then ax(0)=cx-1:ay(0)=cy:ax(1)=cx:ay(1)=cy-1:ax(2)=cx+1:ay(2)=cy:dirs="HVH" if dx= 1 then ax(0)=cx:ay(0)=cy-1:ax(1)=cx+1:ay(1)=cy:ax(2)=cx:ay(2)=cy+1:dirs="VHV" if dy= 1 then ax(0)=cx+1:ay(0)=cy:ax(1)=cx:ay(1)=cy+1:ax(2)=cx-1:ay(2)=cy:dirs="HVH" i = 0 found = false do while i < 3 if -distToEdge <= ax(i) and ax(i) <= distToEdge and -distToEdge <= ay(i) and ay(i) <= distToEdge then XYToID ax(i), ay(i) cid = xy_id set passRS = conn.execute("SELECT State, Owner FROM tg WHERE ID="&xy_id) cstate = passRS(0) cowner = passRS(1) if i <> 1 and dirs="HVH" or i = 1 and dirs="VHV" then badguardstate = 21 else badguardstate = 20 if (1 <= cstate and cstate <= 15 or cstate = 20 or cstate = 21 or 500 <= cstate and cstate <= 503 and cowner = user) and cstate <> badguardstate and purestate <> badguardstate then found = true foundx = ax(i) foundy = ay(i) i = 3 end if end if i = i + 1 loop 'other side not clear? if not found then conn.execute("UPDATE Users SET ResultID=91 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'enough resources? if energy < 2 then conn.execute("UPDATE Users SET ResultID=93 WHERE Username='"&user&"'") conn.close response.redirect("overview.asp") end if 'OK, take resources conn.execute("UPDATE Users SET Energy="&energy-2&" WHERE Username='"&user&"'") 'pass conn.execute("UPDATE Users SET X="&foundx&", Y="&foundy&" WHERE Username='"&user&"'") conn.execute("UPDATE tg SET State="&pureold&", Occupant='' WHERE ID="&tileIDold) if 500 <= cstate and cstate <= 503 then conn.execute("UPDATE tg SET State="&cstate&", Occupant='"&user&"' WHERE ID="&cid) else conn.execute("UPDATE tg SET State="&cstate+charval&", Occupant='"&user&"' WHERE ID="&cid) end if 'messaging elseif msg <> "" then response.cookies("msg")="" set msgcnt = conn.execute("SELECT COUNT(*) FROM z_msg_"&occupant) set msgmax = conn.execute("SELECT MAX(ID) FROM z_msg_"&occupant) msgmaxint = msgmax(0) if not isnumeric(msgmaxint) then msgmaxint=0 if msgcnt(0) >= 10 then conn.execute("UPDATE Users SET ResultID=77, ResultText='"&occupant&"' WHERE Username='"&user&"'") elseif energy < 4 then conn.execute("UPDATE Users SET ResultID=76, ResultText='"&occupant&"' WHERE Username='"&user&"'") else pos = Instr(1, msg, "<") if pos <> 0 then conn.execute("UPDATE Users SET ResultID=82 WHERE Username='"&user&"'") else SQL = "INSERT INTO z_msg_"&occupant&"(ID, MSG, Sender) VALUES ("&(msgmaxint+1)&", " SQL = SQL + "'" & msg & "'" & ", " & "'" & user & "'" & ")" conn.execute("UPDATE Users SET Energy="&(energy-4)&", ResultID=78, ResultText='"&occupant&"' WHERE Username='"&user&"'") conn.execute("UPDATE Users SET NewMsg=yes WHERE Username='"&occupant&"'") conn.execute("INSERT INTO Msgs(Sender, Recipient, Msg) VALUES ('"&user&"', '"&occupant&"', '"&msg&"')") conn.execute(SQL) end if end if 'tell em who it is they moved in to else conn.execute("UPDATE Users SET ResultID=5, ResultText='"&occupant&"' WHERE Username='" & user & "'") end if end if %>