Category : Files from Magazines
Archive   : ANTHILL.ZIP
Filename : ANTHILL.HPP
// //
// C++ Header file for ANTHILL simulation program //
// //
// Taken from The C Users Journal, October 1990, //
// pgs 53 - 67 //
// //
// //
/////////////////////////////////////////////////////////////////////////
/*
**************************************************************************
*
* Modification Log
**************************************************************************
*
*/
/*** revision history ***/
/* 1 ANTHILL.HPP 2-Oct-90,0:40:10,`ERIK' Initial Code Checkin. */
/* 2 ANTHILL.HPP 10-Oct-90,0:32:02,`ERIK' Added version history. */
/* 3 ANTHILL.HPP 10-Oct-90,1:45:16,`ERIK' Added virtual eatFood and */
/* virtual die. */
/*** revision history ***/
typedef unsigned char BOOLEAN;
#define TRUE 1
#define FALSE 0
#define BACKGROUND 0
#define MAX_FOOD_SIZE 30000
// Type of ants:
enum antType { typeQueen, typeWorker, typeEgg };
// Function prototypes:
void moverDefaultDrawFunc (int, int, BOOLEAN, int);
int distance (int, int, int, int);
void showFood (int, int, BOOLEAN);
void showStatus (void);
void resetDefaults (void);
void displayValues (void);
unsigned getNumber (char *, unsigned, unsigned, unsigned);
char getChoice (void);
/////////////////////////////////////////////////////////////////////////
// //
// MOVER class definition //
// //
/////////////////////////////////////////////////////////////////////////
class Mover
{
private:
void moverDrawFunc (int, int, BOOLEAN, int);
// function to draw object
BOOLEAN bVisible; // is object currently visible on
// screen?
protected:
int nInitX, nInitY; // Original position
int nVelX; // Velocity in X direction
int nVelY; // Velocity in Y direction
unsigned uMaxRange; // Max distance object moves from
// original pos.
unsigned uMaxSpeed; // Max distance object moves in one
// cycle.
int nX, nY; // Current position;
int color; // Color of mover
public:
Mover (unsigned, unsigned, int, int);
BOOLEAN moveTo (int, int);
BOOLEAN move (void);
void show (void);
void erase (void);
void draw (void);
virtual int getX (void) = 0;
virtual int getY (void) = 0;
};
/////////////////////////////////////////////////////////////////////////
// //
// CONSUMER class definition //
// //
/////////////////////////////////////////////////////////////////////////
class Consumer
{
public:
int nEnergy; // If this reaches zero,
// it's curtains!
Consumer (int _nEnergy)
{ nEnergy = _nEnergy; } // inline constructor
virtual void eatFood (int); // Eat food at current location
virtual int getX (void) = 0;
virtual int getY (void) = 0;
};
/////////////////////////////////////////////////////////////////////////
// //
// ANT class definition //
// //
/////////////////////////////////////////////////////////////////////////
class Ant : public Consumer, public Mover
{
protected:
int nLifeSpan; // Age at which ant dies
unsigned nAge; // How old is this ant
BOOLEAN bEgg; // Am I an egg still?
public:
BOOLEAN bDead; // Does this and bDead?
Ant (int, int, int, int, int); // constructor
virtual void die (void); // Assume room temprature
void doTheAntThing (void); // Do whatever ants do
virtual int getX (void) { return Mover::getX (); };
virtual int getY (void) { return Mover::getY (); };
};
/////////////////////////////////////////////////////////////////////////
// //
// QUEEN class definition //
// //
/////////////////////////////////////////////////////////////////////////
class Queen : public Ant // Queen is derived from ant
{
private:
unsigned birthRate;
public:
Queen (unsigned, int, int, int, int, unsigned); // Constructor function
virtual void eatFood (int nUnits);
void layEgg (void); // Queen can lay eggs
void doTheAntThing (void); // Do whatever queen ants do
};
/////////////////////////////////////////////////////////////////////////
// //
// WORKER class definition //
// //
/////////////////////////////////////////////////////////////////////////
class Worker : public Ant // worker is derives from ant
{
private:
Worker *nextWorker; // Pointer to next ant in list
Worker *prevWorker; // Pointer to previous ant in list
int nFood; // Indicates worker carrying food
void dropFood (void); // Drop food for Queen
void grabFood (void); // Pick up food
void moveTowardQueen (void); // Carry food toward Queen
void lookForFood (void); // Search for more food
void addToList (void); // Add self to head of list
void die (void); // Assume room temperature
public:
Worker (BOOLEAN, int, int); // constructor
~Worker (void);
Worker *next (void)
{ return (nextWorker); } // Access function to next ptr
void doTheAntThing (void);
};
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/