/* src is attacking dst */ TEG_STATUS clitok_attack( char *str) { int src,dst; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; PCPLAYER pJsrc, pJdst; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { src = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { dst = atoi( p.token ); } else goto error; /* countries are allowed to be -1 (unknown in fog of war) */ if( src<-1 || src>=COUNTRIES_CANT || dst<-1 || dst>=COUNTRIES_CANT ) goto error; pJsrc = NULL; if( src >=0 ) player_whois( g_countries[src].numjug, &pJsrc ); pJdst = NULL; if( dst >=0 ) player_whois( g_countries[dst].numjug, &pJdst ); if( src >= 0 && g_countries[src].numjug == WHOAMI() ) { attack_reset(); } else { attack_show( src, dst ); } if( pJsrc && pJdst ) textmsg(M_INF,_("%s(%s) is attacking %s(%s)"), countries_get_name(src), _(g_colores[pJsrc->color]) ,countries_get_name(dst), _(g_colores[pJdst->color]) ); else textmsg(M_INF,_("%s is attacking %s"),countries_get_name(src), countries_get_name(dst) ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_attack()"); return TEG_STATUS_ERROR; }
/* I'm receiving the card I've requested after finishing my turn */ TEG_STATUS clitok_tarjeta(char *str) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int country,used; if( strlen(str)==0 ) goto error; p.igualador = &igualador; p.separador = &separador; p.data = str; if( parser_call( &p ) && p.hay_otro ) { country = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { used = atoi( p.token ); } else goto error; if( country < 0 || country >= COUNTRIES_CANT ) goto error; ESTADO_SET(PLAYER_STATUS_TARJETA); InsertTailList( &g_game.tarjetas_list, (PLIST_ENTRY) &g_countries[ country ].tarjeta ); g_game.tarjetas_cant++; if( used ) tarjeta_usar( &g_countries[ country ].tarjeta ); g_countries[ country ].tarjeta.numjug = WHOAMI(); if( used ) { textmsg(M_IMP,_("You received card: '%s' and 2 armies where placed there"), countries_get_name( country ) ); } else { textmsg(M_IMP,_("You received card: '%s'"), countries_get_name( country ) ); } gui_tarjeta( country ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_tarjeta()"); return TEG_STATUS_ERROR; }
TEG_STATUS attack_click( PCOUNTRY p ) { if( attack_check() != TEG_STATUS_SUCCESS ) { textmsg(M_ERR,_("Error, It's not the time to attack")); return TEG_STATUS_UNEXPECTED; } if( country_origen == -1 ) { if(p->numjug == WHOAMI()) { if( p->ejercitos >1 ) { p->selected &= ~COUNTRY_SELECT_ATTACK_ENTER; p->selected |= COUNTRY_SELECT_ATTACK; gui_country_select(p->id); country_origen = p->id; textmsg(M_INF,_("Source country: '%s'. Now select the destination country"),countries_get_name(p->id)); } else { textmsg(M_ERR,_("Error, '%s' must have at least 2 armies"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } } else { textmsg(M_ERR,_("Error, '%s' isn't one of your countries"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } } else if( country_destino == -1 ) { if( country_origen == p->id ) { textmsg(M_INF,_("Source country is the same as the destination. Resetting the attack...")); attack_reset(); return TEG_STATUS_SUCCESS; } if(p->numjug != WHOAMI() ) { if( countries_eslimitrofe(country_origen, p->id) ) { p->selected &= ~COUNTRY_SELECT_ATTACK_ENTER; p->selected |= COUNTRY_SELECT_ATTACK; gui_country_select(p->id); country_destino = p->id; textmsg(M_INF,_("Destination country: '%s'. Attacking..."),countries_get_name(p->id)); attack_out(); } else { textmsg(M_ERR,_("Error, '%s' isn't frontier with '%s'"),countries_get_name(p->id),countries_get_name(country_origen)); attack_reset(); return TEG_STATUS_UNEXPECTED; } } else { textmsg(M_ERR,_("Error, you can't attack your own countries ('%s')"),countries_get_name(p->id)); attack_reset(); return TEG_STATUS_UNEXPECTED; } } else { attack_reset(); textmsg(M_ERR,_("Error, unexpected error in attack_click(). Report this bug!")); return TEG_STATUS_UNEXPECTED; } return TEG_STATUS_SUCCESS; }
/** * @fn TEG_STATUS sub_fichas( PCOUNTRY p ) * llamada desde la 'gui' y recuerda los countries que se fueron agregando * @params p country que se esta agregando */ TEG_STATUS fichas_sub( PCOUNTRY p ) { if( fichas_check() != TEG_STATUS_SUCCESS ) { textmsg(M_ERR,_("Error, you cant sub armies now")); return TEG_STATUS_UNEXPECTED; } if(p->numjug == WHOAMI() ) { if( aFichas[p->id] ) { fichas_tot--; p->ejercitos--; aFichas[p->id]--; aConts[p->continente]--; fichas_enter( p ); return TEG_STATUS_SUCCESS; } else return TEG_STATUS_UNEXPECTED; } else { textmsg(M_ERR,_("Error, '%s' isnt one of your countries"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } }
/** * @fn TEG_STATUS add_fichas( PCOUNTRY p ) * llamada desde la 'gui' y recuerda los countries que se fueron agregando * @params p country que se esta agregando */ TEG_STATUS fichas_add( PCOUNTRY p ) { if( fichas_check() != TEG_STATUS_SUCCESS ) { textmsg(M_ERR,_("Error, you cant add armies now")); return TEG_STATUS_UNEXPECTED; } if(p->numjug == WHOAMI() ) { if( fichas_tot < wanted_tot ) { fichas_tot++; p->ejercitos++; aFichas[p->id]++; aConts[p->continente]++; return TEG_STATUS_SUCCESS; } else { textmsg(M_ERR,_("Error, you cant put more than %d armies"),wanted_tot); fichas_enter( p ); return TEG_STATUS_ERROR; } } else { textmsg(M_ERR,_("Error, '%s' isnt one of your countries"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } }
/* dices result */ TEG_STATUS clitok_dados( char *str) { int i; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; /* src and dst country can be -1 */ /* attacker */ if( parser_call( &p ) && p.hay_otro ) { g_game.dados_srccountry = atoi( p.token ); if( g_game.dados_srccountry >= COUNTRIES_CANT || g_game.dados_srccountry < -1 ) { g_game.dados_srccountry = -1; goto error; } } for(i=0;i<3;i++) { if( parser_call( &p ) && p.hay_otro ) { g_game.dados_src[i] = atoi( p.token ); } else goto error; } /* defender */ if( parser_call( &p ) && p.hay_otro ) { g_game.dados_dstcountry = atoi( p.token ); if( g_game.dados_dstcountry >= COUNTRIES_CANT || g_game.dados_dstcountry < -1 ) { g_game.dados_dstcountry = -1; goto error; } } for(i=0;i<2;i++) { if( parser_call( &p ) && p.hay_otro ) { g_game.dados_dst[i] = atoi( p.token ); } else goto error; } if( parser_call( &p ) && !p.hay_otro ) { g_game.dados_dst[2] = atoi( p.token ); } else goto error; textmsg(M_INF,_("Dices: %s: %d %d %d vs. %s: %d %d %d") ,countries_get_name(g_game.dados_srccountry) ,g_game.dados_src[0] ,g_game.dados_src[1] ,g_game.dados_src[2] ,countries_get_name(g_game.dados_dstcountry) ,g_game.dados_dst[0] ,g_game.dados_dst[1] ,g_game.dados_dst[2] ); gui_dados(); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_dados()"); return TEG_STATUS_ERROR; }
/* window that shows armies to move in a regroup */ void reagrupe_window( int src, int dst, int cant ) { GtkWidget *label; GtkWidget *table; GtkWidget *frame; GtkWidget *vbox_dia,*vbox; GtkWidget *hbox; GtkAdjustment *adj; char buf[200]; reagrupe_src = src; reagrupe_dst = dst; if( reagrupe_dialog != NULL ) { gdk_window_show( reagrupe_dialog->window); gdk_window_raise( reagrupe_dialog->window); return ; } reagrupe_cant = 0; // reagrupe_dialog = gnome_dialog_new(_("Regrouping armies"),GNOME_STOCK_BUTTON_OK,NULL); reagrupe_dialog = teg_dialog_new(_("Regrouping armies"),_("Regroup your armies")); // Make the dialog modal (=main window is deactivated while the dialog is open) to fix // bug [689687]: Error, unexpected error in reagrupe_click(). gtk_window_set_modal( GTK_WINDOW( reagrupe_dialog ), TRUE ); gnome_dialog_append_button(GNOME_DIALOG(reagrupe_dialog), GNOME_STOCK_BUTTON_OK); gnome_dialog_set_parent (GNOME_DIALOG (reagrupe_dialog), GTK_WINDOW (main_window)); gtk_signal_connect (GTK_OBJECT (reagrupe_dialog), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &reagrupe_dialog); // When ok gets pressed, call reagrupe_ok_cb(). gnome_dialog_button_connect(GNOME_DIALOG(reagrupe_dialog), 0, GTK_SIGNAL_FUNC(reagrupe_ok_cb), NULL); vbox_dia = GNOME_DIALOG(reagrupe_dialog)->vbox; table = gtk_table_new (2, 2, FALSE); gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD); gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD); gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD); gtk_box_pack_start( GTK_BOX( vbox_dia), table, TRUE, TRUE, 0); frame = gtk_frame_new (_("Regrouping")); gtk_container_border_width (GTK_CONTAINER (frame), 0); vbox = gtk_vbox_new (TRUE, 0); gtk_container_border_width (GTK_CONTAINER (vbox), GNOME_PAD); snprintf(buf, sizeof(buf) -1, _("Moving armies from '%s' to '%s'\n"), countries_get_name(src), countries_get_name(dst) ); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); hbox = gtk_hbox_new( FALSE, 0); gtk_container_add( GTK_CONTAINER( vbox ), hbox ); label = gtk_label_new(_("Armies to move")); gtk_box_pack_start( GTK_BOX( hbox), label, TRUE, TRUE, 0); adj = (GtkAdjustment *) gtk_adjustment_new( (gfloat) cant, 0.0, (gfloat) (cant + 1), 1.0, 1.0, 1.0 ); reagrupe_hscale_cant = gtk_hscale_new( adj); gtk_box_pack_start( GTK_BOX( hbox), reagrupe_hscale_cant, TRUE, TRUE, 0); gtk_scale_set_digits(GTK_SCALE(reagrupe_hscale_cant), 0); gtk_scale_set_draw_value(GTK_SCALE(reagrupe_hscale_cant),1); /* gtk_range_draw_trough(GTK_RANGE(reagrupe_hscale_cant)); */ snprintf(buf, sizeof(buf) -1,_("[Note: You can regroup as many times as you want,\nas long as you don't regroup an army that was\nregrouped before in this turn.]")); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); if (!GTK_WIDGET_VISIBLE (reagrupe_dialog)) gtk_widget_show_all (reagrupe_dialog); else gtk_widget_destroy (reagrupe_dialog); }
/* shows how many armies you can move after an attack */ void tropas_window( int src, int dst, int cant ) { GtkWidget *label; GtkWidget *table; GtkWidget *frame; GtkWidget *vbox_dia,*vbox; GtkWidget *hbox; GtkAdjustment *adj; char buf[200]; tropas_src = src; tropas_dst = dst; if( tropas_dialog != NULL ) { gdk_window_show( tropas_dialog->window); gdk_window_raise( tropas_dialog->window); return ; } tropas_cant = 0; // tropas_dialog = gnome_dialog_new(_("A country was conquered"),GNOME_STOCK_BUTTON_OK,NULL); tropas_dialog = teg_dialog_new(_("A country was conquered"),_("A country was conquered")); gnome_dialog_append_button( GNOME_DIALOG(tropas_dialog),GNOME_STOCK_BUTTON_OK); gnome_dialog_set_parent (GNOME_DIALOG (tropas_dialog), GTK_WINDOW (main_window)); gtk_signal_connect (GTK_OBJECT (tropas_dialog), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &tropas_dialog); if( cant > 0 ) gnome_dialog_button_connect(GNOME_DIALOG(tropas_dialog), 0, GTK_SIGNAL_FUNC(tropas_ok_cb), NULL); else gnome_dialog_button_connect(GNOME_DIALOG(tropas_dialog), 0, GTK_SIGNAL_FUNC(tropas_close_cb), NULL); vbox_dia = GNOME_DIALOG(tropas_dialog)->vbox; table = gtk_table_new (2, 2, FALSE); gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD); gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD); gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD); gtk_box_pack_start( GTK_BOX( vbox_dia), table, TRUE, TRUE, 0); frame = gtk_frame_new (_("A new country")); gtk_container_border_width (GTK_CONTAINER (frame), 0); vbox = gtk_vbox_new (TRUE, 0); gtk_container_border_width (GTK_CONTAINER (vbox), GNOME_PAD); snprintf(buf,sizeof(buf)-1,_("You conquered '%s' in your attack from '%s'!!\n"), countries_get_name(dst), countries_get_name(src) ); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); if( cant > 0) { hbox = gtk_hbox_new( FALSE, 0); gtk_container_add( GTK_CONTAINER( vbox ), hbox ); label = gtk_label_new(_("Armies to move")); gtk_box_pack_start( GTK_BOX( hbox), label, TRUE, TRUE, 0); adj = (GtkAdjustment *) gtk_adjustment_new( (gfloat) cant, 0.0, (gfloat) (cant + 1), 1.0, 1.0, 1.0 ); // tropas_spinner_cant = gtk_spin_button_new( adj, 0.0, 0); tropas_hscale_cant = gtk_hscale_new( adj); gtk_box_pack_start( GTK_BOX( hbox), tropas_hscale_cant, TRUE, TRUE, 0); gtk_scale_set_digits(GTK_SCALE(tropas_hscale_cant), 0); gtk_scale_set_draw_value(GTK_SCALE(tropas_hscale_cant),1); /* gtk_range_draw_trough(GTK_RANGE(tropas_hscale_cant)); */ snprintf(buf, sizeof(buf) -1, _("[Note: The server moved 1 army to '%s' for you.\nChoose how many more armies you want to move]"), countries_get_name(dst) ); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); } gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); if (!GTK_WIDGET_VISIBLE (tropas_dialog)) gtk_widget_show_all (tropas_dialog); else gtk_widget_destroy (tropas_dialog); }