// -*- c++ -*-
#ifndef _RIVERS_H
#define _RIVERS_H

#include "coord.h"

class MsgQ;

class Rivers
{
public:
  Rivers(int NumRivers, int RiverLength, World *pworld);
  Rivers(World *pworld); // get from save file
  Rivers(MsgQ *, World *pworld); // get from socket
  ~Rivers();
  
  void Save();
  
  void DrawRiver(WDisplay *window, MapCoord c);

  void Send(MsgQ *); // send over the socket

private:

  class RiverInfo {
  public:
    RiverInfo() { NumPts = 0; riverId = 0; }

    int NumPts;
    int riverId;
    int pts[3];
  };

  World *world;
  RiverInfo *riverInfo; // used only to create the rivers
  int riverId; // used only to create the rivers

  RiverInfo &Get(MapCoord c) { return riverInfo[c.y*world->MaxX()+c.x]; }

  char *riverMap;

  void RiverEnd(MapCoord &coord, int &dir);

  // returns 1 if ok
  // returns 2 if can't go any further
  // returns 3 if will hit another river on the move
  int PickNewDir(MapCoord coord, int fromdir, MapCoord &coord1, int &dir);

  void AddPiece(MapCoord coord, int fromdir, int todir);

  void NewRiver(int riverLength);

  void ConvDir(MapCoord coord, int dir, MapCoord &coord1);
};

#endif
