// -*- c++ -*-
//
// Action procedures
//

void leftButton(Widget /*w*/, XEvent* ev, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(MOUSE_LEFT, ev->xbutton.x, ev->xbutton.y, NULL);
}

void rightButton(Widget /*w*/, XEvent* ev, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(MOUSE_RIGHT, ev->xbutton.x, ev->xbutton.y, NULL);
}

void enter(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, '\r', 0, NULL);
}

////////////////////////////////////////

void moveUpLeft(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_UPLEFT, 0, NULL);
}

void moveUp(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_UP, 0, NULL);
}

void moveUpRight(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_UPRIGHT, 0, NULL);
}

void moveLeft(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_LEFT, 0, NULL);
}

void moveRight(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_RIGHT, 0, NULL);
}

void moveDownLeft(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_DOWNLEFT, 0, NULL);
}

void moveDown(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_DOWN, 0, NULL);
}

void moveDownRight(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, KEY_DOWNRIGHT, 0, NULL);
}

/////////////////////////////////////////

void nextUnit(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'n', 0, NULL);
}

void accept(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'a', 0, NULL);
}

void save(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'S', 0, NULL);
}

void unitDisband(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'd', 0, NULL);
}

void unitFortify(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'f', 0, NULL);
}

void unitSleep(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 's', 0, NULL);
}

void unitDoNothing(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, ' ', 0, NULL);
}

void settlerBuildCity(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'b', 0, NULL);
}

void settlerIrrigate(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'i', 0, NULL);
}

void settlerMine(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'm', 0, NULL);
}

void settlerCleanPollution(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'p', 0, NULL);
}

void settlerBuildRoad(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'r', 0, NULL);
}

void cityBuySkill(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'b', 0, NULL);
}

void cityChangeSkill(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'c', 0, NULL);
}

void cityGovernmentChange(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'g', 0, NULL);
}

void citySetLuxuriesRate(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'l', 0, NULL);
}

void citySetTaxRate(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 't', 0, NULL);
}

void cityBackToMap(Widget /*w*/, XEvent* /*ev*/, String* /*param*/, Cardinal* /*num*/)
{
  (*screen).keyPressed(KEYBOARD, 'm', 0, NULL);
}

//
// Action table
//
static XtActionsRec actionTable[] =
{
  // FIXME: fix handling of these events
  {"leftButton", leftButton},
  {"rightButton", rightButton},
  {"enter", enter},

  {"moveUpLeft", moveUpLeft},
  {"moveUp", moveUp},
  {"moveUpRight", moveUpRight},
  {"moveLeft", moveLeft},
  {"moveRight", moveRight},
  {"moveDownLeft", moveDownLeft},
  {"moveDown", moveDown},
  {"moveDownRight", moveDownRight},
  
  {"accept", accept},
  {"save", save},

  {"nextUnit", nextUnit},
  {"unitDisband", unitDisband},
  {"unitFortify", unitFortify},
  {"unitSleep", unitSleep},
  {"unitDoNothing", unitDoNothing},
  {"settlerBuildCity", settlerBuildCity},
  {"settlerIrrigate", settlerIrrigate},
  {"settlerMine", settlerMine},
  {"settlerCleanPollution", settlerCleanPollution},
  {"settlerBuildRoad", settlerBuildRoad},

  {"cityBuySkill", cityBuySkill},
  {"cityChangeSkill", cityChangeSkill},
  {"cityGovernmentChange", cityGovernmentChange},
  {"citySetLuxuriesRate", citySetLuxuriesRate},
  {"citySetTaxRate", citySetTaxRate},
  {"cityBackToMap", cityBackToMap},
};
