Compare commits
4 Commits
soldiers-a
...
7677c30572
Author | SHA1 | Date | |
---|---|---|---|
7677c30572 | |||
eac6017c2c | |||
f971ba320c | |||
cf624cc77b |
@@ -139,16 +139,15 @@ func loadMapsFrom(mapsPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Maps in %s:", mapsPath)
|
log.Printf("Maps in %s:", mapsPath)
|
||||||
for key, gameMap := range gameMaps {
|
for key, gm := range gameMaps {
|
||||||
rect := gameMap.Rect()
|
rect := gm.Rect()
|
||||||
hdr := gameMap.Header
|
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
" * `%s`: IsCampaignMap=%v W=%v:%v L=%v:%v SetName=%s\n",
|
" * `%s`: IsCampaignMap=%v W=%v:%v L=%v:%v SetName=%s\n",
|
||||||
key,
|
key,
|
||||||
hdr.IsCampaignMap,
|
gm.IsCampaignMap,
|
||||||
rect.Min.X, rect.Max.X,
|
rect.Min.X, rect.Max.X,
|
||||||
rect.Min.Y, rect.Max.Y,
|
rect.Min.Y, rect.Max.Y,
|
||||||
string(hdr.SetName[:]),
|
string(gm.SetName),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -181,8 +181,8 @@ func (e *env) Draw(screen *ebiten.Image) error {
|
|||||||
|
|
||||||
for y := int(rect.Min.Y); y < int(rect.Max.Y); y++ {
|
for y := int(rect.Min.Y); y < int(rect.Max.Y); y++ {
|
||||||
for x := int(rect.Min.X); x < int(rect.Max.X); x++ {
|
for x := int(rect.Min.X); x < int(rect.Max.X); x++ {
|
||||||
cell := gameMap.Cells.At(x, y, int(e.state.zIdx))
|
cell := gameMap.At(x, y, int(e.state.zIdx))
|
||||||
imd.Set(x, y, makeColour(&cell, e.state.cellIdx))
|
imd.Set(x, y, makeColour(cell, e.state.cellIdx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -598,7 +598,8 @@ Ignoring them for now, here's a first guess at a header:
|
|||||||
| 24 | 2 | ??? - varies. Seems related to character/squad position? |
|
| 24 | 2 | ??? - varies. Seems related to character/squad position? |
|
||||||
| 26 | 2 | ??? - invariant `00 04` |
|
| 26 | 2 | ??? - invariant `00 04` |
|
||||||
| 28 | 4 | ??? - varies (0 vs 5) |
|
| 28 | 4 | ??? - varies (0 vs 5) |
|
||||||
| 32 | 4 | Number of thingies (26 vs 1) |
|
| 32 | 1 | Number of thingies |
|
||||||
|
| 33 | 3 | ???. With a Lord of Change on the map, only one byte works as thingies count |
|
||||||
| 36 | 20 | Padding? |
|
| 36 | 20 | Padding? |
|
||||||
|
|
||||||
56 bytes of data is interesting because the value of that first, ignored byte is
|
56 bytes of data is interesting because the value of that first, ignored byte is
|
||||||
@@ -625,7 +626,79 @@ Generating a map with no characters at all, the trailer is 2,447 bytes, and the
|
|||||||
mission title starts at 0x3B (59). So we can say we have 20 bytes of padding as
|
mission title starts at 0x3B (59). So we can say we have 20 bytes of padding as
|
||||||
a first approximation?
|
a first approximation?
|
||||||
|
|
||||||
The "trailer trailer", for want of a better term, seems to be organised as:
|
Here's where we're at with the per-character data, going from the padding values
|
||||||
|
suggested above:
|
||||||
|
|
||||||
|
| Offset | Size | Meaning |
|
||||||
|
| ------ | ---- | ------- |
|
||||||
|
| 0 | 178 | ??? |
|
||||||
|
| 178 | 1 | Character type |
|
||||||
|
| 179 | 80 | Character name |
|
||||||
|
| 259 | 1 | Weapon Skill |
|
||||||
|
| 260 | 1 | Ballistic Skill |
|
||||||
|
| 261 | 1 | Unknown |
|
||||||
|
| 262 | 1 | Leadership |
|
||||||
|
| 263 | 1 | Toughness |
|
||||||
|
| 264 | 1 | Strength |
|
||||||
|
| 265 | 1 | Action Points |
|
||||||
|
| 266 | 1 | Unknown |
|
||||||
|
| 267 | 1 | Unknown |
|
||||||
|
| 268 | 1 | Health |
|
||||||
|
| 269 | 495 | ??? |
|
||||||
|
| 764 | 1(?) | Squad number? |
|
||||||
|
| 765 | 927 | ??? |
|
||||||
|
|
||||||
|
There's still a lot of bytes to dig through, but this allows me to load the
|
||||||
|
character names from Chapter01 correctly, with the exception of record 57 which
|
||||||
|
just contains `\x02` and is then null-terminated all the way through - but maybe
|
||||||
|
that's just a data thing.
|
||||||
|
|
||||||
|
How about their types? `HasAction.dat` lists numbers for character types, and
|
||||||
|
those show up immediately before the name. going from the character type to the
|
||||||
|
animation group is not yet fully deciphered - captains mess up a direct
|
||||||
|
correlation - but a fixed offset table allows me to draw the characters \o/.
|
||||||
|
Orientation is not yet deciphered, however.
|
||||||
|
|
||||||
|
Given two characters of the same type, just in different locations, differing
|
||||||
|
values are seen at:
|
||||||
|
|
||||||
|
* `0x103 - 0x10c` (hodgepodge)
|
||||||
|
* `0x178 - 0x1be` (hodgepodge)
|
||||||
|
* `0x2fc` (0, 1) - squad number?
|
||||||
|
|
||||||
|
|
||||||
|
I can easily correlate certain bytes in the first range to various character
|
||||||
|
attributes. A few remain unset.
|
||||||
|
|
||||||
|
In Chapter01, picking a random character (Gorgon) and looking at his squadmates,
|
||||||
|
they are all in the same squad, and no other characters are in that squad, so it
|
||||||
|
looks pretty diagnostic to me. There's nothing in the UI to indicate the squad,
|
||||||
|
though.
|
||||||
|
|
||||||
|
Now let's look for position. In my 2-character map, they're at 65,50 and 70,55.
|
||||||
|
Within a character, I see those numbers repeated twice - around `0x1b{9,a}` and
|
||||||
|
`0x1b{d,e}`. This may be some kind of multiple-squares-taken-up thing.
|
||||||
|
|
||||||
|
Adding a (tall) Lord of Change to the map gave me `02 36 45 00 02 37 45`, which
|
||||||
|
doesn't quite match what my eyes are telling me for Z,Y,X. In addition, the data
|
||||||
|
immediately after this offset changed into a large number of coordinate-like
|
||||||
|
sets of values - far too many for it to actually be a bounding box. However, the
|
||||||
|
first one remains good as a position specifier.
|
||||||
|
|
||||||
|
Down in `0x679` (Chaos Sorcerer) or `0x68D` (Lord of Change), the map coords for
|
||||||
|
the *other* character appears, which is downright odd. For now, just use the
|
||||||
|
first-indexed value.
|
||||||
|
|
||||||
|
Thingies next: these aren't decoded at all yet, and the sizes seem to be
|
||||||
|
variable.
|
||||||
|
|
||||||
|
| Offset | Size | Meaning |
|
||||||
|
| ------ | ---- | ------- |
|
||||||
|
| | | |
|
||||||
|
|
||||||
|
|
||||||
|
Finally, the "trailer trailer", for want of a better term, seems to be organised
|
||||||
|
as:
|
||||||
|
|
||||||
| Offset | Size | Meaning |
|
| Offset | Size | Meaning |
|
||||||
| ----- | ---- | ------- |
|
| ----- | ---- | ------- |
|
||||||
@@ -633,6 +706,8 @@ The "trailer trailer", for want of a better term, seems to be organised as:
|
|||||||
| 255 | 2048 | Briefing |
|
| 255 | 2048 | Briefing |
|
||||||
| 2304 | 85 | ??? - each byte is 1 or 0. Spaced so it may be partly uint32 |
|
| 2304 | 85 | ??? - each byte is 1 or 0. Spaced so it may be partly uint32 |
|
||||||
|
|
||||||
|
This duplicates the information found in the `.TXT` files. No idea what the end
|
||||||
|
data is yet.
|
||||||
|
|
||||||
## Soldiers At War
|
## Soldiers At War
|
||||||
|
|
||||||
|
3
go.mod
3
go.mod
@@ -8,7 +8,9 @@ require (
|
|||||||
github.com/hajimehoshi/ebiten v1.11.1
|
github.com/hajimehoshi/ebiten v1.11.1
|
||||||
github.com/jfreymuth/oggvorbis v1.0.1 // indirect
|
github.com/jfreymuth/oggvorbis v1.0.1 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/samuel/go-pcx v0.0.0-20180426214139-d9c017170db4
|
github.com/samuel/go-pcx v0.0.0-20180426214139-d9c017170db4
|
||||||
github.com/stretchr/testify v1.5.1
|
github.com/stretchr/testify v1.5.1
|
||||||
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 // indirect
|
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5 // indirect
|
||||||
@@ -16,4 +18,5 @@ require (
|
|||||||
golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 // indirect
|
golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 // indirect
|
||||||
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
|
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||||
|
gopkg.in/restruct.v1 v1.0.0-20190323193435-3c2afb705f3c
|
||||||
)
|
)
|
||||||
|
6
go.sum
6
go.sum
@@ -40,9 +40,13 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe h1:ewr1srjRCmcQogPQ/NCx6XCk6LGVmsVCc9Y3vvPZj+Y=
|
||||||
|
github.com/lunixbochs/struc v0.0.0-20200521075829-a4cb8d33dbbe/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/samuel/go-pcx v0.0.0-20180426214139-d9c017170db4 h1:Y/KOCu+ZLB730PudefxfsKVjtI0m0RhvFk9a0l4O1+c=
|
github.com/samuel/go-pcx v0.0.0-20180426214139-d9c017170db4 h1:Y/KOCu+ZLB730PudefxfsKVjtI0m0RhvFk9a0l4O1+c=
|
||||||
@@ -107,5 +111,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR
|
|||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/restruct.v1 v1.0.0-20190323193435-3c2afb705f3c h1:7j7Yy/3gedviEts3jKY0bEruQkTFKh+8pDmEFaM6UBc=
|
||||||
|
gopkg.in/restruct.v1 v1.0.0-20190323193435-3c2afb705f3c/go.mod h1:WJaLhyHHEQFOgwIxu/SJxvUHJA18glYsMETBTMIySTY=
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
package assetstore
|
package assetstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.ur.gs/lupine/ordoor/internal/data"
|
||||||
"code.ur.gs/lupine/ordoor/internal/idx"
|
"code.ur.gs/lupine/ordoor/internal/idx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -76,3 +79,50 @@ func (a *AssetStore) Animation(groupIdx, recIdx int) (*Animation, error) {
|
|||||||
|
|
||||||
return &Animation{Frames: sprites}, nil
|
return &Animation{Frames: sprites}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AssetStore) CharacterAnimation(ctype data.CharacterType, action data.AnimAction) (*Animation, error) {
|
||||||
|
ha, err := a.HasAction()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ha.Check(ctype, action) {
|
||||||
|
return nil, fmt.Errorf("character %s: animation %s: not available", ctype, action)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: we still need to be able to go from CTYPE to GROUP. In particular,
|
||||||
|
// squad leaders seem to be a modification on top of a previous group, which
|
||||||
|
// is a bit awkward. For now, hardcode it. How are captain modifiers stored?
|
||||||
|
group, ok := map[data.CharacterType]int{
|
||||||
|
data.CharacterTypeTactical: 1, // Has captain
|
||||||
|
data.CharacterTypeAssault: 3, // Has captain
|
||||||
|
data.CharacterTypeDevastator: 5,
|
||||||
|
data.CharacterTypeTerminator: 6, // Has captain
|
||||||
|
data.CharacterTypeApothecary: 8,
|
||||||
|
data.CharacterTypeTechmarine: 9,
|
||||||
|
data.CharacterTypeChaplain: 10,
|
||||||
|
data.CharacterTypeLibrarian: 11,
|
||||||
|
data.CharacterTypeCaptain: 12,
|
||||||
|
data.CharacterTypeChaosMarine: 13,
|
||||||
|
data.CharacterTypeChaosLord: 14,
|
||||||
|
data.CharacterTypeChaosChaplain: 15,
|
||||||
|
data.CharacterTypeChaosSorcerer: 16,
|
||||||
|
data.CharacterTypeChaosTerminator: 17,
|
||||||
|
data.CharacterTypeKhorneBerserker: 18,
|
||||||
|
data.CharacterTypeBloodThirster: 19, // This is a rotating thing?
|
||||||
|
data.CharacterTypeBloodLetter: 20,
|
||||||
|
data.CharacterTypeFleshHound: 21,
|
||||||
|
data.CharacterTypeLordOfChange: 22, // Another rotating thing?
|
||||||
|
data.CharacterTypeFlamer: 23,
|
||||||
|
data.CharacterTypePinkHorror: 24,
|
||||||
|
data.CharacterTypeBlueHorror: 25,
|
||||||
|
data.CharacterTypeChaosCultist: 26,
|
||||||
|
}[ctype]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("Unknown character type: %s", ctype)
|
||||||
|
}
|
||||||
|
|
||||||
|
rec := ha.Index(ctype, action)
|
||||||
|
|
||||||
|
return a.Animation(group, rec)
|
||||||
|
}
|
||||||
|
@@ -45,6 +45,7 @@ type AssetStore struct {
|
|||||||
cursors map[CursorName]*Cursor
|
cursors map[CursorName]*Cursor
|
||||||
fonts map[string]*Font
|
fonts map[string]*Font
|
||||||
generic *data.Generic
|
generic *data.Generic
|
||||||
|
hasAction *data.HasAction
|
||||||
idx *idx.Idx
|
idx *idx.Idx
|
||||||
images map[string]*ebiten.Image
|
images map[string]*ebiten.Image
|
||||||
maps map[string]*Map
|
maps map[string]*Map
|
||||||
@@ -111,6 +112,8 @@ func (a *AssetStore) Refresh() error {
|
|||||||
a.cursors = make(map[CursorName]*Cursor)
|
a.cursors = make(map[CursorName]*Cursor)
|
||||||
a.entries = newEntryMap
|
a.entries = newEntryMap
|
||||||
a.fonts = make(map[string]*Font)
|
a.fonts = make(map[string]*Font)
|
||||||
|
a.generic = nil
|
||||||
|
a.hasAction = nil
|
||||||
a.idx = nil
|
a.idx = nil
|
||||||
a.images = make(map[string]*ebiten.Image)
|
a.images = make(map[string]*ebiten.Image)
|
||||||
a.maps = make(map[string]*Map)
|
a.maps = make(map[string]*Map)
|
||||||
|
@@ -66,6 +66,26 @@ func (a *AssetStore) DefaultOptions() (*config.Options, error) {
|
|||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AssetStore) HasAction() (*data.HasAction, error) {
|
||||||
|
if a.hasAction != nil {
|
||||||
|
return a.hasAction, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
filename, err := a.lookup("HasAction", "dat", "Data")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
hasAction, err := data.LoadHasAction(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.hasAction = hasAction
|
||||||
|
|
||||||
|
return hasAction, nil
|
||||||
|
}
|
||||||
|
|
||||||
func intToBool(i int) bool {
|
func intToBool(i int) bool {
|
||||||
return i > 0
|
return i > 0
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"code.ur.gs/lupine/ordoor/internal/data"
|
||||||
"code.ur.gs/lupine/ordoor/internal/maps"
|
"code.ur.gs/lupine/ordoor/internal/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ func (a *AssetStore) Map(name string) (*Map, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m := &Map{
|
m := &Map{
|
||||||
Rect: raw.Rect(),
|
Rect: raw.Rect(),
|
||||||
assets: a,
|
assets: a,
|
||||||
raw: raw,
|
raw: raw,
|
||||||
set: set,
|
set: set,
|
||||||
@@ -74,8 +75,8 @@ func (m *Map) LoadSprites() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: get rid of this
|
// FIXME: get rid of this
|
||||||
func (m *Map) Cell(x, y, z int) maps.Cell {
|
func (m *Map) Cell(x, y, z int) *maps.Cell {
|
||||||
return m.raw.Cells.At(x, y, z)
|
return m.raw.At(x, y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpritesForCell returns the sprites needed to correctly render this cell.
|
// SpritesForCell returns the sprites needed to correctly render this cell.
|
||||||
@@ -102,5 +103,17 @@ func (m *Map) SpritesForCell(x, y, z int) ([]*Sprite, error) {
|
|||||||
sprites = append(sprites, sprite)
|
sprites = append(sprites, sprite)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, chr := range m.raw.Characters {
|
||||||
|
if chr.XPos == x && chr.YPos == y && z == 1 { // FIXME: sort out ZPos
|
||||||
|
// Look up the correct animation, get the frame, boom
|
||||||
|
anim, err := m.assets.CharacterAnimation(chr.Type, data.AnimActionNone)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sprites = append(sprites, anim.Frames[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sprites, nil
|
return sprites, nil
|
||||||
}
|
}
|
||||||
|
@@ -94,6 +94,42 @@ type HasAction struct {
|
|||||||
bits bitfield.BitField
|
bits bitfield.BitField
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
cTypes = map[CharacterType]string{
|
||||||
|
CharacterTypeTactical: "Tactical",
|
||||||
|
CharacterTypeAssault: "Assault",
|
||||||
|
CharacterTypeDevastator: "Devastator",
|
||||||
|
CharacterTypeTerminator: "Terminator",
|
||||||
|
CharacterTypeApothecary: "Apothecary",
|
||||||
|
CharacterTypeTechmarine: "Techmarine",
|
||||||
|
CharacterTypeChaplain: "Chaplain",
|
||||||
|
CharacterTypeLibrarian: "Librarian",
|
||||||
|
CharacterTypeCaptain: "Captain",
|
||||||
|
CharacterTypeChaosMarine: "Chaos Marine",
|
||||||
|
CharacterTypeChaosLord: "Chaos Lord",
|
||||||
|
CharacterTypeChaosChaplain: "Chaos Chaplain",
|
||||||
|
CharacterTypeChaosSorcerer: "Chaos Sorcerer",
|
||||||
|
CharacterTypeChaosTerminator: "Chaos Terminator",
|
||||||
|
CharacterTypeKhorneBerserker: "Knorne Berserker",
|
||||||
|
CharacterTypeBloodThirster: "Bloodthirster",
|
||||||
|
CharacterTypeBloodLetter: "Bloodletter",
|
||||||
|
CharacterTypeFleshHound: "Flesh Hound",
|
||||||
|
CharacterTypeLordOfChange: "Lord of Change",
|
||||||
|
CharacterTypeFlamer: "Flamer",
|
||||||
|
CharacterTypePinkHorror: "Pink Horror",
|
||||||
|
CharacterTypeBlueHorror: "Blue Horror",
|
||||||
|
CharacterTypeChaosCultist: "Cultist",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c CharacterType) String() string {
|
||||||
|
if str, ok := cTypes[c]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown Character"
|
||||||
|
}
|
||||||
|
|
||||||
func LoadHasAction(filename string) (*HasAction, error) {
|
func LoadHasAction(filename string) (*HasAction, error) {
|
||||||
scanner, err := asciiscan.New(filename)
|
scanner, err := asciiscan.New(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -161,6 +197,17 @@ func (h *HasAction) Actions(c CharacterType) []AnimAction {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Too slow
|
||||||
|
func (h *HasAction) Index(c CharacterType, requestedAction AnimAction) int {
|
||||||
|
for i, action := range h.Actions(c) {
|
||||||
|
if action == requestedAction {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HasAction) Print() {
|
func (h *HasAction) Print() {
|
||||||
fmt.Println(" Tac Ass Dev Term Apo Tech Chp Lib Cpt CMar CLrd CChp CSrc CTrm Kbz BTh BL FHnd LoC Flm PHr BHr Cult")
|
fmt.Println(" Tac Ass Dev Term Apo Tech Chp Lib Cpt CMar CLrd CChp CSrc CTrm Kbz BTh BL FHnd LoC Flm PHr BHr Cult")
|
||||||
for a := AnimActionStart; a <= AnimActionEnd; a++ {
|
for a := AnimActionStart; a <= AnimActionEnd; a++ {
|
||||||
|
@@ -6,17 +6,19 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/lunixbochs/struc"
|
||||||
|
|
||||||
|
"code.ur.gs/lupine/ordoor/internal/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
expectedMagic = []byte("\x15\x00AMB_MAP\x00")
|
expectedMagic = []byte("\x08\x00WHMAP\x00")
|
||||||
expectedSetNameOffset = uint32(0x10)
|
expectedSetNameOffset = uint32(0x34)
|
||||||
notImplemented = fmt.Errorf("Not implemented")
|
notImplemented = fmt.Errorf("Not implemented")
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,77 +27,135 @@ const (
|
|||||||
MaxLength = 100 // Y coordinate
|
MaxLength = 100 // Y coordinate
|
||||||
MaxWidth = 130 // X coordinate
|
MaxWidth = 130 // X coordinate
|
||||||
|
|
||||||
CellSize = 13 // seems to be
|
CellSize = 16 // seems to be
|
||||||
|
|
||||||
cellDataOffset = 0xc0
|
cellDataOffset = 0x110 // definitely
|
||||||
cellCount = MaxHeight * MaxLength * MaxWidth
|
cellCount = MaxHeight * MaxLength * MaxWidth
|
||||||
)
|
)
|
||||||
|
|
||||||
type Header struct {
|
type GameMap struct {
|
||||||
Magic [10]byte // "\x15\x00AMB_MAP\x00"
|
// Main Header
|
||||||
SetName [8]byte // Links to a filename in `/Sets/*.set`
|
IsCampaignMap bool `struc:"uint32"` // Tentatively: 0 = no, 1 = yes
|
||||||
// Need to investigate the rest of the header too
|
MinWidth int `struc:"uint32"`
|
||||||
IsCampaignMap byte
|
MinLength int `struc:"uint32"`
|
||||||
|
MaxWidth int `struc:"uint32"`
|
||||||
|
MaxLength int `struc:"uint32"`
|
||||||
|
Unknown1 int `struc:"uint32"`
|
||||||
|
Unknown2 int `struc:"uint32"`
|
||||||
|
Unknown3 int `struc:"uint32"`
|
||||||
|
Unknown4 int `struc:"uint32"`
|
||||||
|
Magic []byte `struc:"[8]byte"` // "\x08\x00WHMAP\x00"
|
||||||
|
Unknown5 int `struc:"uint32"`
|
||||||
|
Unknown6 int `struc:"uint32"`
|
||||||
|
SetName string `struc:"[8]byte"` // Links to a filename in `/Sets/*.set`
|
||||||
|
Padding []byte `struc:"[212]byte"`
|
||||||
|
|
||||||
|
// Per-cell data
|
||||||
|
NumCells int `struc:"skip"` // FIXME: We can't use []Cell below without this field
|
||||||
|
Cells []Cell `struc:"[]Cell,sizefrom=NumCells"`
|
||||||
|
|
||||||
|
// Trailer header
|
||||||
|
Discard1 [3]byte `struc:"[3]byte"` // First byte is size of trailer header?
|
||||||
|
|
||||||
|
TrailerMaxWidth int `struc:"uint32"`
|
||||||
|
TrailerMaxLength int `struc:"uint32"`
|
||||||
|
TrailerMinWidth int `struc:"uint32"`
|
||||||
|
TrailerMinLength int `struc:"uint32"`
|
||||||
|
|
||||||
|
NumCharacters int `struc:"uint32"`
|
||||||
|
|
||||||
|
TrailerUnknown1 int `struc:"uint32"`
|
||||||
|
TrailerUnknown2 int `struc:"uint16"`
|
||||||
|
TrailerUnknown3 int `struc:"uint16"`
|
||||||
|
TrailerUnknown4 int `struc:"uint32"`
|
||||||
|
|
||||||
|
NumThingies int `struc:"byte"`
|
||||||
|
TrailerUnknown5 []byte `struc:"[3]byte"`
|
||||||
|
Padding1 []byte `struc:"[20]byte"`
|
||||||
|
|
||||||
|
// FIXME: The rest is trash until Character & Thingy are worked out
|
||||||
|
|
||||||
|
Characters []Character `struc:"[]Character,sizefrom=NumCharacters"`
|
||||||
|
Thingies []Thingy `struc:"[]Thingy,sizefrom=NumThingies"`
|
||||||
|
|
||||||
|
Title string `struc:"[255]byte"`
|
||||||
|
Briefing string `struc:"[2048]byte"`
|
||||||
|
|
||||||
|
// Maybe? each contains either 0 or 1? Hard to say
|
||||||
|
TrailerUnknown6 []byte `struc:"[85]byte"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrailerHeader struct {
|
type Cell struct {
|
||||||
Discard1 [3]byte // No idea what this lot is
|
DoorAndCanisterRelated byte `struc:"byte"`
|
||||||
MaxWidth uint32
|
DoorLockAndReactorRelated byte `struc:"byte"`
|
||||||
MaxLength uint32
|
Unknown2 byte `struc:"byte"`
|
||||||
MinWidth uint32
|
Surface ObjRef
|
||||||
MinLength uint32
|
Left ObjRef
|
||||||
|
Right ObjRef
|
||||||
NumCharacters uint32
|
Center ObjRef
|
||||||
|
Unknown11 byte `struc:"byte"`
|
||||||
Unknown1 uint32
|
Unknown12 byte `struc:"byte"`
|
||||||
Unknown2 uint16
|
Unknown13 byte `struc:"byte"`
|
||||||
Unknown3 uint16
|
Unknown14 byte `struc:"byte"`
|
||||||
Unknown4 uint32
|
SquadRelated byte `struc:"byte"`
|
||||||
NumThingies uint32
|
|
||||||
Padding1 [20]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type TrailerTrailer struct {
|
|
||||||
Title [255]byte
|
|
||||||
Briefing [2048]byte
|
|
||||||
Unknown1 [85]uint8 // Maybe? each contains either 0 or 1? Hard to say
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Character struct {
|
type Character struct {
|
||||||
Unknown1 uint32
|
Unknown1 []byte `struc:"[178]byte"`
|
||||||
|
Type data.CharacterType `struc:"byte"`
|
||||||
|
Name string `struc:"[80]byte"`
|
||||||
|
|
||||||
|
// Attributes guessed by matching up numbers. Starts at 0x103
|
||||||
|
WeaponSkill int `struc:"byte"`
|
||||||
|
BallisticSkill int `struc:"byte"`
|
||||||
|
Unknown2 byte `struc:"byte"`
|
||||||
|
Leadership int `struc:"byte"`
|
||||||
|
Toughness int `struc:"byte"`
|
||||||
|
Strength int `struc:"byte"`
|
||||||
|
ActionPoints int `struc:"byte"`
|
||||||
|
Unknown3 byte `struc:"byte"`
|
||||||
|
Unknown4 byte `struc:"byte"`
|
||||||
|
Health int `struc:"byte"`
|
||||||
|
|
||||||
|
Unknown5 []byte `struc:"[91]byte"`
|
||||||
|
Armor int `struc:"byte"`
|
||||||
|
Unknown6 []byte `struc:"[84]byte"`
|
||||||
|
YPos int `struc:"byte"` // These are actually much more complicated
|
||||||
|
XPos int `struc:"byte"`
|
||||||
|
Unknown7 []byte `struc:"[317]byte"`
|
||||||
|
SquadNumber byte `struc:"byte"`
|
||||||
|
Unknown8 []byte `struc:"[927]byte"`
|
||||||
|
// TODO: each character may have a fixed number of subrecords for inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
type Characters []Character
|
type Characters []Character
|
||||||
|
|
||||||
// TODO. These are triggers/reactors/etc.
|
// TODO. These are triggers/reactors/etc.
|
||||||
type Thingy struct {}
|
type Thingy struct {
|
||||||
|
Unknown1 int `struc:"uint32"`
|
||||||
|
}
|
||||||
|
|
||||||
type Thingies []Thingy
|
type Thingies []Thingy
|
||||||
|
|
||||||
func (h Header) MapSetName() string {
|
func (g *GameMap) MapSetName() string {
|
||||||
idx := bytes.IndexByte(h.SetName[:], 0)
|
return g.SetName
|
||||||
if idx < 0 {
|
|
||||||
idx = 8 // all 8 bytes are used
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(h.SetName[0:idx:idx])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Header) MapSetFilename() string {
|
func (g *GameMap) MapSetFilename() string {
|
||||||
return h.MapSetName() + ".set"
|
return g.MapSetName() + ".set"
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjRef struct {
|
type ObjRef struct {
|
||||||
AreaByte byte
|
AreaByte byte `struc:"byte"`
|
||||||
SpriteAndFlagByte byte
|
SpriteAndFlagByte byte `struc:"byte"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// The index into a set palette to retrieve the object
|
// The index into a set palette to retrieve the object
|
||||||
func (o ObjRef) Index() int {
|
func (o *ObjRef) Index() int {
|
||||||
return int(o.AreaByte & 0x7f)
|
return int(o.AreaByte)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o ObjRef) Sprite() int {
|
func (o *ObjRef) Sprite() int {
|
||||||
// The top bit seems to be a flag of some kind
|
// The top bit seems to be a flag of some kind
|
||||||
return int(o.SpriteAndFlagByte & 0x7f)
|
return int(o.SpriteAndFlagByte & 0x7f)
|
||||||
}
|
}
|
||||||
@@ -103,128 +163,67 @@ func (o ObjRef) Sprite() int {
|
|||||||
// The top bit seems to say whether we should draw or not.
|
// The top bit seems to say whether we should draw or not.
|
||||||
func (o ObjRef) IsActive() bool {
|
func (o ObjRef) IsActive() bool {
|
||||||
return (o.SpriteAndFlagByte & 0x80) == 0x80
|
return (o.SpriteAndFlagByte & 0x80) == 0x80
|
||||||
} // PARIS is 78 x 60 x 7
|
|
||||||
// 4E 3C 7
|
|
||||||
/*
|
|
||||||
type Cell struct {
|
|
||||||
DoorAndCanisterRelated byte
|
|
||||||
// DoorLockAndReactorRelated byte
|
|
||||||
// Unknown2 byte
|
|
||||||
Surface ObjRef
|
|
||||||
Left ObjRef
|
|
||||||
Right ObjRef
|
|
||||||
Center ObjRef
|
|
||||||
Unknown11 byte
|
|
||||||
Unknown12 byte
|
|
||||||
Unknown13 byte
|
|
||||||
Unknown14 byte
|
|
||||||
// SquadRelated byte
|
|
||||||
}*/
|
|
||||||
|
|
||||||
type Cell struct {
|
|
||||||
Unknown1 byte
|
|
||||||
Surface ObjRef
|
|
||||||
Left ObjRef
|
|
||||||
Right ObjRef
|
|
||||||
Center ObjRef
|
|
||||||
Unknown2 [4]byte
|
|
||||||
|
|
||||||
/*
|
|
||||||
DoorAndCanisterRelated byte
|
|
||||||
// DoorLockAndReactorRelated byte
|
|
||||||
// Unknown2 byte
|
|
||||||
Surface ObjRef
|
|
||||||
Left ObjRef
|
|
||||||
Right ObjRef
|
|
||||||
Center ObjRef
|
|
||||||
Unknown11 byte
|
|
||||||
Unknown12 byte
|
|
||||||
Unknown13 byte
|
|
||||||
Unknown14 byte
|
|
||||||
SquadRelated byte*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cell) At(n int) byte {
|
func (c *Cell) At(n int) byte {
|
||||||
switch n {
|
switch n {
|
||||||
case 0:
|
case 0:
|
||||||
return c.Unknown1
|
return c.DoorAndCanisterRelated
|
||||||
case 1:
|
case 1:
|
||||||
return c.Surface.AreaByte
|
return c.DoorLockAndReactorRelated
|
||||||
case 2:
|
case 2:
|
||||||
return c.Surface.SpriteAndFlagByte
|
return c.Unknown2
|
||||||
case 3:
|
case 3:
|
||||||
return c.Left.AreaByte
|
return c.Surface.AreaByte
|
||||||
case 4:
|
case 4:
|
||||||
return c.Left.SpriteAndFlagByte
|
return c.Surface.SpriteAndFlagByte
|
||||||
case 5:
|
case 5:
|
||||||
return c.Right.AreaByte
|
return c.Left.AreaByte
|
||||||
case 6:
|
case 6:
|
||||||
return c.Right.SpriteAndFlagByte
|
return c.Left.SpriteAndFlagByte
|
||||||
case 7:
|
case 7:
|
||||||
return c.Center.AreaByte
|
return c.Right.AreaByte
|
||||||
case 8:
|
case 8:
|
||||||
return c.Center.SpriteAndFlagByte
|
return c.Right.SpriteAndFlagByte
|
||||||
case 9:
|
case 9:
|
||||||
return c.Unknown2[0]
|
return c.Center.AreaByte
|
||||||
case 10:
|
case 10:
|
||||||
return c.Unknown2[1]
|
return c.Center.SpriteAndFlagByte
|
||||||
case 11:
|
case 11:
|
||||||
return c.Unknown2[2]
|
return c.Unknown11
|
||||||
case 12:
|
case 12:
|
||||||
return c.Unknown2[3]
|
return c.Unknown12
|
||||||
|
case 13:
|
||||||
|
return c.Unknown13
|
||||||
|
case 14:
|
||||||
|
return c.Unknown14
|
||||||
|
case 15:
|
||||||
|
return c.SquadRelated
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cells is always a fixed size; use At to get a cell according to x,y,z
|
func (g *GameMap) At(x, y, z int) *Cell {
|
||||||
type Cells []Cell
|
return &g.Cells[(z*MaxLength*MaxWidth)+(y*MaxWidth)+x]
|
||||||
|
|
||||||
// 6 Possibilities for being laid out in memory. Most likely:
|
|
||||||
// XXYYZZ
|
|
||||||
// OR
|
|
||||||
// XYZXYZ
|
|
||||||
|
|
||||||
func (c Cells) At(x, y, z int) Cell {
|
|
||||||
// log.Printf("At (%v,%v,%v)=%v", x, y, z, x*y*z)
|
|
||||||
return c[(z*MaxLength*MaxWidth)+
|
|
||||||
(y*MaxWidth)+
|
|
||||||
x]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Header) Check() []error {
|
func (g *GameMap) Check() error {
|
||||||
var out []error
|
if bytes.Compare(expectedMagic, g.Magic) != 0 {
|
||||||
// if h.IsCampaignMap > 1 {
|
return fmt.Errorf("Unexpected magic value: %v", g.Magic)
|
||||||
// out = append(out, fmt.Errorf("Expected 0 or 1 for IsCampaignMap, got %v", h.IsCampaignMap))
|
|
||||||
// }
|
|
||||||
|
|
||||||
if bytes.Compare(expectedMagic, h.Magic[:]) != 0 {
|
|
||||||
out = append(out, fmt.Errorf("Unexpected magic value: %v", h.Magic))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
// TODO: other consistency checks
|
||||||
}
|
|
||||||
|
|
||||||
type GameMap struct {
|
return nil
|
||||||
Header
|
|
||||||
Cells
|
|
||||||
TrailerHeader
|
|
||||||
Characters
|
|
||||||
Thingies
|
|
||||||
TrailerTrailer
|
|
||||||
|
|
||||||
// TODO: parse this into sections. This is the text that comes from the
|
|
||||||
// .TXT file. Maybe we don't need it at all since it should be duplicated in
|
|
||||||
// the trailer.
|
|
||||||
Text string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *GameMap) Rect() image.Rectangle {
|
func (m *GameMap) Rect() image.Rectangle {
|
||||||
return image.Rect(
|
return image.Rect(
|
||||||
int(m.TrailerHeader.MinWidth),
|
int(m.MinWidth),
|
||||||
int(m.TrailerHeader.MinLength),
|
int(m.MinLength),
|
||||||
int(m.TrailerHeader.MaxWidth-1),
|
int(m.MaxWidth),
|
||||||
int(m.TrailerHeader.MaxLength-1),
|
int(m.MaxLength),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,23 +246,17 @@ func LoadGameMap(prefix string) (*GameMap, error) {
|
|||||||
return nil, fmt.Errorf("Couldn't find %s.{map,txt}, even ignoring case", prefix)
|
return nil, fmt.Errorf("Couldn't find %s.{map,txt}, even ignoring case", prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A game map is composed of two files: .map and .txt
|
// A game map is composed of two files: .map and .txt. We ignore the text file,
|
||||||
|
// since the content is replicated in the map file.
|
||||||
func LoadGameMapByFiles(mapFile, txtFile string) (*GameMap, error) {
|
func LoadGameMapByFiles(mapFile, txtFile string) (*GameMap, error) {
|
||||||
out, err := loadMapFile(mapFile)
|
out, err := loadMapFile(mapFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: load text and parse into sections
|
if err := out.Check(); err != nil {
|
||||||
txt, err := ioutil.ReadFile(txtFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out.Text = string(txt)
|
|
||||||
|
|
||||||
for _, err := range out.Check() {
|
|
||||||
log.Printf("%s: %v", mapFile, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
@@ -301,6 +294,7 @@ func LoadGameMaps(dir string) (map[string]*GameMap, error) {
|
|||||||
|
|
||||||
func loadMapFile(filename string) (*GameMap, error) {
|
func loadMapFile(filename string) (*GameMap, error) {
|
||||||
var out GameMap
|
var out GameMap
|
||||||
|
out.NumCells = cellCount
|
||||||
|
|
||||||
mf, err := os.Open(filename)
|
mf, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -316,57 +310,45 @@ func loadMapFile(filename string) (*GameMap, error) {
|
|||||||
|
|
||||||
defer zr.Close()
|
defer zr.Close()
|
||||||
|
|
||||||
if err := binary.Read(zr, binary.LittleEndian, &out.Header); err != nil {
|
if err := struc.UnpackWithOrder(zr, &out, binary.LittleEndian); err != nil {
|
||||||
return nil, fmt.Errorf("Error parsing %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// no gzip.SeekReader, so discard unread header bytes for now
|
|
||||||
discardSize := int64(cellDataOffset - binary.Size(&out.Header))
|
|
||||||
if _, err := io.CopyN(ioutil.Discard, zr, discardSize); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
out.Cells = make(Cells, cellCount)
|
// Trim any trailing nulls off of the strings
|
||||||
if err := binary.Read(zr, binary.LittleEndian, &out.Cells); err != nil {
|
nullTerminate(&out.SetName)
|
||||||
return nil, fmt.Errorf("Error parsing cells for %s: %v", filename, err)
|
nullTerminate(&out.Title)
|
||||||
|
nullTerminate(&out.Briefing)
|
||||||
|
|
||||||
|
for i, chr := range out.Characters {
|
||||||
|
nullTerminate(&chr.Name)
|
||||||
|
fmt.Printf("Character %v: %s\n", i, chr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// no gzip.SeekReader, so discard unread trailer bytes for now
|
fmt.Printf("Mission Title: %q\n", out.Title)
|
||||||
if _, err := io.CopyN(ioutil.Discard, zr, int64(3320-2)); err != nil { // observed
|
fmt.Printf("Mission Briefing: %q\n", out.Briefing)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := binary.Read(zr, binary.LittleEndian, &out.TrailerHeader); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error parsing trailer header for %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Trailer Header: %#+v", out.TrailerHeader)
|
|
||||||
/*
|
|
||||||
// TODO: until we know how large each character record should be, we can't read this lot
|
|
||||||
|
|
||||||
out.Characters = make(Characters, int(out.TrailerHeader.NumCharacters))
|
|
||||||
if err := binary.Read(zr, binary.LittleEndian, &out.Characters); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error parsing characters for %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
out.Thingies = make(Thingies, int(out.TrailerHeader.NumThingies))
|
|
||||||
if err := binary.Read(zr, binary.LittleEndian, &out.Thingies); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error parsing thingies for %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := binary.Read(zr, binary.LittleEndian, &out.TrailerTrailer); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error parsing trailer trailer for %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
log.Printf("Trailer Trailer: %s", out.TrailerTrailer.String())
|
|
||||||
*/
|
|
||||||
return &out, nil
|
return &out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrailerTrailer) String() string {
|
func nullTerminate(s *string) {
|
||||||
|
sCpy := *s
|
||||||
|
idx := strings.Index(sCpy, "\x00")
|
||||||
|
if idx < 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
*s = sCpy[0:idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Character) String() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"title=%q briefing=%q rest=%#+v",
|
"squad=%v pos=(%v,%v) type=%q name=%q\n"+
|
||||||
strings.TrimRight(string(t.Title[:]), "\x00"),
|
"\t%3d %3d %3d %3d %3d\n\t%3d %3d ??? ??? %3d\n",
|
||||||
strings.TrimRight(string(t.Briefing[:]), "\x00"),
|
c.SquadNumber,
|
||||||
t.Unknown1,
|
c.XPos, c.YPos,
|
||||||
|
c.Type.String(),
|
||||||
|
c.Name,
|
||||||
|
c.ActionPoints, c.Health, c.Armor, c.BallisticSkill, c.WeaponSkill,
|
||||||
|
c.Strength, c.Toughness /*c.Initiative, c.Attacks,*/, c.Leadership,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -51,13 +51,13 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|||||||
sw, sh := screen.Size()
|
sw, sh := screen.Size()
|
||||||
|
|
||||||
topLeft := CartPt{
|
topLeft := CartPt{
|
||||||
X: float64(s.Viewpoint.X) - (2*cellWidth/s.Zoom), // Ensure all visible cells are rendered
|
X: float64(s.Viewpoint.X) - (2 * cellWidth / s.Zoom), // Ensure all visible cells are rendered
|
||||||
Y: float64(s.Viewpoint.Y) - (2*cellHeight/s.Zoom),
|
Y: float64(s.Viewpoint.Y) - (2 * cellHeight / s.Zoom),
|
||||||
}.ToISO()
|
}.ToISO()
|
||||||
|
|
||||||
bottomRight := CartPt{
|
bottomRight := CartPt{
|
||||||
X: float64(s.Viewpoint.X) + (float64(sw)/s.Zoom) + (2*cellHeight/s.Zoom),
|
X: float64(s.Viewpoint.X) + (float64(sw) / s.Zoom) + (2 * cellHeight / s.Zoom),
|
||||||
Y: float64(s.Viewpoint.Y) + (float64(sh)/s.Zoom) + (5*cellHeight/s.Zoom), // Z dimension requires it
|
Y: float64(s.Viewpoint.Y) + (float64(sh) / s.Zoom) + (5 * cellHeight / s.Zoom), // Z dimension requires it
|
||||||
}.ToISO()
|
}.ToISO()
|
||||||
|
|
||||||
// X+Y is constant for all tiles in a column
|
// X+Y is constant for all tiles in a column
|
||||||
@@ -95,17 +95,15 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
counter := map[string]int{}
|
counter := 0
|
||||||
for _, pt := range toDraw {
|
for _, pt := range toDraw {
|
||||||
for z := 0; z <= s.ZIdx; z++ {
|
for z := 0; z <= s.ZIdx; z++ {
|
||||||
if err := s.renderCell(int(pt.X), int(pt.Y), z, screen, counter); err != nil {
|
if err := s.renderCell(int(pt.X), int(pt.Y), z, screen, &counter); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Printf("%#+v", counter)
|
|
||||||
|
|
||||||
// Finally, draw cursor chrome
|
// Finally, draw cursor chrome
|
||||||
// FIXME: it looks like we might need to do this in normal painting order...
|
// FIXME: it looks like we might need to do this in normal painting order...
|
||||||
spr, err := s.specials.Sprite(0)
|
spr, err := s.specials.Sprite(0)
|
||||||
@@ -123,7 +121,7 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|||||||
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
if err := screen.DrawImage(spr.Image, &op); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
x1, y1 := geo.Apply(0, 0)
|
x1, y1 := geo.Apply(0, 0)
|
||||||
ebitenutil.DebugPrintAt(
|
ebitenutil.DebugPrintAt(
|
||||||
screen,
|
screen,
|
||||||
@@ -132,13 +130,15 @@ func (s *Scenario) Draw(screen *ebiten.Image) error {
|
|||||||
int(y1),
|
int(y1),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Sprites: %v", counter), 0, 16)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// debug: draw a square around the selected cell
|
// debug: draw a square around the selected cell
|
||||||
x2, y2 := geo.Apply(cellWidth, cellHeight)
|
x2, y2 := geo.Apply(cellWidth, cellHeight)
|
||||||
ebitenutil.DrawLine(screen, x1, y1, x2, y1, colornames.Green) // top line
|
ebitenutil.DrawLine(screen, x1, y1, x2, y1, colornames.Green) // top line
|
||||||
ebitenutil.DrawLine(screen, x1, y1, x1, y2, colornames.Green) // left line
|
ebitenutil.DrawLine(screen, x1, y1, x1, y2, colornames.Green) // left line
|
||||||
ebitenutil.DrawLine(screen, x2, y1, x2, y2, colornames.Green) // right line
|
ebitenutil.DrawLine(screen, x2, y1, x2, y2, colornames.Green) // right line
|
||||||
ebitenutil.DrawLine(screen, x1, y2, x2, y2, colornames.Green) // bottom line
|
ebitenutil.DrawLine(screen, x1, y2, x2, y2, colornames.Green) // bottom line
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -164,7 +164,7 @@ func (s *Scenario) geoForCoords(x, y, z int) ebiten.GeoM {
|
|||||||
return geo
|
return geo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scenario) renderCell(x, y, z int, screen *ebiten.Image, counter map[string]int) error {
|
func (s *Scenario) renderCell(x, y, z int, screen *ebiten.Image, counter *int) error {
|
||||||
sprites, err := s.area.SpritesForCell(x, y, z)
|
sprites, err := s.area.SpritesForCell(x, y, z)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -179,10 +179,7 @@ func (s *Scenario) renderCell(x, y, z int, screen *ebiten.Image, counter map[str
|
|||||||
iso.Translate(-209, -332)
|
iso.Translate(-209, -332)
|
||||||
|
|
||||||
for _, spr := range sprites {
|
for _, spr := range sprites {
|
||||||
// if _, ok := counter[spr.ID]; !ok {
|
*counter = *counter + 1
|
||||||
// counter[spr.ID] = 0
|
|
||||||
// }
|
|
||||||
// counter[spr.ID] = counter[spr.ID] + 1
|
|
||||||
op := ebiten.DrawImageOptions{GeoM: iso}
|
op := ebiten.DrawImageOptions{GeoM: iso}
|
||||||
|
|
||||||
op.GeoM.Translate(float64(spr.Rect.Min.X), float64(spr.Rect.Min.Y))
|
op.GeoM.Translate(float64(spr.Rect.Min.X), float64(spr.Rect.Min.Y))
|
||||||
|
@@ -9,7 +9,7 @@ type CellPoint struct {
|
|||||||
Z int
|
Z int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scenario) CellAtCursor() (maps.Cell, CellPoint) {
|
func (s *Scenario) CellAtCursor() (*maps.Cell, CellPoint) {
|
||||||
cell := s.area.Cell(int(s.selectedCell.X), int(s.selectedCell.Y), 0)
|
cell := s.area.Cell(int(s.selectedCell.X), int(s.selectedCell.Y), 0)
|
||||||
return cell, CellPoint{IsoPt: s.selectedCell, Z: 0}
|
return cell, CellPoint{IsoPt: s.selectedCell, Z: 0}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user