Skip to content

Commit

Permalink
Add stateowner redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
K4thos committed Feb 14, 2023
1 parent 2d4e80c commit 8f65b92
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion external/script/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ end
function stateInfo()
return string.format(
'State No: %d (P%d); CTRL: %s; Type: %s; MoveType: %s; Physics: %s; Time: %d',
stateno(), stateowner(), boolToInt(ctrl()), statetype(), movetype(), physics(), time()-1
stateno(), stateownerplayerno(), boolToInt(ctrl()), statetype(), movetype(), physics(), time()-1
)
end

Expand Down
8 changes: 8 additions & 0 deletions src/bytecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const (
OC_enemynear
OC_playerid
OC_p2
OC_stateowner
OC_rdreset
OC_const_
OC_st_
Expand Down Expand Up @@ -997,6 +998,13 @@ func (be BytecodeExp) run(c *Char) BytecodeValue {
}
sys.bcStack.Push(BytecodeSF())
i += int(*(*int32)(unsafe.Pointer(&be[i]))) + 4
case OC_stateowner:
if c = sys.chars[c.ss.sb.playerNo][0]; c != nil {
i += 4
continue
}
sys.bcStack.Push(BytecodeSF())
i += int(*(*int32)(unsafe.Pointer(&be[i]))) + 4
case OC_rdreset:
// NOP
case OC_run:
Expand Down
26 changes: 15 additions & 11 deletions src/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,17 @@ func newCompiler() *Compiler {

var triggerMap = map[string]int{
// redirections
"player": 0,
"parent": 0,
"root": 0,
"helper": 0,
"target": 0,
"partner": 0,
"enemy": 0,
"enemynear": 0,
"playerid": 0,
"p2": 0,
"player": 0,
"parent": 0,
"root": 0,
"helper": 0,
"target": 0,
"partner": 0,
"enemy": 0,
"enemynear": 0,
"playerid": 0,
"p2": 0,
"stateowner": 0,
// mugen triggers
"abs": 1,
"acos": 1,
Expand Down Expand Up @@ -1159,7 +1160,7 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string,
case "":
return bvNone(), Error("Nothing assigned")
case "root", "player", "parent", "helper", "target", "partner",
"enemy", "enemynear", "playerid", "p2":
"enemy", "enemynear", "playerid", "p2", "stateowner":
switch c.token {
case "parent":
opc = OC_parent
Expand All @@ -1170,6 +1171,9 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string,
case "p2":
opc = OC_p2
c.token = c.tokenizer(in)
case "stateowner":
opc = OC_stateowner
c.token = c.tokenizer(in)
default:
switch c.token {
case "player":
Expand Down
16 changes: 12 additions & 4 deletions src/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,14 @@ func triggerFunctions(l *lua.LState) {
l.Push(lua.LBool(ret))
return 1
})
luaRegister(l, "stateowner", func(*lua.LState) int {
ret := false
if c := sys.chars[sys.debugWC.ss.sb.playerNo][0]; c != nil {
sys.debugWC, ret = c, true
}
l.Push(lua.LBool(ret))
return 1
})
// vanilla triggers
luaRegister(l, "ailevel", func(*lua.LState) int {
l.Push(lua.LNumber(sys.debugWC.aiLevel()))
Expand Down Expand Up @@ -4159,10 +4167,6 @@ func triggerFunctions(l *lua.LState) {
l.Push(lua.LNumber(sys.debugWC.curFrame.Number))
return 1
})
luaRegister(l, "stateowner", func(*lua.LState) int {
l.Push(lua.LNumber(sys.debugWC.ss.sb.playerNo + 1))
return 1
})
luaRegister(l, "stateownerid", func(*lua.LState) int {
l.Push(lua.LNumber(sys.chars[sys.debugWC.ss.sb.playerNo][0].id))
return 1
Expand All @@ -4171,6 +4175,10 @@ func triggerFunctions(l *lua.LState) {
l.Push(lua.LString(sys.chars[sys.debugWC.ss.sb.playerNo][0].name))
return 1
})
luaRegister(l, "stateownerplayerno", func(*lua.LState) int {
l.Push(lua.LNumber(sys.debugWC.ss.sb.playerNo + 1))
return 1
})
luaRegister(l, "tickcount", func(*lua.LState) int {
l.Push(lua.LNumber(sys.tickCount))
return 1
Expand Down

0 comments on commit 8f65b92

Please sign in to comment.