Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/draw.c

Go to the documentation of this file.
00001 /* {{{
00002  * CalcRogue, a roguelike game for PCs, calculators and PDAs
00003  * Copyright (C) 2003 Jim Babcock
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * }}} */
00019 // draw.c
00022 
00023 #include "crogue.h"
00024 
00025 //{{{
00026 static const char* hunger_status(void)
00027 {
00028     if(w->plr.satiation <= -600)
00029         return gettext(" starving");
00030     else if(w->plr.satiation <= 600)
00031         return gettext(" weak");
00032     else if(w->plr.satiation < 2400)
00033         return gettext(" hungry");
00034     else
00035         return "";
00036 }
00037 //}}}
00038 
00039 static int clear_top;
00040 static int statuslinepos;
00041 //{{{
00042 void UI_Status_Place(int y, int t)
00043 {
00044     statuslinepos = y;
00045     clear_top = t;
00046 }
00047 //}}}
00048 
00049 //{{{
00050 void full_redraw(void)
00051 {
00052     Graph_ClrScr();
00053     UI_TF_FullRedraw();
00054     w->messagevis++;
00055     draw();
00056 }
00057 //}}}
00058 //{{{
00059 void draw(void)
00060 {
00061     char outbuf[64];
00062     
00063     if(w->messagevis)
00064     {
00065         if(!(w->plr.extrinsic[STAT_FLAGS] & STAT_FLAG_PARALYZED))
00066             w->messagevis--;
00067     }
00068     else
00069         UI_MF_clear();
00070     
00071     // Draw statusbar
00072     if(w->plr.extrinsic[STAT_FLAGS] & STAT_FLAG_NUMB)
00073         sprintf(outbuf, gettext("HP\?\?/%i "), w->plr.hps_max);
00074     else
00075         sprintf(outbuf, gettext("HP%i/%i "), w->plr.hps, w->plr.hps_max);
00076     
00077     catprintf(outbuf, gettext("PW%i/%i LV%i $:%li %s%s%s%s"),
00078         w->plr.pps,
00079         w->plr.pps_max,
00080         w->plr.level,
00081         player_gold(),
00082         (const char*)deref_file_ptr(MAPDESC_CURRENT.name),
00083         hunger_status(),
00084         (w->plr.extrinsic[STAT_FLAGS] & STAT_FLAG_CONFUSED) ?
00085             gettext(" conf") : "",
00086         (w->plr.extrinsic[STAT_FLAGS] & STAT_FLAG_HALLUCINATING) ?
00087             gettext(" hallu") : ""
00088     );
00089 
00090 #ifdef IS_CALCULATOR
00091     Graph_ClearRect(0, clear_top, SCREEN_WIDTH-1, SCREEN_HEIGHT-1);
00092     SetFont(w->options[OPTION_FONTSIZE]);
00093     Graph_DrawStr(0, statuslinepos, outbuf);
00094 #endif
00095 #ifdef PALMOS
00096     Graph_ClearRect(0, clear_top, SCREEN_WIDTH-1, SCREEN_HEIGHT-1);
00097     Graph_DrawStr(0, statuslinepos, outbuf);
00098 #endif
00099 #ifdef REALCOMPUTER
00100     clear_line(statuslinepos-1);
00101     clear_line(statuslinepos);
00102     mvaddstr(statuslinepos, 0, outbuf);
00103     move(w->plr.y+2, w->plr.x);
00104 #endif
00105 #ifdef REALCOMPUTER // Place the cursor over the player
00106     UI_TF_PlaceCursor(w->plr.x, w->plr.y);
00107 #endif
00108 }
00109 //}}}
00110 //{{{
00111 void draw_all_tiles(void)
00112 {
00113     int x, y;
00114     
00115     for(y=0; y<MAPSIZE_Y; y++)
00116     for(x=0; x<MAPSIZE_X; x++)
00117         draw_tile(x, y);    
00118 }
00119 //}}}
00120 
00121 //{{{
00122 void draw_tile(ushort x, ushort y)
00123 {
00124     uchar tilenum=1;
00125     int flags;
00126     uchar lighting=LIGHTING_DARK;
00127 #   ifdef SUPPORT_COLOR
00128     colorinfo color = {COLOR_WHITE|COLOR_BOLD, COLOR_WHITE|COLOR_BOLD};
00129 #   endif
00130     sint monstnum;
00131     
00132     flags = w->t[y][x].flags;
00133     
00134     if( !(flags & TFLAG_EXPLORED) ) {
00135         tilenum = 1;
00136         lighting = LIGHTING_UNEXPLORED;
00137         goto done;
00138     }
00139     
00140     if(flags & TFLAG_LIT)
00141         lighting = LIGHTING_LIT;
00142     
00143     if((flags & (TFLAG_OCCUPIED|TFLAG_LIT)) == (TFLAG_OCCUPIED|TFLAG_LIT))
00144     {
00145         if(x==w->plr.x && y==w->plr.y) {
00146             tilenum = '@';
00147             goto done;
00148         } else {
00149             monstnum = monstbytile(x, y);
00150             if( monstnum >= 0 && player_can_see(monstnum) )
00151             {
00152                 if(w->plr.extrinsic[STAT_FLAGS] & STAT_FLAG_HALLUCINATING) {
00153                     tilenum = RANGE('Z', 'A');
00154 #                   ifdef SUPPORT_COLOR
00155                     color.lit = RANGE(7,1) | COLOR_BOLD;
00156 #                   endif
00157                 } else {
00158                     tilenum = MDESC(monstnum)->drawchar;
00159 #                   ifdef SUPPORT_COLOR
00160                     color = MDESC(monstnum)->color;
00161 #                   endif
00162                 }
00163                 goto done;
00164             }
00165         }
00166     }
00167     
00168     if(flags & TFLAG_ITEM) {
00169         tilenum = draw_item(x, y);
00170 #       ifdef SUPPORT_COLOR
00171         color = color_item(x, y);
00172 #       endif
00173     } else {
00174         if(flags & TFLAG_HIDETRAP)
00175         {
00176             tilenum = w->tiledescs[TILE_FLOOR].drawchar;
00177 #           ifdef SUPPORT_COLOR
00178             color = w->tiledescs[TILE_FLOOR].color;
00179 #           endif
00180         }
00181         else
00182         {
00183             tilenum = w->tiledescs[w->t[y][x].type].drawchar;
00184 #           ifdef SUPPORT_COLOR
00185             color = w->tiledescs[w->t[y][x].type].color;
00186 #           endif
00187         }
00188     }
00189     
00190 done:
00191 #   ifdef SUPPORT_COLOR
00192     UI_TF_PutTile_Color(x, y, tilenum, lighting, color);
00193 #   else
00194     UI_TF_PutTile(x, y, tilenum, lighting);
00195 #   endif
00196 }
00197 //}}}
00198 

Generated on Thu May 20 13:12:09 2004 for CalcRogue by doxygen 1.3.6