#include "xrisk.h" #include "xrisklibex.h" #include #include /* Function to jump to when writing error_msg etc., extits to unix */ void risk_exit(char *format,...) { va_list ap; char *args[5]; int argno = 0; va_start (ap, format); while ((argno<5)&&((args[argno++] = va_arg(ap, char *)) != LAST_ARG)); va_end (ap); fprintf(stderr,format,args[0],args[1],args[2],args[3],args[4]); exit(0); } /* Read then mapnumber and return it (or -1 if none) */ int mapnumber(s) char *s; { int retur; if ((*s!='#')||(s[1]<'0')||(s[1]>'9')||(s[2]<'0')||(s[2]>'9') ||(s[3]<'0')||(s[3]>'9')||(s[4]!='_')) return(-1); retur = atoi(&s[1]); if ( retur >= MAX_MAPS ) risk_exit ("Mistake in program, to high mapnumber %d\n",s,retur,LAST_ARG); return(retur); } /* Return the mapping of aa sentence ( Multi-language-support) */ char *mappet(s) char *s; { int t; t = mapnumber(s); if ( ( t == -1) || ( ! sentencemapping[t] ) ) return(s); return(sentencemapping[t]); } /* Write a line in a window */ int write_line(xinfo,win,fg,bg,x,y,dx,dy,msg,flag) xconp xinfo; Window win; int fg,bg; int x,y,dx,dy; char *msg; int flag; { if (!xinfo) return(1); if (dy == -1) dy=FONTH+2*FILLH; if (dx == -1) dx=strlen(msg)*FONTB; if (flag&CLR) { if (bg == -1) XSetForeground(xinfo->disp,xinfo->gc,xinfo->black); else XSetForeground(xinfo->disp,xinfo->gc,(unsigned long)bg); XFillRectangle(xinfo->disp,win,xinfo->gc,x,y-dy+FILLH,dx,dy); } if (*msg) { char *tmp; tmp = mappet(msg); if (bg == -1) XSetBackground(xinfo->disp,xinfo->gc,xinfo->black); else XSetBackground(xinfo->disp,xinfo->gc,(unsigned long)bg); if (fg == -1) XSetForeground(xinfo->disp,xinfo->gc,xinfo->white); else XSetForeground(xinfo->disp,xinfo->gc,(unsigned long)fg); if (flag&CENTER) x+=(dx-strlen(tmp)*FONTB)/2; if (flag&CLR || (!(flag&DRAWIMAGESTRING))) XDrawString (xinfo->disp,win,xinfo->gc,x,y,tmp,strlen(tmp)); else XDrawImageString (xinfo->disp,win,xinfo->gc,x,y,tmp,strlen(tmp)); } XFlush(xinfo->disp); return(0); } /* Write msg to user */ int write_msg(player, msg) playerp player; char *msg; { if ( !player || !player->xcon ) return(1); if (msg) { strncpy(player->pstat->string[2],msg,Min(strlen(msg),MAXLEN_MISC)); *(player->pstat->string[2]+Min(strlen(msg),MAXLEN_MISC)) = 0; write_line(player->xcon,player->xcon->win,-1,-1,MSGX,MSGY, MSGLEN,-1,player->pstat->string[2],CLR|CENTER); } else write_line(player->xcon,player->xcon->win,-1,-1, MSGX,MSGY,MSGLEN,-1,player->pstat->string[2],CLR|CENTER); return(0); } /* Map argumentlist based on format-sentence */ void mappargs(format, args, argno) char *format, **args; int argno; { int t,flag,ant; for(t=0,flag=0,ant=0;format[t]&&ant %s",mappet(msg)); for(t=0;txcon; XSetForeground(xinfo->disp,xinfo->gc,xinfo->black); XFillRectangle(xinfo->disp,xinfo->scrollwin,xinfo->gc,0,0,SCWINL,SCWINH); for(t1=0;t1xcon,players[t]->xcon->scrollwin,-1,-1, FONTB/2,t1*(FONTH+FILLH)+FONTH+FILLH,-1,-1,linjer[t1],0); } } /* Write a message with arguments to all players */ void write_msg_all_arg(char *file,...) { va_list ap; char *args[5]; char msg[MAXLEN_MISC]; int argno = 0; va_start (ap, file); file = mappet(file); while ((argno<5)&& ((args[argno++] = va_arg(ap, char *)) != LAST_ARG) ); va_end (ap); mappargs(file,args,argno); sprintf(msg,file,args[0],args[1],args[2],args[3],args[4]); write_msg_all(msg); } /* Write name of country/continent down near south-america */ void write_country(xinfo, country) xconp xinfo; countryp country; { static countryp last_country[MAX_PLAYERS]; if(last_country[xinfo->indexs]!=country) { last_country[xinfo->indexs]=country; if (country) { write_line(xinfo,xinfo->win,-1,-1, TEXTX,TEXTY,WIDTH_NMISC,-1,country->name,CLR); write_line(xinfo,xinfo->win,-1,-1, TEXTX,TEXTY+FONTH+2*FILLH,WIDTH_NMISC,-1, country->continent->name,CLR); } else { write_line(xinfo,xinfo->win,-1,-1,TEXTX,TEXTY,WIDTH_NMISC,-1,"",CLR); write_line(xinfo,xinfo->win,-1,-1, TEXTX,TEXTY+FONTH+2*FILLH,WIDTH_NMISC,-1,"",CLR); } } }