Skip to content
This repository has been archived by the owner on Jan 13, 2018. It is now read-only.

Commit

Permalink
Reorganised codebase to split out item types
Browse files Browse the repository at this point in the history
  • Loading branch information
iand committed May 20, 2012
1 parent 615cf0c commit e94df30
Show file tree
Hide file tree
Showing 9 changed files with 614 additions and 566 deletions.
111 changes: 111 additions & 0 deletions amberfellcondenser.go
@@ -0,0 +1,111 @@
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main

type AmberfellCondenser struct {
pos Vectori
firewood uint16
amberfell uint16
crystals uint16
timeRemaining float64
}

func NewAmberfellCondenser(pos Vectori) *AmberfellCondenser {
ac := AmberfellCondenser{pos: pos}
return &ac
}

func (self *AmberfellCondenser) Update(dt float64) (completed bool) {
if self.timeRemaining > 0 {
self.timeRemaining -= 1 * dt
if self.timeRemaining <= 0 {
self.crystals++
}
}

if self.timeRemaining <= 0 {
if self.amberfell > 20 && self.firewood > 5 {
self.amberfell -= 20
self.firewood -= 5
self.timeRemaining = 120
} else {
self.timeRemaining = 0
}
}
return false
}

func (self *AmberfellCondenser) Label() string {
if self.timeRemaining > 0 {
return "Amberfell Condenser (active)"
}

return "Amberfell Condenser (inactive)"
}

func (self *AmberfellCondenser) Slots() int {
return 3
}

func (self *AmberfellCondenser) Item(slot int) ItemQuantity {
if slot == 0 && self.firewood > 0 {
return ItemQuantity{ITEM_FIREWOOD, self.firewood}
} else if slot == 1 && self.amberfell > 0 {
return ItemQuantity{ITEM_AMBERFELL, self.amberfell}
} else if slot == 2 && self.crystals > 0 {
return ItemQuantity{ITEM_AMBERFELL_CRYSTAL, self.crystals}
}

return ItemQuantity{}
}

func (self *AmberfellCondenser) Take(slot int, quantity uint16) {
switch slot {
case 0:
self.firewood -= quantity
if self.firewood < 0 {
self.firewood = 0
}
case 1:
self.amberfell -= quantity
if self.amberfell < 0 {
self.amberfell = 0
}
case 2:
self.crystals -= quantity
if self.crystals < 0 {
self.crystals = 0
}
}
}

func (self *AmberfellCondenser) Place(slot int, iq *ItemQuantity) {
if (slot == 0 && self.firewood != 0 && iq.item != ITEM_FIREWOOD) ||
(slot == 1 && self.amberfell != 0 && iq.item != ITEM_AMBERFELL) ||
(slot == 2 && self.crystals != 0 && iq.item != ITEM_AMBERFELL_CRYSTAL) {
return
}

switch iq.item {
case ITEM_FIREWOOD:
self.firewood += iq.quantity
case ITEM_AMBERFELL:
self.amberfell += iq.quantity
case ITEM_AMBERFELL_CRYSTAL:
self.crystals += iq.quantity
}
}

func (self *AmberfellCondenser) CanTake() bool {
return true
}

func (self *AmberfellCondenser) CanPlace(itemid uint16) bool {
if itemid == ITEM_FIREWOOD || itemid == ITEM_AMBERFELL || itemid == ITEM_AMBERFELL_CRYSTAL {
return true
}
return false
}
99 changes: 99 additions & 0 deletions amberfellpump.go
@@ -0,0 +1,99 @@
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main

type AmberfellPump struct {
pos Vectori
sourced bool
unitsPerSecond float64
unitsHeld float64
}

func NewAmberfellPump(pos Vectori, sourced bool, powered bool) *AmberfellPump {
pump := AmberfellPump{pos: pos, sourced: sourced}
return &pump
}

func (self *AmberfellPump) Update(dt float64) (completed bool) {
if self.sourced {
self.unitsPerSecond = AMBERFELL_UNITS_PER_SECOND_UNPOWERED
for face := 0; face < 6; face++ {
npos := Vectori{self.pos[XAXIS], self.pos[YAXIS], self.pos[ZAXIS]}
switch face {
case NORTH_FACE:
npos[ZAXIS]--
case SOUTH_FACE:
npos[ZAXIS]++
case EAST_FACE:
npos[XAXIS]++
case WEST_FACE:
npos[XAXIS]--
case UP_FACE:
npos[YAXIS]++
case DOWN_FACE:
npos[YAXIS]--
}

if gen, ok := TheWorld.generatorObjects[npos]; ok && gen.Active() {
self.unitsPerSecond = AMBERFELL_UNITS_PER_SECOND_POWERED
break
}
}

self.unitsHeld += self.unitsPerSecond * dt
if self.unitsHeld > AMBERFELL_PUMP_CAPACITY {
self.unitsHeld = AMBERFELL_PUMP_CAPACITY
}
}

return false
}

func (self *AmberfellPump) Label() string {
if self.sourced {
if self.unitsPerSecond == AMBERFELL_UNITS_PER_SECOND_POWERED {
return "Amberfell Pump (powered)"
} else {
return "Amberfell Pump (unpowered)"

}
}

return "Amberfell Pump (inactive)"
}

func (self *AmberfellPump) Slots() int {
return 1
}

func (self *AmberfellPump) Item(slot int) ItemQuantity {
if slot == 0 && self.unitsHeld >= 1 {
return ItemQuantity{ITEM_AMBERFELL, uint16(self.unitsHeld)}
}

return ItemQuantity{}
}
func (self *AmberfellPump) Take(slot int, quantity uint16) {
if slot == 0 {
self.unitsHeld -= float64(quantity)
}

if self.unitsHeld < 0 {
self.unitsHeld = 0
}
}

func (self *AmberfellPump) Place(slot int, iq *ItemQuantity) {
// NOOP
}

func (self *AmberfellPump) CanTake() bool {
return true
}

func (self *AmberfellPump) CanPlace(itemid uint16) bool {
return false
}
62 changes: 62 additions & 0 deletions beesnest.go
@@ -0,0 +1,62 @@
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main

type BeesNest struct {
pos Vectori
unitsHeld float64
}

func NewBeesNest(pos Vectori) *BeesNest {
nest := BeesNest{pos: pos}
return &nest
}

func (self *BeesNest) Update(dt float64) (completed bool) {
self.unitsHeld += BEESNEST_UNITS_PER_SECOND * dt
if self.unitsHeld > BEESNEST_CAPACITY {
self.unitsHeld = BEESNEST_CAPACITY
}

return false
}

func (self *BeesNest) Label() string {
return items[BLOCK_BEESNEST].name
}

func (self *BeesNest) Slots() int {
return 1
}

func (self *BeesNest) Item(slot int) ItemQuantity {
if slot == 0 && self.unitsHeld >= 1 {
return ItemQuantity{ITEM_BEESWAX, uint16(self.unitsHeld)}
}

return ItemQuantity{}
}
func (self *BeesNest) Take(slot int, quantity uint16) {
if slot == 0 {
self.unitsHeld -= float64(quantity)
}

if self.unitsHeld < 0 {
self.unitsHeld = 0
}
}

func (self *BeesNest) Place(slot int, iq *ItemQuantity) {
// NOOP
}

func (self *BeesNest) CanTake() bool {
return true
}

func (self *BeesNest) CanPlace(itemid uint16) bool {
return false
}
44 changes: 44 additions & 0 deletions campfire.go
@@ -0,0 +1,44 @@
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main

type CampFire struct {
pos Vectori
life float64
}

func NewCampFire(pos Vectori) *CampFire {
return &CampFire{pos: pos, life: CAMPFIRE_DURATION}
}

func (self *CampFire) Intensity() uint16 {
return CAMPFIRE_INTENSITY
}

func (self *CampFire) Update(dt float64) (completed bool) {
completed = false
self.life -= 0.02 * dt
if self.life <= 0 {
TheWorld.Setv(self.pos, BLOCK_AIR)
delete(TheWorld.lightSources, self.pos)
TheWorld.InvalidateRadius(self.pos[XAXIS], self.pos[ZAXIS], CAMPFIRE_INTENSITY)
completed = true
}

return completed
}

func (self *CampFire) TargetType() uint8 {
return TARGET_CAMPFIRE
}

func (self *CampFire) Position() Vectorf {
return self.pos.Vectorf()
}

func (self *CampFire) Velocity() Vectorf {
return Vectorf{}
}
23 changes: 23 additions & 0 deletions carpentersbench.go
@@ -0,0 +1,23 @@
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main

type CarpentersBench struct {
pos Vectori
}

func NewCarpentersBench(pos Vectori) *CarpentersBench {
obj := CarpentersBench{pos: pos}
return &obj
}

func (self *CarpentersBench) Label() string {
return "Carpenter's Bench"
}

func (self *CarpentersBench) Recipes() []Recipe {
return carpenterRecipes
}
23 changes: 23 additions & 0 deletions forge.go
@@ -0,0 +1,23 @@
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main

type Forge struct {
pos Vectori
}

func NewForge(pos Vectori) *Forge {
obj := Forge{pos: pos}
return &obj
}

func (self *Forge) Label() string {
return "Forge"
}

func (self *Forge) Recipes() []Recipe {
return forgeRecipes
}

0 comments on commit e94df30

Please sign in to comment.