Atrinik Client 2.5
gui/target.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 
00036 void widget_event_target(widgetdata *widget, int x, int y)
00037 {
00038     /* Combat modes */
00039     if (y > widget->y1 + 3 && y < widget->y1 + 38 && x > widget->x1 + 3 && x < widget->x1 + 30)
00040         keybind_process_command("?COMBAT");
00041 
00042     /* Talk button */
00043     if (y > widget->y1 + 7 && y < widget->y1 + 25 && x > widget->x1 + 223 && x < widget->x1 + 259)
00044     {
00045         if (cpl.target_code)
00046             send_command("/t_tell hello");
00047     }
00048 }
00049 
00054 void widget_show_target(widgetdata *widget)
00055 {
00056     char *ptr = NULL;
00057     SDL_Rect box;
00058     double temp;
00059     int hp_tmp;
00060 
00061     sprite_blt(Bitmaps[BITMAP_TARGET_BG], widget->x1, widget->y1, NULL, NULL);
00062 
00063     sprite_blt(Bitmaps[cpl.target_mode ? BITMAP_TARGET_ATTACK : BITMAP_TARGET_NORMAL], widget->x1 + 5, widget->y1 + 4, NULL, NULL);
00064 
00065     sprite_blt(Bitmaps[BITMAP_TARGET_HP_B], widget->x1 + 4, widget->y1 + 24, NULL, NULL);
00066 
00067     hp_tmp = (int) cpl.target_hp;
00068 
00069     /* Redirect target_hp to our hp - server doesn't send it
00070      * because we should know our hp exactly */
00071     if (cpl.target_code == 0)
00072         hp_tmp = (int)(((float) cpl.stats.hp / (float) cpl.stats.maxhp) * 100.0f);
00073 
00074     if (cpl.target_code == 0)
00075     {
00076         if (cpl.target_mode)
00077             ptr = "target self (hold attack)";
00078         else
00079             ptr = "target self";
00080     }
00081     else if (cpl.target_code == 1)
00082     {
00083         if (cpl.target_mode)
00084             ptr = "target and attack enemy";
00085         else
00086             ptr = "target enemy";
00087     }
00088     else if (cpl.target_code == 2)
00089     {
00090         if (cpl.target_mode)
00091             ptr = "target friend (hold attack)";
00092         else
00093             ptr = "target friend";
00094     }
00095 
00096     if (cpl.target_code)
00097     {
00098         sprite_blt(Bitmaps[BITMAP_TARGET_TALK], widget->x1 + 223, widget->y1 + 7, NULL, NULL);
00099     }
00100 
00101     if (setting_get_int(OPT_CAT_GENERAL, OPT_TARGET_SELF) || cpl.target_code != 0)
00102     {
00103         if (hp_tmp)
00104         {
00105             temp = (double) hp_tmp * 0.01;
00106             box.x = 0;
00107             box.y = 0;
00108             box.h = Bitmaps[BITMAP_TARGET_HP]->bitmap->h;
00109             box.w = (int) (Bitmaps[BITMAP_TARGET_HP]->bitmap->w * temp);
00110 
00111             if (!box.w)
00112             {
00113                 box.w = 1;
00114             }
00115 
00116             if (box.w > Bitmaps[BITMAP_TARGET_HP]->bitmap->w)
00117             {
00118                 box.w = Bitmaps[BITMAP_TARGET_HP]->bitmap->w;
00119             }
00120 
00121             sprite_blt(Bitmaps[BITMAP_TARGET_HP], widget->x1 + 5, widget->y1 + 25, &box, NULL);
00122         }
00123 
00124         if (ptr)
00125         {
00126             /* Draw the name of the target */
00127             string_blt(ScreenSurface, FONT_ARIAL10, cpl.target_name, widget->x1 + 35, widget->y1 + 2, cpl.target_color, 0, NULL);
00128 
00129             /* Either draw HP remaining percent and description... */
00130             if (hp_tmp > 0)
00131             {
00132                 char hp_text[MAX_BUF];
00133                 const char *hp_color;
00134 
00135                 snprintf(hp_text, sizeof(hp_text), "HP: %d%%", hp_tmp);
00136 
00137                 if (hp_tmp > 90)
00138                 {
00139                     hp_color = COLOR_GREEN;
00140                 }
00141                 else if (hp_tmp > 75)
00142                 {
00143                     hp_color = COLOR_DGOLD;
00144                 }
00145                 else if (hp_tmp > 50)
00146                 {
00147                     hp_color = COLOR_HGOLD;
00148                 }
00149                 else if (hp_tmp > 25)
00150                 {
00151                     hp_color = COLOR_ORANGE;
00152                 }
00153                 else if (hp_tmp > 10)
00154                 {
00155                     hp_color = COLOR_YELLOW;
00156                 }
00157                 else
00158                 {
00159                     hp_color = COLOR_RED;
00160                 }
00161 
00162                 string_blt(ScreenSurface, FONT_ARIAL10, hp_text, widget->x1 + 35, widget->y1 + 14, hp_color, 0, NULL);
00163                 string_blt(ScreenSurface, FONT_ARIAL10, ptr, widget->x1 + 85, widget->y1 + 14, cpl.target_color, 0, NULL);
00164             }
00165             /* Or draw just the description */
00166             else
00167             {
00168                 string_blt(ScreenSurface, FONT_ARIAL10, ptr, widget->x1 + 35, widget->y1 + 14, cpl.target_color, 0, NULL);
00169             }
00170         }
00171     }
00172 }