Skip to content

Instantly share code, notes, and snippets.

@Nucleareal
Created December 21, 2014 11:12
Show Gist options
  • Save Nucleareal/b3982aea4ca933402bb6 to your computer and use it in GitHub Desktop.
Save Nucleareal/b3982aea4ca933402bb6 to your computer and use it in GitHub Desktop.
幻想郷IntelMap
#include "mod_img.as"
#include "upaint.as"
#include "a2d.hsp"
#packopt name "pointCreator"
randomize
crs = 8
scx = 800
scy = 800
paintspcount = 0
screen 0, scx, scy : title "幻想郷Ingressシステム Loading..."
buffer 1, scx, scy
buffer 2, 12*32+12, 16
//CF
buffer 10, scx, scy
br = 0
bg = 0
bb = 0
font "メイリオ", 12, 1
sdim pointsData, 4096
sdim attacksData, 4096
sdim linksData, 4096
dim paintsData, 128
dim paintsPosData, 128, 2
//Load PointData
gosub *reloadPointData
//Load AttackData
gosub *reloadAttackData
//Load LinkData
gosub *reloadLinkData
onexit goto *savePoints
onclick gosub *addPoint
onkey gosub *reloadAll
cudir = dir_cur
chdir "./imgs"
gsel 1 : pos 0, 0
picload "ingress.jpg"
chdir cudir
enlightenedLink = 0
enlightenedCF = 0
resistanceLink = 0
resistanceCF = 0
gsel 0
title "幻想郷Ingressシステム v1.0"
repeat
gsel 0
redraw 0
gmode 0 : pos 0, 0
gcopy 1, 0, 0, scx, scy
gsel 10
color : boxf
//drawLink
repeat linkmax
cntr = posLink(cnt, 0)
gosub *setOwnerColor
cntr = cnt
gosub *drawLink
loop
// drawCF
repeat paintspcount
cntr = paintsData(cnt)
gosub *setOwnerColor
color br/4, bg/4, bb/4
floodfill paintsPosData(cnt, 0), paintsPosData(cnt, 1), 0
loop
// drawPoint
repeat pointmax
cntr = cnt
gosub *setOwnerColor
gosub *drawPoint
gosub *drawOwner
loop
gsel 0 : pos 0, 0
gmode 5, scx, scy, 256
gcopy 10, 0, 0, scx, scy
redraw 1
await 1000
loop
stop
*reloadAll
logmes "key:"+iparam
if (iparam == 49) {
//Load PointData
gosub *reloadPointData
//Load AttackData
gosub *reloadAttackData
//Load LinkData
gosub *reloadLinkData
}
if(iparam == 50) {
beforeinfo = ginfo(2)
gsel 0
bmpsave "Intel.bmp"
logmes "param:"+stat
gsel beforeinfo
}
return
*reloadPointData
//Load PointData
notesel pointsData
exist "pointData.txt"
if strsize < 0 {
notesave "pointData.txt"
}
noteload "pointData.txt"
pointmax = notemax
logmes "Portals:"+notemax
sdim pointData, 4, pointmax, 64
dim posX, pointmax
dim posY, pointmax
dim posOwner, pointmax
dim posNumber, pointmax
dim posName, pointmax
repeat pointmax
sdim tmp, 1024
noteget tmp, cnt
//x, y, pointName
split tmp, " ", pointData(cnt, 0), pointData(cnt, 1), pointData(cnt, 2)
//X, Y
posX(cnt) = int(pointData(cnt, 0))
posY(cnt) = int(pointData(cnt, 1))
//PosName
posName(cnt) = pointData(cnt, 2)
//Owner -1: Enlightened 0:Uncaptured 1:Resistance
posOwner(cnt) = 0
posNumber(cnt) = cnt
logmes "Loaded Point ["+pointData(cnt, 2)+"]("+pointData(cnt, 0)+","+pointData(cnt, 1)+")"
loop
return
*reloadAttackData
notesel attacksData
exist "attackData.txt"
if strsize < 0 {
notesave "attackData.txt"
}
noteload "attackData.txt"
repeat notemax
sdim tmp, 1024
noteget tmp, cnt
//PointNumber, AttackedColor
split tmp, " ", pointData(cnt, 0), pointData(cnt, 1)
cntt = cnt
searched = -1
repeat pointmax
if posName(cnt) == pointData(cntt, 0) {
searched = cnt
break
}
loop
if searched == -1 : continue
posOwner(searched) += int(pointData(cnt, 1))
logmes "Attacked ["+posName(searched)+"] by ["+int(pointData(cnt, 1))+"]"
loop
return
*reloadLinkData
paintspcount = 0
notesel linksData
exist "linkData.txt"
if strsize < 0 {
notesave "linkData.txt"
}
noteload "linkData.txt"
dim posLink, notemax, 2
linkmax = notemax
logmes "AllLinks:"+notemax
sdim linkBufferData, 2, notemax, 64
repeat notemax
sdim tmp, 1024
noteget tmp, cnt
commentQ = strmid(tmp, 0, 2)
if commentQ == "//" : continue
//From -> To
split tmp, "->", linkBufferData(cnt, 0), linkBufferData(cnt, 1)
cntt = cnt
searchedFrom = -1
repeat pointmax
if posName(cnt) == linkBufferData(cntt, 0) {
searchedFrom = cnt
break
}
loop
searchedTo = -1
repeat pointmax
if posName(cnt) == linkBufferData(cntt, 1) {
searchedTo = cnt
break
}
loop
if searchedFrom == -1 || searchedTo == -1 : continue
posLink(cnt, 0) = searchedFrom
posLink(cnt, 1) = searchedTo
logmes "Linked ["+posName(searchedFrom)+"] -> ["+posName(searchedTo)+"]"
cppp = cnt
// C
//
//A--->B
linkA = searchedFrom
linkB = searchedTo
outsideCnt = cnt
repeat cnt
linkC = -1
//Check From A to C
if linkA == posLink(cnt, 0) {
// C(To)
// /
//A-->B
linkC = posLink(cnt, 1)
}
//Check From C to A
if linkA == posLink(cnt, 1) {
// C(From)
// /
//A-->B
linkC = posLink(cnt, 0)
}
if linkC == -1 : continue
successCF = 0
repeat outSideCnt
//Check From B to C
if (linkB == posLink(cnt, 0) && linkC == posLink(cnt, 1)) {
successCF = 1 : break
}
//Check From C to B
if (linkC == posLink(cnt, 0) && linkB == posLink(cnt, 1)) {
successCF = 1 : break
}
loop
if successCF == 0 : continue
logmes "Create Control Field ["+posName(linkA)+" -> "+posName(linkB)+" -> "+posName(linkC)+"]"
paintsData(paintspcount) = linkA
ax = posX(linkA) : bx = posX(linkB) : cx = posX(linkC)
ay = posY(linkA) : by = posY(linkB) : cy = posY(linkC)
/*a = sqrt((cy - by) * (cy - by) + (cx - bx) * (cx - bx))
b = sqrt((cy - ay) * (cy - ay) + (cx - ax) * (cx - ax))
c = sqrt((ay - by) * (ay - by) + (ax - bx) * (ax - bx))
patX = (a*ax + b*bx + c*cx) / (a + b + c)
patY = (a*ay + b*by + c*cy) / (a + b + c)*/
patX = (ax + bx + cx) / 3
patY = (ay + by + cy) / 3
//logmes "paintspcount: "+paintspcount
paintsPosData(paintspcount, 0) = patX
paintsPosData(paintspcount, 1) = patY
//logmes "重心:("+paintsPosData(paintspcount, 0)+", "+paintsPosData(paintspcount, 1)+")"
paintspcount += 1
loop
loop
return
*savePoints
end
*editPoint
px = mousex
py = mousey
dis = 0
mindis = 999999
dpnum = 0
repeat pointmax
ex = posX(cnt)
ey = posY(cnt)
gosub *getDistance
if(dis < mindis) {
mindis = dis
dpnum = cnt
}
loop
saved_flag = 0
apointName = posName(dpnum)
apx = posX(dpnum)
apy = posY(dpnum)
screen 9, 200, 200, screen_fixedsize+screen_tool, 0, 0
cls
objsize 200, 24 : pos 0, 0
input apointName
mes "("+apx+", "+apy+")"
mes
button gosub "修正", *fixPoint
button gosub "削除", *delPoint
button gosub "キャンセル", *cancelPoint
saved_flag = 0
repeat
if saved_flag : break
await 20
loop
return
*getDistance
dx = px - ex
dy = py - ey
dis = sqrt(dx*dx+dy*dy)
return
*addPoint
swp = 0
switch(iparam)
case 0: swbreak
case 6: gosub *paintPoint : swp = 1 : swbreak
case 3: gosub *editPoint : swp = 1 : swbreak
default: logmes ""+iparam: swp = 1 : swbreak
swend
if swp : return
apx = mousex
apy = mousey
saved_flag = 0
apointName = ""
screen 9, 200, 200, screen_fixedsize+screen_tool, 0, 0
cls
objsize 200, 24 : pos 0, 0
input apointName
mes "("+apx+", "+apy+")"
mes
button gosub "追加", *submitPoint
button gosub "キャンセル", *cancelPoint
saved_flag = 0
repeat
if saved_flag : break
await 20
loop
return
*fixPoint
svstr = ""+ apx + " "+ apy + " " + apointName
notesel pointsData
noteload "pointData.txt"
noteadd svstr, dpnum, 1
notesave "pointData.txt"
logmes "Fixed Point ("+apx+", "+apy+") as "+apointName
gosub *reloadPointData
saved_flag = 1
gsel 9, -1
return
*paintPoint
px = mousex
py = mousey
dis = 0
mindis = 999999
dpnum = 0
repeat pointmax
ex = posX(cnt)
ey = posY(cnt)
gosub *getDistance
if(dis < mindis) {
mindis = dis
dpnum = cnt
}
loop
paintsData(paintspcount) = dpnum
paintsPosData(paintspcount, 0) = px
paintsPosData(paintspcount, 1) = py
paintspcount += 1
return
*delPoint
dialog "本当に["+apointName+"]を削除しますか?", 3, "削除の確認"
if stat != 6 : return
notesel pointsData
noteload "pointData.txt"
notedel dpnum
notesave "pointData.txt"
logmes "Fixed Point ("+apx+", "+apy+") as "+apointName
gosub *reloadPointData
saved_flag = 1
gsel 9, -1
return
*submitPoint
svstr = ""+ apx + " "+ apy + " " + apointName
notesel pointsData
noteload "pointData.txt"
noteadd svstr, pointmax
notesave "pointData.txt"
logmes "Saved Point ("+apx+", "+apy+") as "+apointName
gosub *reloadPointData
saved_flag = 1
gsel 9, -1
return
*cancelPoint
saved_flag = 1
gsel 9, -1
return
*setOwnerColor
owner = posOwner(cntr)
if (owner == 0) {
br = 255
bg = 255
bb = 255
}
if (owner < 0) {
br = 0
bg = 255
bb = 0
}
if (owner > 0) {
br = 0
bg = 0
bb = 255
}
return
*drawLink
color br, bg, bb
line posX(posLink(cntr, 1)), posY(posLink(cntr, 1)), posX(posLink(cntr, 0)), posY(posLink(cntr, 0))
return
*drawOwner
gsel 2 : color 0, 0, 0 : boxf
gosub *setOwnerColor
pos 0, 0
mes posName(cntr)
tmpx = ginfo_mesx
gsel 10
px = posX(cntr) - tmpx/2 + crs
py = posY(cntr) + crs+2
if(px < 0) : px = 0
if(py < 0) : py = 0
if(px + tmpx >= scx) : px = scx - tmpx
if(py + 12 >= scy) : px = scy - 12
pos px, py : color br, bg, bb
mes posName(cntr)
return
*drawPoint
repeat 8
cntt = 3 - cnt
color br - (cntt * 32) * (owner == 0), bg - (cntt * 32) * (owner <= 0), bb - (cntt * 32) * (owner >= 0)
if cnt == 0 : color br, bg, bb
circle posX(cntr)-(crs+cntt), posY(cntr)-(crs+cntt), posX(cntr)+(crs+cntt), posY(cntr)+(crs+cntt)
loop
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment