Module sneak.berlin/go/rogue, package game: - types.go: all rogue.h constants, flag types, Coord/Stats/Room/ObjInfo - creature.go/object.go: the THING union split into Creature (Player/ Monster) and Object; slices replace the C linked lists - level.go: Place map with the C column-major layout and chat/flat/moat/ winat access methods - tables.go: extern.c + init.c data (bestiary, item tables, name pools) - rng.go: the exact C LCG (seed*11109+13849), golden-tested against a compiled C reference for seed compatibility - init.go: per-game item appearance randomization (init.c) - daemon.go/daemons.go: scheduler with DaemonID replacing function pointers (ids match the C save format's mapping) - game.go: RogueGame holds all former globals; NewGame constructor
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package game
|
|
|
|
// Object is the _o arm of the C THING union: anything that can lie on the
|
|
// floor or ride in a pack.
|
|
type Object struct {
|
|
Type byte // what kind of object it is (Potion, Scroll, Weapon, ...)
|
|
Pos Coord // where it lives on the screen
|
|
Text string // what it says if you read it
|
|
Launch int // what you need to launch it (weapon index, -1 none)
|
|
PackCh byte // what character it is in the pack
|
|
Damage string // damage if used like sword
|
|
HurlDmg string // damage if thrown
|
|
Count int // count for plural objects
|
|
Which int // which object of a type it is
|
|
HPlus int // plusses to hit
|
|
DPlus int // plusses to damage
|
|
Arm int // armor protection — overloaded as in C (see Charges/GoldVal)
|
|
Flags ObjFlags
|
|
Group int // group number for this object
|
|
Label string // label for object
|
|
}
|
|
|
|
// newObject is list.c new_item() for objects: a zeroed Object with the
|
|
// same non-zero defaults the C code relies on.
|
|
func newObject() *Object {
|
|
return &Object{Launch: -1}
|
|
}
|
|
|
|
// Charges is the o_charges alias for Arm on wands and staffs.
|
|
func (o *Object) Charges() int { return o.Arm }
|
|
|
|
// SetCharges stores a charge count in the overloaded Arm field.
|
|
func (o *Object) SetCharges(n int) { o.Arm = n }
|
|
|
|
// GoldVal is the o_goldval alias for Arm on gold piles.
|
|
func (o *Object) GoldVal() int { return o.Arm }
|
|
|
|
// SetGoldVal stores a gold value in the overloaded Arm field.
|
|
func (o *Object) SetGoldVal(n int) { o.Arm = n }
|
|
|
|
// attachObj is list.c attach(): push item onto the front of a list.
|
|
func attachObj(list *[]*Object, item *Object) {
|
|
*list = append([]*Object{item}, *list...)
|
|
}
|
|
|
|
// detachObj is list.c detach(): remove item (by identity) from a list.
|
|
func detachObj(list *[]*Object, item *Object) {
|
|
for i, o := range *list {
|
|
if o == item {
|
|
*list = append((*list)[:i], (*list)[i+1:]...)
|
|
return
|
|
}
|
|
}
|
|
}
|