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 } } }