Skip to content

Commit 97c5508

Browse files
authored
Merge pull request #3608 from ikemen-engine/fix4
feat: RemapMovelist sctrl; fix: WinCount regression
2 parents 117aad6 + 8a96bc6 commit 97c5508

8 files changed

Lines changed: 142 additions & 28 deletions

File tree

external/script/menu.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,11 @@ function menu.f_commandlistParse()
763763
end
764764
if player(pn) and aiLevel() == 0 then
765765
local ref = getSelectNo()
766-
if start.f_getCharData(ref).commandlist == nil then
767-
local movelist = getCharMovelist(ref)
766+
local movelist = getMovelist()
767+
if sel.movelistText ~= movelist then
768+
sel.movelistText = movelist
769+
sel.commandlist = nil
770+
sel.movelistLine = 1
768771
if movelist ~= '' then
769772
-- Replace glyph tokens with <token> for later lookup in motif.glyphs.
770773
for k, v in main.f_sortKeys(motif.glyphs, function(t, a, b) return string.len(a) > string.len(b) end) do
@@ -801,14 +804,14 @@ function menu.f_commandlistParse()
801804
table.insert(t, subt)
802805
end
803806
t[#t] = nil --blank line produced by regexp matching
804-
start.f_getCharData(ref).commandlist = t
807+
sel.commandlist = t
805808
end
806809
end
807810
table.insert(menu.t_movelists, {
808811
pn = pn,
809812
name = start.f_getCharData(ref).name,
810813
tbl = sel,
811-
commandlist = start.f_getCharData(ref).commandlist,
814+
commandlist = sel.commandlist,
812815
})
813816
end
814817
end

external/script/start.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,10 @@ function start.f_selectReset(hardReset, preserveProgress)
17631763
if not preserveProgress then
17641764
resetGameStats()
17651765
setMatchNo(1)
1766-
setWinCount(1, 0)
1767-
setWinCount(2, 0)
1766+
if main.elimination then
1767+
setWinCount(1, 0)
1768+
setWinCount(2, 0)
1769+
end
17681770
setConsecutiveWins(1, 0)
17691771
setConsecutiveWins(2, 0)
17701772
end

src/bytecode.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12202,6 +12202,34 @@ func (sc redLifeSet) Run(c *Char, _ []int32) bool {
1220212202
return false
1220312203
}
1220412204

12205+
type remapMovelist StateControllerBase
12206+
12207+
const (
12208+
remapMovelist_value byte = iota
12209+
remapMovelist_redirectid
12210+
)
12211+
12212+
func (sc remapMovelist) Run(c *Char, _ []int32) bool {
12213+
crun := getRedirectedChar(c, StateControllerBase(sc), remapMovelist_redirectid, "RemapMovelist")
12214+
if crun == nil {
12215+
return false
12216+
}
12217+
12218+
var v int32
12219+
StateControllerBase(sc).run(c, func(paramID byte, exp []BytecodeExp) bool {
12220+
switch paramID {
12221+
case remapMovelist_value:
12222+
v = exp[0].evalI(c)
12223+
}
12224+
return true
12225+
})
12226+
if v < 0 {
12227+
v = 0
12228+
}
12229+
crun.movelist = v
12230+
return false
12231+
}
12232+
1220512233
type remapSprite StateControllerBase
1220612234

1220712235
const (

src/char.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,61 @@ type PalInfo struct {
29492949
selectable bool
29502950
}
29512951

2952+
func readMovelistFiles(is IniSection) map[int]string {
2953+
ret := make(map[int]string)
2954+
if v := decodeShiftJIS(is["movelist"]); v != "" {
2955+
ret[0] = v
2956+
}
2957+
if v := decodeShiftJIS(is["movelist0"]); v != "" {
2958+
if _, ok := ret[0]; !ok {
2959+
ret[0] = v
2960+
}
2961+
}
2962+
for k, v := range is {
2963+
kl := strings.ToLower(k)
2964+
if kl == "movelist" || kl == "movelist0" || !strings.HasPrefix(kl, "movelist") {
2965+
continue
2966+
}
2967+
idx := kl[len("movelist"):]
2968+
if idx == "" || !IsInt(idx) {
2969+
continue
2970+
}
2971+
n := int(Atoi(idx))
2972+
if n < 0 {
2973+
continue
2974+
}
2975+
if ml := decodeShiftJIS(v); ml != "" {
2976+
ret[n] = ml
2977+
}
2978+
}
2979+
if len(ret) == 0 {
2980+
return nil
2981+
}
2982+
return ret
2983+
}
2984+
2985+
func loadMovelistFiles(def string, files map[int]string) map[int]string {
2986+
if len(files) == 0 {
2987+
return nil
2988+
}
2989+
ret := make(map[int]string, len(files))
2990+
for idx, file := range files {
2991+
idx, file := idx, file
2992+
LoadFile(&file, []string{def, "", "data/"}, "", func(filename string) error {
2993+
txt, err := LoadText(filename)
2994+
if err != nil {
2995+
return err
2996+
}
2997+
ret[idx] = txt
2998+
return nil
2999+
})
3000+
}
3001+
if len(ret) == 0 {
3002+
return nil
3003+
}
3004+
return ret
3005+
}
3006+
29523007
type CharGlobalInfo struct {
29533008
def string
29543009
name string
@@ -2977,6 +3032,7 @@ type CharGlobalInfo struct {
29773032
callFuncs map[string]BytecodeFunction
29783033
hitPauseToggleFlagCount int32
29793034
quotes [MaxQuotes]string
3035+
movelists map[int]string
29803036
portraitscale float32
29813037
constants map[string]float32
29823038
remapPreset map[string]RemapPreset
@@ -3002,6 +3058,7 @@ func newCharGlobalInfo() CharGlobalInfo {
30023058
palInfo: make(map[int]PalInfo, sys.cfg.Config.PaletteMax),
30033059
fnt: make(map[int]*Fnt),
30043060
quotes: [MaxQuotes]string{},
3061+
movelists: make(map[int]string),
30053062
remapPreset: make(map[string]RemapPreset),
30063063
portraitscale: 1,
30073064
}
@@ -3232,6 +3289,7 @@ type Char struct {
32323289
ownpal bool
32333290
ownProjectile bool
32343291
winquote int32
3292+
movelist int32
32353293
memberNo int
32363294
selectNo int
32373295
inheritJuggle int32
@@ -3329,6 +3387,7 @@ func (c *Char) init(n int, idx int) {
33293387
facing: 1,
33303388
minus: 3,
33313389
winquote: -1,
3390+
movelist: 0,
33323391
clsnBaseScale: [2]float32{1, 1},
33333392
clsnScaleMul: [2]float32{1, 1},
33343393
clsnScale: [2]float32{1, 1},
@@ -3454,6 +3513,7 @@ func (c *Char) prepareNextRound() {
34543513
//c.updateSizeBox()
34553514
c.oldPos, c.interPos = c.pos, c.pos
34563515
if c.helperIndex == 0 {
3516+
c.movelist = 0
34573517
if sys.roundsExisted[c.playerNo&1] > 0 { // TODO: Why do we need this branch?
34583518
c.palfx.clear()
34593519
} else {
@@ -3546,6 +3606,7 @@ func (c *Char) resetModifyPlayer() {
35463606
c.powerMax = gi.data.power
35473607
c.dizzyPointsMax = gi.data.dizzypoints
35483608
c.guardPointsMax = gi.data.guardpoints
3609+
c.movelist = 0
35493610
// c.teamside already assigned by loadCharacter()
35503611
}
35513612

@@ -3578,6 +3639,7 @@ func (c *Char) load(def string) error {
35783639

35793640
lines, lnidx := SplitAndTrim(str, "\n"), 0
35803641
cns, sprite, anim, sound := "", "", "", ""
3642+
var movelistFiles map[int]string
35813643
info, files, keymap, mapArray := true, true, true, true
35823644
lanInfo, lanFiles, lanKeymap, lanMapArray := true, true, true, true
35833645
shaders := true
@@ -3676,6 +3738,7 @@ func (c *Char) load(def string) error {
36763738
sprite = decodeShiftJIS(is["sprite"])
36773739
anim = decodeShiftJIS(is["anim"])
36783740
sound = decodeShiftJIS(is["sound"])
3741+
movelistFiles = readMovelistFiles(is)
36793742
for i := 0; i < sys.cfg.Config.PaletteMax; i++ {
36803743
pal := gi.palInfo[i]
36813744
pal.filename = decodeShiftJIS(is[fmt.Sprintf("pal%v", i+1)])
@@ -3764,6 +3827,9 @@ func (c *Char) load(def string) error {
37643827
// Reset maps in order to upload the freshly loaded defaults
37653828
c.mapReset(nil)
37663829

3830+
// Load movelists from the loaded character DEF
3831+
gi.movelists = loadMovelistFiles(def, movelistFiles)
3832+
37673833
// Set constants to defaults
37683834
c.initConstants()
37693835

src/compiler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func newStateCompiler() *StateCompiler {
170170
"printtoconsole": c.printToConsole,
171171
"redlifeadd": c.redLifeAdd,
172172
"redlifeset": c.redLifeSet,
173+
"remapmovelist": c.remapMovelist,
173174
"remapsprite": c.remapSprite,
174175
"rootmapadd": c.rootMapAdd,
175176
"rootmapset": c.rootMapSet,

src/compiler_functions.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5397,6 +5397,21 @@ func (c *StateCompiler) redLifeSet(is IniSection, sc *StateControllerBase) (Stat
53975397
return *ret, err
53985398
}
53995399

5400+
func (c *StateCompiler) remapMovelist(is IniSection, sc *StateControllerBase) (StateController, error) {
5401+
ret, err := (*remapMovelist)(sc), c.stateSec(is, func() error {
5402+
if err := c.paramValue(is, sc, "redirectid",
5403+
remapMovelist_redirectid, VT_Int, 1, false); err != nil {
5404+
return err
5405+
}
5406+
if err := c.paramValue(is, sc, "value",
5407+
remapMovelist_value, VT_Int, 1, false); err != nil {
5408+
return err
5409+
}
5410+
return nil
5411+
})
5412+
return *ret, err
5413+
}
5414+
54005415
func (c *StateCompiler) remapSprite(is IniSection, sc *StateControllerBase) (StateController, error) {
54015416
ret, err := (*remapSprite)(sc), c.stateSec(is, func() error {
54025417
if err := c.paramValue(is, sc, "redirectid",

src/script.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,16 +3330,6 @@ func systemScriptInit(l *lua.LState) {
33303330
l.Push(tbl)
33313331
return 1
33323332
})
3333-
luaRegister(l, "getCharMovelist", func(*lua.LState) int {
3334-
/*Get the movelist file path for a character slot.
3335-
@function getCharMovelist
3336-
@tparam int charRef 0-based character index in the select list.
3337-
@treturn string movelist Path or identifier of the movelist file.
3338-
function getCharMovelist(charRef) end*/
3339-
c := sys.sel.GetChar(int(numArg(l, 1)))
3340-
l.Push(lua.LString(c.movelist))
3341-
return 1
3342-
})
33433333
luaRegister(l, "getCharName", func(*lua.LState) int {
33443334
/*Get the display name of a character slot.
33453335
@function getCharName
@@ -3850,6 +3840,26 @@ func systemScriptInit(l *lua.LState) {
38503840
l.Push(lua.LNumber(ti))
38513841
return 1
38523842
})
3843+
luaRegister(l, "getMovelist", func(*lua.LState) int {
3844+
/*[redirectable] Get the character's movelist text.
3845+
@function getMovelist
3846+
@treturn string movelist Movelist text.
3847+
function getCharMovelist() end*/
3848+
idx := int(sys.debugWC.movelist)
3849+
if idx < 0 {
3850+
idx = 0
3851+
}
3852+
if ml, ok := sys.debugWC.gi().movelists[idx]; ok {
3853+
l.Push(lua.LString(ml))
3854+
return 1
3855+
}
3856+
if ml, ok := sys.debugWC.gi().movelists[0]; ok {
3857+
l.Push(lua.LString(ml))
3858+
return 1
3859+
}
3860+
l.Push(lua.LString(""))
3861+
return 1
3862+
})
38533863
luaRegister(l, "getRandom", func(l *lua.LState) int {
38543864
/*Return a 32-bit random number, updating the global seed.
38553865
@function getRandom

src/system.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,7 +4189,6 @@ type SelectChar struct {
41894189
intro string
41904190
ending string
41914191
arcadepath string
4192-
movelist string
41934192
pal []int32
41944193
pal_defaults []int32
41954194
pal_keymap []int32
@@ -4439,7 +4438,7 @@ func (s *Select) AddChar(def string) *SelectChar {
44394438
return useDummy("DEF read error: " + err.Error())
44404439
}
44414440

4442-
var cns_orig, sprite_orig, anim_orig, movelist_orig string
4441+
var cns_orig, sprite_orig, anim_orig string
44434442
var fnt_orig [10][2]string
44444443

44454444
lines, lnidx := SplitAndTrim(charDefContent, "\n"), 0
@@ -4499,7 +4498,6 @@ func (s *Select) AddChar(def string) *SelectChar {
44994498
}
45004499
}
45014500

4502-
movelist_orig = decodeShiftJIS(isec["movelist"])
45034501
for fIdx := range fnt_orig {
45044502
fnt_orig[fIdx][0] = isec[fmt.Sprintf("font%v", fIdx)]
45054503
fnt_orig[fIdx][1] = isec[fmt.Sprintf("fnt_height%v", fIdx)]
@@ -4651,15 +4649,6 @@ func (s *Select) AddChar(def string) *SelectChar {
46514649
sc.anims.addSprite(sc.sff, k[0], k[1])
46524650
}
46534651
}
4654-
// read movelist
4655-
if len(movelist_orig) > 0 {
4656-
// Movelist is text, can be loaded now
4657-
LoadFile(&movelist_orig, []string{sc.def, "", "data/"}, "", func(filename string) error {
4658-
sc.movelist, _ = LoadText(filename)
4659-
return nil
4660-
})
4661-
}
4662-
46634652
return sc
46644653
}
46654654

0 commit comments

Comments
 (0)