ctrl.h (6015B)
1 /* ctrl.h - maquina de estados de la interaccion, comun a TUI, GUI y PicoCalc. 2 * 3 * El frontend le pasa teclas abstractas (o clicks ya resueltos a vertice/arista/ 4 * hex/item) y ctrl devuelve movidas listas para mandar a la autoridad. El 5 * frontend dibuja a partir de Game + Ctrl. */ 6 #ifndef CTRL_H 7 #define CTRL_H 8 9 #include "catan.h" 10 #include "input.h" 11 12 enum CtrlMode { CM_IDLE, CM_VERT, CM_EDGE, CM_HEX, CM_MENU, CM_CARDS, CM_HANDOFF, CM_OVER }; 13 14 enum Intent { 15 I_NONE, I_SETUP_S, I_SETUP_R, I_SETTLE, I_ROAD, I_CITY, I_FREE_ROAD, I_NEUTRAL, 16 I_ROBBER, I_VICTIM, I_DISCARD, I_GIVEBACK, I_ACTIONS, I_DEV, I_PLENTY, I_MONO, 17 I_BANK_GIVE, I_BANK_GET, I_OFFER, I_RESPOND, I_OFFER_TO, I_CONFIRM_END, I_COUNTER, I_SETUP_OK, 18 I_ROBBER_OK, /* confirmar adonde va el ladron (y a quien roba) antes de que robe */ 19 I_SHIP, I_MOVESHIP_FROM, I_MOVESHIP_TO, I_GOLD 20 }; 21 22 enum Action { 23 A_ROLL, A_KNIGHT, A_ROAD, A_SETTLE, A_CITY, A_BUYDEV, A_DEV, A_BANK, A_OFFER, 24 A_CONFIRM, A_CANCEL, A_TOKTRADE, A_TOKROBBER, A_UNDO, A_END, A_SHIP, A_MOVESHIP, A__COUNT 25 }; 26 27 enum PickKind { PK_VERT, PK_EDGE, PK_HEX, PK_ITEM, PK_CARD, PK_ACTION, PK_BOARD, PK_APP = HIT_APP }; 28 29 /* Datos de presentacion que arma la app. */ 30 typedef struct { 31 int layout; 32 const char *names[MAXP]; 33 const char *const *log; /* registro, la mas nueva al final; marca + asiento: \1 chat, \2 privado, 34 \3 movida (nombre en color), \4 te paso a vos */ 35 int nlog; 36 int log_scroll; /* filas hacia atras desde el final (0 = lo ultimo) */ 37 int *log_max; /* el dibujo deja aca el maximo de log_scroll */ 38 const char *chat_input; /* no NULL: hay linea de chat (lo escrito hasta ahora) */ 39 bool chat_focus; /* se esta escribiendo en ella */ 40 const char *status; /* linea extra (conexion, etc) */ 41 bool show_info; /* panel de detalle (Tab) */ 42 bool show_help; 43 int view_seat; /* cuya mano se muestra */ 44 int modal; /* dialogo de la app encima (salir, etc): 0 ninguno */ 45 const char *modal_text; 46 bool can_free; /* al terminar se puede seguir en juego libre (partida local) */ 47 bool can_again; /* al terminar: jugar otra con las mismas opciones y otro reparto (local) */ 48 bool touch; /* pantalla tactil sin teclado: botones para lo que solo tenia tecla */ 49 const char *preview; /* no NULL: vista previa del tablero antes de crear la partida (titulo); 50 abajo van los botones PK_APP 20 mapa anterior, 21 otro reparto, 51 22 mapa siguiente, 23 jugar, 24 volver */ 52 } UiInfo; 53 54 typedef struct { 55 uint8_t action; /* enum Action (en I_ACTIONS) o valor propio del menu */ 56 int16_t arg; 57 uint8_t enabled; 58 char key; /* atajo */ 59 char label[48]; 60 } MenuItem; 61 62 typedef struct { 63 const Game *g; 64 uint8_t local_mask; /* asientos humanos que controla esta pantalla */ 65 bool handoff; /* mostrar "pasa la compu" entre humanos locales */ 66 const char *names[MAXP]; 67 68 int actor; /* asiento local que tiene que actuar, -1 ninguno */ 69 int shown; /* asiento cuya mano se muestra */ 70 int mode, intent; 71 uint32_t ctx_sig; /* firma del contexto de decision */ 72 73 int16_t targets[NEDGE]; /* vertices/aristas/hexagonos elegibles */ 74 int ntargets, cursor; /* cursor: indice en targets del ultimo objetivo valido */ 75 int pos; /* donde esta el cursor (vertice/arista/hex), valido o no */ 76 int last_x, last_y; /* posicion del cursor (coords de topologia x2) */ 77 int pending_hex; 78 int pending_victim; /* a quien se le roba (o -1) mientras se confirma el ladron */ 79 80 MenuItem items[24]; 81 int nitems, icursor; 82 int menu_title; /* id de string para el titulo */ 83 84 MenuItem actions[20]; /* acciones disponibles en CM_IDLE */ 85 int nactions; 86 87 uint8_t sel[NRES], sel2[NRES]; 88 int need; /* cartas a elegir (descarte/devolucion/abundancia) */ 89 int row, rescur; /* en CM_CARDS: fila (0 doy, 1 pido) y recurso */ 90 int bank_give; 91 int ship_from; /* mover barco: el que se eligio */ 92 uint8_t offer_mask; /* destinatarios elegidos para el trueque */ 93 94 char msg[96]; 95 bool msg_err; 96 97 /* colocacion inicial: pueblo y ruta quedan en borrador hasta confirmar (u deshace) */ 98 int16_t draft_v, draft_e; 99 Move queue[2]; /* movidas confirmadas que faltan mandar (ctrl_next) */ 100 int nqueue; 101 } Ctrl; 102 103 void ctrl_init(Ctrl *c, uint8_t local_mask, bool handoff); 104 void ctrl_sync(Ctrl *c, const Game *g); /* despues de cada movida */ 105 bool ctrl_key(Ctrl *c, int key, Move *out); /* true: hay movida para mandar */ 106 bool ctrl_can_back(const Ctrl *c); /* Esc hace algo ahora (cancelar, deshacer el borrador) */ 107 bool ctrl_pick(Ctrl *c, int kind, int id, Move *out); 108 bool ctrl_next(Ctrl *c, Move *out); /* otra movida para mandar detras de la anterior */ 109 void ctrl_draft(const Ctrl *c, int *v, int *e); /* borrador de colocacion (-1 si no hay) */ 110 void ctrl_error(Ctrl *c, int err); 111 bool ctrl_is_target(const Ctrl *c, int id); 112 int ctrl_cursor_target(const Ctrl *c); /* id bajo el cursor si es valido, -1 si no */ 113 int ctrl_cursor_pos(const Ctrl *c); /* id bajo el cursor aunque no sea valido (-1 fuera de modo) */ 114 const char *ctrl_prompt(const Ctrl *c); /* instruccion para la barra de estado */ 115 116 /* Descripcion de una movida para el log (despues de aplicarla). */ 117 int move_describe(const Game *g, const Move *m, const char *const names[MAXP], char *buf, int n); 118 int move_describe_for(const Game *g, const Move *m, const char *const names[MAXP], unsigned viewers, char *buf, int n); 119 120 #endif