Commit a6e93214 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added ships

parent 55423f6d
Loading
Loading
Loading
Loading
+64 −1
Original line number Diff line number Diff line
package engine

import (
	"fmt"
	"io"
)

const (
	VERSION     = "V1.01"
	STARNO      = 16
	TASKNO      = 26
	PLANETNO    = 8
	PLAYERNO    = 4
	UNINHABITED = PLAYERNO + 1
	FIGHTING    = PLAYERNO + 2
	XMAX        = 25
	YMAX        = 25
	SHIPNO      = 27
	INVESTING   = SHIPNO
	RESEARCHING = SHIPNO + 1
	DO_NOTHING  = SHIPNO + 3
	MINING      = SHIPNO + 2
	STRLENGTH   = 20
	MCOST       = 15
	ICOST       = 15
	RCOST       = 10
	MAXSPEED    = 10
	OREUNIT     = 25
	POPUNIT     = 26
	BUFLENGTH   = 50
)

type env struct {
	in  io.Reader
	out io.Writer
	err io.Writer
	g   game
}

type game struct {
	ships []Ship
}

// Conquest is the main entry point for the game.
func Conquest() error {
func Conquest(ci io.Reader, co io.Writer, ce io.Writer) error {
	e := env{
		in:  ci,
		out: co,
		err: ce,
	}
	defer cleanup(e)
	title(e)
	if err := initShips(e); err != nil {
		return err
	}
	return nil
}

func title(e env) {
	fmt.Fprintf(e.out, "************************************************************\n")
	fmt.Fprintf(e.out, "* Cosmic Conquest: Starting...                             *\n")
	fmt.Fprintf(e.out, "************************************************************\n")
}

func cleanup(e env) {
	fmt.Fprintf(e.out, "************************************************************\n")
	fmt.Fprintf(e.out, "* Cosmic Conquest: Terminating...                          *\n")
	fmt.Fprintf(e.out, "************************************************************\n")
}
+7 −6
Original line number Diff line number Diff line
@@ -2,19 +2,20 @@ package engine

// A ship's special abilities.
const (
	Normal = iota << 1 // no special abilities
	StarKiller
	Kamikaze
	NOSPEC = iota << 1 // no special abilities
	STARKILLER
	KAMIKAZE
	Invisible
	FastEjecter
	NotProd
	FASTEJECTER
	NOTPROD
	Steal
	FastEjecable
	FASTEJECTABLE
)

// Ship characteristics.
type Ship struct {
	Name       string
	Size       int
	Capacity   int
	HyperRange int
	HyperSpeed int

cosmic/engine/ships.go

0 → 100644
+386 −0
Original line number Diff line number Diff line
package engine

func initShips(e env) error {
	ships := []Ship{
		{
			"Clearer", /* char name[STRLENGTH];*/
			3,         /*int size;*/
			0,         /*int capacity;*/
			0,         /*int hyprange;*/
			0,         /*int hypspeed;*/
			1,         /*int speed;*/
			1,         /*int attack;*/
			20,        /*int attackno;*/
			4,         /*int shields;*/
			NOSPEC,    /*int special;*/
			100,       /*int techcost;*/
			620,       /*int techlevel;*/
		},
		{
			"UltraStinger", /* char name[STRLENGTH];*/
			1,              /*int size;*/
			0,              /*int capacity;*/
			50,             /*int hyprange;*/
			50,             /*int hypspeed;*/
			3,              /*int speed;*/
			7,              /*int attack;*/
			1,              /*int attackno;*/
			4,              /*int shields;*/
			NOSPEC,         /*int special;*/
			60,             /*int techcost;*/
			800,            /*int techlevel;*/
		},
		{
			"Stinger",     /* char name[STRLENGTH];*/
			1,             /*int size;*/
			0,             /*int capacity;*/
			0,             /*int hyprange;*/
			0,             /*int hypspeed;*/
			3,             /*int speed;*/
			7,             /*int attack;*/
			1,             /*int attackno;*/
			2,             /*int shields;*/
			FASTEJECTABLE, /*int special;*/
			25,            /*int techcost;*/
			150,           /*int techlevel;*/
		},
		{
			"Light Cruiser", /* char name[STRLENGTH];*/
			5,               /*int size;*/
			0,               /*int capacity;*/
			6,               /*int hyprange;*/
			1,               /*int hypspeed;*/
			5,               /*int speed;*/
			10,              /*int attack;*/
			1,               /*int attackno;*/
			10,              /*int shields;*/
			NOSPEC,          /*int special;*/
			100,             /*int techcost;*/
			100,             /*int techlevel;*/
		},
		{
			"Space Cannon", /* char name[STRLENGTH];*/
			10,             /*int size;*/
			0,              /*int capacity;*/
			0,              /*int hyprange;*/
			0,              /*int hypspeed;*/
			4,              /*int speed;*/
			40,             /*int attack;*/
			1,              /*int attackno;*/
			0,              /*int shields;*/
			NOSPEC,         /*int special;*/
			120,            /*int techcost;*/
			550,            /*int techlevel;*/
		},
		{
			"Destroyer", /* char name[STRLENGTH];*/
			12,          /*int size;*/
			0,           /*int capacity;*/
			9,           /*int hyprange;*/
			2,           /*int hypspeed;*/
			6,           /*int speed;*/
			18,          /*int attack;*/
			1,           /*int attackno;*/
			10,          /*int shields;*/
			NOSPEC,      /*int special;*/
			110,         /*int techcost;*/
			310,         /*int techlevel;*/
		},
		{
			"Battleship", /* char name[STRLENGTH];*/
			25,           /*int size;*/
			3,            /*int capacity;*/
			8,            /*int hyprange;*/
			2,            /*int hypspeed;*/
			6,            /*int speed;*/
			15,           /*int attack;*/
			3,            /*int attackno;*/
			18,           /*int shields;*/
			FASTEJECTER,  /*int special;*/
			150,          /*int techcost;*/
			450,          /*int techlevel;*/
		},
		{
			"Battlestar", /* char name[STRLENGTH];*/
			950,          /*int size;*/
			100,          /*int capacity;*/
			9,            /*int hyprange;*/
			1,            /*int hypspeed;*/
			8,            /*int speed;*/
			30,           /*int attack;*/
			15,           /*int attackno;*/
			40,           /*int shields;*/
			FASTEJECTER,  /*int special;*/
			900,          /*int techcost;*/
			950,          /*int techlevel;*/
		},
		{
			"HeavyCruiser", /* char name[STRLENGTH];*/
			8,              /*int size;*/
			0,              /*int capacity;*/
			8,              /*int hyprange;*/
			1,              /*int hypspeed;*/
			7,              /*int speed;*/
			15,             /*int attack;*/
			1,              /*int attackno;*/
			14,             /*int shields;*/
			NOSPEC,         /*int special;*/
			120,            /*int techcost;*/
			220,            /*int techlevel;*/
		},
		{
			"Mothership", /* char name[STRLENGTH];*/
			100,          /*int size;*/
			20,           /*int capacity;*/
			11,           /*int hyprange;*/
			1,            /*int hypspeed;*/
			6,            /*int speed;*/
			12,           /*int attack;*/
			2,            /*int attackno;*/
			24,           /*int shields;*/
			NOSPEC,       /*int special;*/
			230,          /*int techcost;*/
			620,          /*int techlevel;*/
		},
		{
			"Satellite", /* char name[STRLENGTH];*/
			2000,        /*int size;*/
			0,           /*int capacity;*/
			0,           /*int hyprange;*/
			0,           /*int hypspeed;*/
			9,           /*int speed;*/
			12,          /*int attack;*/
			1,           /*int attackno;*/
			6,           /*int shields;*/
			NOSPEC,      /*int special;*/
			20,          /*int techcost;*/
			660,         /*int techlevel;*/
		},
		{
			"Trans III", /* char name[STRLENGTH];*/
			20,          /*int size;*/
			8,           /*int capacity;*/
			9,           /*int hyprange;*/
			2,           /*int hypspeed;*/
			10,          /*int speed;*/
			0,           /*int attack;*/
			0,           /*int attackno;*/
			6,           /*int shields;*/
			NOSPEC,      /*int special;*/
			100,         /*int techcost;*/
			360,         /*int techlevel;*/
		},
		{
			"UltraTrans", /* char name[STRLENGTH];*/
			40,           /*int size;*/
			30,           /*int capacity;*/
			50,           /*int hyprange;*/
			4,            /*int hypspeed;*/
			10,           /*int speed;*/
			0,            /*int attack;*/
			0,            /*int attackno;*/
			8,            /*int shields;*/
			NOSPEC,       /*int special;*/
			160,          /*int techcost;*/
			900,          /*int techlevel;*/
		},
		{
			"Glitter", /* char name[STRLENGTH];*/
			20,        /*int size;*/
			19,        /*int capacity;*/
			0,         /*int hyprange;*/
			0,         /*int hypspeed;*/
			10,        /*int speed;*/
			0,         /*int attack;*/
			0,         /*int attackno;*/
			0,         /*int shields;*/
			NOSPEC,    /*int special;*/
			10,        /*int techcost;*/
			420,       /*int techlevel;*/
		},
		{
			"Scout", /* char name[STRLENGTH];*/
			2,       /*int size;*/
			0,       /*int capacity;*/
			11,      /*int hyprange;*/
			3,       /*int hypspeed;*/
			10,      /*int speed;*/
			0,       /*int attack;*/
			0,       /*int attackno;*/
			6,       /*int shields;*/
			NOSPEC,  /*int special;*/
			50,      /*int techcost;*/
			180,     /*int techlevel;*/
		},
		{
			"Transporter", /* char name[STRLENGTH];*/
			10,            /*int size;*/
			4,             /*int capacity;*/
			4,             /*int hyprange;*/
			1,             /*int hypspeed;*/
			10,            /*int speed;*/
			0,             /*int attack;*/
			0,             /*int attackno;*/
			6,             /*int shields;*/
			NOSPEC,        /*int special;*/
			40,            /*int techcost;*/
			50,            /*int techlevel;*/
		},
		{
			"Spy Sat", /* char name[STRLENGTH];*/
			1,         /*int size;*/
			0,         /*int capacity;*/
			9,         /*int hyprange;*/
			1,         /*int hypspeed;*/
			10,        /*int speed;*/
			0,         /*int attack;*/
			0,         /*int attackno;*/
			70,        /*int shields;*/
			NOSPEC,    /*int special;*/
			280,       /*int techcost;*/
			750,       /*int techlevel;*/
		},
		{
			"Torpedo",                /* char name[STRLENGTH];*/
			1,                        /*int size;*/
			0,                        /*int capacity;*/
			0,                        /*int hyprange;*/
			0,                        /*int hypspeed;*/
			1,                        /*int speed;*/
			25,                       /*int attack;*/
			1,                        /*int attackno;*/
			0,                        /*int shields;*/
			KAMIKAZE | FASTEJECTABLE, /*int special;*/
			15,                       /*int techcost;*/
			240,                      /*int techlevel;*/
		},
		{
			"Pirate", /* char name[STRLENGTH];*/
			10,       /*int size;*/
			3,        /*int capacity;*/
			9,        /*int hyprange;*/
			2,        /*int hypspeed;*/
			5,        /*int speed;*/
			6,        /*int attack;*/
			3,        /*int attackno;*/
			14,       /*int shields;*/
			NOSPEC,   /*int special;*/
			180,      /*int techcost;*/
			370,      /*int techlevel;*/
		},
		{
			"Carrier",   /* char name[STRLENGTH];*/
			30,          /*int size;*/
			5,           /*int capacity;*/
			7,           /*int hyprange;*/
			1,           /*int hypspeed;*/
			10,          /*int speed;*/
			0,           /*int attack;*/
			0,           /*int attackno;*/
			28,          /*int shields;*/
			FASTEJECTER, /*int special;*/
			100,         /*int techcost;*/
			430,         /*int techlevel;*/
		},
		{
			"Q-Bomb",   /* char name[STRLENGTH];*/
			30,         /*int size;*/
			0,          /*int capacity;*/
			0,          /*int hyprange;*/
			0,          /*int hypspeed;*/
			0,          /*int speed;*/
			0,          /*int attack;*/
			0,          /*int attackno;*/
			0,          /*int shields;*/
			STARKILLER, /*int special;*/
			350,        /*int techcost;*/
			950,        /*int techlevel;*/
		},
		{
			"Trans II", /* char name[STRLENGTH];*/
			10,         /*int size;*/
			4,          /*int capacity;*/
			9,          /*int hyprange;*/
			1,          /*int hypspeed;*/
			0,          /*int speed;*/
			0,          /*int attack;*/
			0,          /*int attackno;*/
			6,          /*int shields;*/
			NOSPEC,     /*int special;*/
			70,         /*int techcost;*/
			210,        /*int techlevel;*/
		},
		{
			"",      /* char name[STRLENGTH];*/
			1,       /*int size;*/
			0,       /*int capacity;*/
			0,       /*int hyprange;*/
			0,       /*int hypspeed;*/
			0,       /*int speed;*/
			0,       /*int attack;*/
			0,       /*int attackno;*/
			0,       /*int shields;*/
			NOTPROD, /*int special;*/
			1000,    /*int techcost;*/
			1000,    /*int techlevel;*/
		},
		{
			"",      /* char name[STRLENGTH];*/
			1,       /*int size;*/
			0,       /*int capacity;*/
			0,       /*int hyprange;*/
			0,       /*int hypspeed;*/
			0,       /*int speed;*/
			0,       /*int attack;*/
			0,       /*int attackno;*/
			0,       /*int shields;*/
			NOTPROD, /*int special;*/
			1000,    /*int techcost;*/
			1000,    /*int techlevel;*/
		},
		{
			"",      /* char name[STRLENGTH];*/
			1,       /*int size;*/
			0,       /*int capacity;*/
			0,       /*int hyprange;*/
			0,       /*int hypspeed;*/
			0,       /*int speed;*/
			0,       /*int attack;*/
			0,       /*int attackno;*/
			0,       /*int shields;*/
			NOTPROD, /*int special;*/
			1000,    /*int techcost;*/
			1000,    /*int techlevel;*/
		},
		{
			"Ore Unit", /* char name[STRLENGTH];*/
			1,          /*int size;*/
			0,          /*int capacity;*/
			0,          /*int hyprange;*/
			0,          /*int hypspeed;*/
			10,         /*int speed;*/
			0,          /*int attack;*/
			0,          /*int attackno;*/
			0,          /*int shields;*/
			NOTPROD,    /*int special;*/
			MCOST,      /*int techcost;*/
			0,          /*int techlevel;*/
		},
		{
			"Pop Unit", /* char name[STRLENGTH];*/
			1,          /*int size;*/
			0,          /*int capacity;*/
			0,          /*int hyprange;*/
			0,          /*int hypspeed;*/
			10,         /*int speed;*/
			0,          /*int attack;*/
			0,          /*int attackno;*/
			0,          /*int shields;*/
			NOTPROD,    /*int special;*/
			20,         /*int techcost;*/
			0,          /*int techlevel;*/
		},
	}
	e.g.ships = ships
	return nil
}
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ import (

func main() {
	mainDebug()
	cosmic.Conquest()
	cosmic.Conquest(os.Stdin, os.Stdout, os.Stderr)
}

func mainDebug() {