Skip to content

Commit

Permalink
feat: removeText, new text params, numText trigger, explod friction (#…
Browse files Browse the repository at this point in the history
…2082)

* feat: removeText, new text params, numText trigger, explod friction

* lineSpacing default and localscl, minor organization

* removeText redirectID

* minor fix

* removed localscale from linespacing

* fix: accel/friction order,stoping threshold,removed scale convertions from frictions

* fix: more fixes

* even more fixes

* fix: text sctrl not redirecting ownerid correctly
  • Loading branch information
RakieI authored Oct 19, 2024
1 parent 81434cc commit c1af1cd
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 8 deletions.
109 changes: 107 additions & 2 deletions src/bytecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const (
OC_numexplod
OC_numprojid
OC_numproj
OC_numtext
OC_teammode
OC_teamside
OC_hitdefattr
Expand Down Expand Up @@ -740,6 +741,9 @@ const (
OC_ex2_explodvar_accel_x
OC_ex2_explodvar_accel_y
OC_ex2_explodvar_accel_z
OC_ex2_explodvar_friction_x
OC_ex2_explodvar_friction_y
OC_ex2_explodvar_friction_z
OC_ex2_explodvar_angle
OC_ex2_explodvar_angle_x
OC_ex2_explodvar_angle_y
Expand Down Expand Up @@ -1641,6 +1645,8 @@ func (be BytecodeExp) run(c *Char) BytecodeValue {
*sys.bcStack.Top() = c.numProjID(*sys.bcStack.Top())
case OC_numtarget:
*sys.bcStack.Top() = c.numTarget(*sys.bcStack.Top())
case OC_numtext:
*sys.bcStack.Top() = c.numText(*sys.bcStack.Top())
case OC_palno:
sys.bcStack.PushI(c.palno())
case OC_pos_x:
Expand Down Expand Up @@ -3117,6 +3123,12 @@ func (be BytecodeExp) run_ex2(c *Char, i *int, oc *Char) {
case OC_ex2_explodvar_accel_y:
correctScale = true
fallthrough
case OC_ex2_explodvar_friction_x:
correctScale = true
fallthrough
case OC_ex2_explodvar_friction_y:
correctScale = true
fallthrough
case OC_ex2_explodvar_anim:
fallthrough
case OC_ex2_explodvar_animelem:
Expand Down Expand Up @@ -4197,19 +4209,22 @@ type destroySelf StateControllerBase
const (
destroySelf_recursive = iota
destroySelf_removeexplods
destroySelf_removetexts
destroySelf_redirectid
)

func (sc destroySelf) Run(c *Char, _ []int32) bool {
crun := c
rec, rem := false, false
rec, rem, rtx := false, false, false
self := true
StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool {
switch id {
case destroySelf_recursive:
rec = exp[0].evalB(c)
case destroySelf_removeexplods:
rem = exp[0].evalB(c)
case destroySelf_removetexts:
rtx = exp[0].evalB(c)
case destroySelf_redirectid:
if rid := sys.playerID(exp[0].evalI(c)); rid != nil {
self = rid.id == c.id
Expand All @@ -4220,7 +4235,7 @@ func (sc destroySelf) Run(c *Char, _ []int32) bool {
}
return true
})
return crun.destroySelf(rec, rem) && self
return crun.destroySelf(rec, rem, rtx) && self
}

type changeAnim StateControllerBase
Expand Down Expand Up @@ -4881,6 +4896,7 @@ const (
explod_random
explod_postype
explod_velocity
explod_friction
explod_accel
explod_scale
explod_bindtime
Expand Down Expand Up @@ -5017,6 +5033,14 @@ func (sc explod) Run(c *Char, _ []int32) bool {
e.velocity[2] = exp[2].evalF(c) * redirscale
}
}
case explod_friction:
e.friction[0] = exp[0].evalF(c)
if len(exp) > 1 {
e.friction[1] = exp[1].evalF(c)
if len(exp) > 2 {
e.friction[2] = exp[2].evalF(c)
}
}
case explod_accel:
e.accel[0] = exp[0].evalF(c) * redirscale
if len(exp) > 1 {
Expand Down Expand Up @@ -5316,6 +5340,7 @@ func (sc modifyExplod) Run(c *Char, _ []int32) bool {
e.setZ(e.offset[2])
e.relativePos = [3]float32{0, 0, 0}
e.velocity = [3]float32{0, 0, 0}
e.friction = [3]float32{1, 1, 1}
e.accel = [3]float32{0, 0, 0}
e.bindId = -2
if e.bindtime == 0 {
Expand Down Expand Up @@ -5423,6 +5448,29 @@ func (sc modifyExplod) Run(c *Char, _ []int32) bool {
}
}
}
case explod_friction:
if ptexists || c.stWgi().ikemenver[0] != 0 || c.stWgi().ikemenver[1] != 0 {
friction := exp[0].evalF(c)
eachExpl(func(e *Explod) {
e.friction[0] = friction
})
}
if len(exp) > 1 {
if ptexists || c.stWgi().ikemenver[0] != 0 || c.stWgi().ikemenver[1] != 0 {
friction := exp[1].evalF(c)
eachExpl(func(e *Explod) {
e.friction[1] = friction
})
}
if len(exp) > 2 {
if ptexists || c.stWgi().ikemenver[0] != 0 || c.stWgi().ikemenver[1] != 0 {
friction := exp[2].evalF(c)
eachExpl(func(e *Explod) {
e.friction[2] = friction
})
}
}
}
case explod_accel:
if ptexists || c.stWgi().ikemenver[0] != 0 || c.stWgi().ikemenver[1] != 0 {
accel := exp[0].evalF(c) * redirscale
Expand Down Expand Up @@ -11001,20 +11049,28 @@ const (
text_localcoord
text_bank
text_align
text_linespacing
text_textdelay
text_text
text_pos
text_velocity
text_friction
text_accel
text_scale
text_color
text_id
text_redirectid
)

func (sc text) Run(c *Char, _ []int32) bool {
crun := c
params := []interface{}{}
ownerID := crun.id
ts := NewTextSprite()
ts.SetLocalcoord(float32(sys.scrrect[2]), float32(sys.scrrect[3]))
var xscl, yscl float32 = 1, 1
var fnt int = -1
ts.ownerid = ownerID
StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool {
switch id {
case text_removetime:
Expand Down Expand Up @@ -11058,11 +11114,30 @@ func (sc text) Run(c *Char, _ []int32) bool {
ts.bank = exp[0].evalI(c)
case text_align:
ts.align = exp[0].evalI(c)
case text_linespacing:
ts.lineSpacing = exp[0].evalF(c)
case text_textdelay:
ts.textDelay = exp[0].evalF(c)
case text_pos:
ts.x = exp[0].evalF(c)/ts.localScale + float32(ts.offsetX)
if len(exp) > 1 {
ts.y = exp[1].evalF(c) / ts.localScale
}
case text_velocity:
ts.velocity[0] = exp[0].evalF(c)/ts.localScale
if len(exp) > 1 {
ts.velocity[1] = exp[1].evalF(c) / ts.localScale
}
case text_friction:
ts.friction[0] = exp[0].evalF(c)
if len(exp) > 1 {
ts.friction[1] = exp[1].evalF(c)
}
case text_accel:
ts.accel[0] = exp[0].evalF(c)/ts.localScale
if len(exp) > 1 {
ts.accel[1] = exp[1].evalF(c) / ts.localScale
}
case text_scale:
xscl = exp[0].evalF(c)
if len(exp) > 1 {
Expand All @@ -11077,9 +11152,12 @@ func (sc text) Run(c *Char, _ []int32) bool {
}
}
ts.SetColor(r, g, b)
case text_id:
ts.id = exp[0].evalI(c)
case text_redirectid:
if rid := sys.playerID(exp[0].evalI(c)); rid != nil {
crun = rid
ts.ownerid = crun.id
} else {
return false
}
Expand All @@ -11100,6 +11178,33 @@ func (sc text) Run(c *Char, _ []int32) bool {
return false
}

type removeText StateControllerBase

const (
removetext_id byte = iota
removetext_redirectid
)

func (sc removeText) Run(c *Char, _ []int32) bool {
crun := c
textID := int32(-1)
StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool {
switch id {
case removetext_id:
textID = exp[0].evalI(c)
case removetext_redirectid:
if rid := sys.playerID(exp[0].evalI(c)); rid != nil {
crun = rid
} else {
return false
}
}
return true
})
sys.lifebar.RemoveText(textID, crun.id)
return false
}

// Platform bytecode definitons
type createPlatform StateControllerBase

Expand Down
27 changes: 25 additions & 2 deletions src/char.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ type Explod struct {
statehaschanged bool
removetime int32
velocity [3]float32
friction [3]float32
accel [3]float32
sprpriority int32
layerno int32
Expand Down Expand Up @@ -1198,6 +1199,7 @@ func (e *Explod) clear() {
bindId: -2,
ignorehitpause: true,
interpolate_scale: [...]float32{1, 1, 0, 0},
friction: [3]float32{1, 1, 1},
}
}
func (e *Explod) setX(x float32) {
Expand Down Expand Up @@ -1501,7 +1503,11 @@ func (e *Explod) update(oldVer bool, playerNo int) {
e.newPos[1] = e.pos[1] + e.velocity[1]
e.newPos[2] = e.pos[2] + e.velocity[2]
for i := range e.velocity {
e.velocity[i] *= e.friction[i]
e.velocity[i] += e.accel[i]
if math.Abs(float64(e.velocity[i])) < 0.1 && math.Abs(float64(e.friction[i])) < 1 {
e.velocity[i] = 0
}
}
eleminterpolate := e.interpolate && e.interpolate_time[1] > 0 && e.interpolate_animelem[1] >= 0
if e.animfreeze || eleminterpolate {
Expand Down Expand Up @@ -3782,6 +3788,20 @@ func (c *Char) numExplod(eid BytecodeValue) BytecodeValue {
}
return BytecodeInt(n)
}

func (c *Char) numText(textid BytecodeValue) BytecodeValue {
if textid.IsSF() {
return BytecodeSF()
}
var id, n int32 = textid.ToI(), 0
for _, ts := range sys.lifebar.textsprite {
if ts.id == id && ts.ownerid == c.id {
n++
}
}
return BytecodeInt(n)
}

func (c *Char) explodVar(eid BytecodeValue, idx BytecodeValue, vtype OpCode) BytecodeValue {
if eid.IsSF() {
return BytecodeSF()
Expand Down Expand Up @@ -4510,18 +4530,21 @@ func (c *Char) destroy() {
}
}

func (c *Char) destroySelf(recursive, removeexplods bool) bool {
func (c *Char) destroySelf(recursive, removeexplods, removetexts bool) bool {
if c.helperIndex <= 0 {
return false
}
c.setCSF(CSF_destroy)
if removeexplods {
c.removeExplod(-1, -1)
}
if removetexts {
sys.lifebar.RemoveText(-1, c.id)
}
if recursive {
for _, ch := range c.children {
if ch != nil {
ch.destroySelf(recursive, removeexplods)
ch.destroySelf(recursive, removeexplods, removetexts)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func newCompiler() *Compiler {
"projectile": c.projectile,
"remappal": c.remapPal,
"removeexplod": c.removeExplod,
"removetext": c.removeText,
"reversaldef": c.reversalDef,
"screenbound": c.screenBound,
"selfstate": c.selfState,
Expand Down Expand Up @@ -278,6 +279,7 @@ var triggerMap = map[string]int{
"numproj": 1,
"numprojid": 1,
"numtarget": 1,
"numtext": 1,
"p1name": 1,
"p2bodydist": 1,
"p2dist": 1,
Expand Down Expand Up @@ -2031,6 +2033,19 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string,
default:
return bvNone(), Error(fmt.Sprint("Invalid argument: %s", c.token))
}
case "friction":
c.token = c.tokenizer(in)

switch c.token {
case "x":
opc = OC_ex2_explodvar_friction_x
case "y":
opc = OC_ex2_explodvar_friction_y
case "z":
opc = OC_ex2_explodvar_friction_z
default:
return bvNone(), Error(fmt.Sprint("Invalid argument: %s", c.token))
}
case "scale":
c.token = c.tokenizer(in)

Expand Down Expand Up @@ -2596,6 +2611,11 @@ func (c *Compiler) expValue(out *BytecodeExp, in *string,
return bvNone(), err
}
out.append(OC_numtarget)
case "numtext":
if _, err := c.oneArg(out, in, rd, true, BytecodeInt(-1)); err != nil {
return bvNone(), err
}
out.append(OC_numtext)
case "palno":
out.append(OC_palno)
case "pos":
Expand Down
Loading

0 comments on commit c1af1cd

Please sign in to comment.