1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 /*
20  * $Source: u://RCS/bark.c $
21  * $Revision: 1.33 $
22  * $Author: xemu $
23  * $Date: 1994/10/27 04:52:50 $
24  *
25  *
26  */
27 
28 // Includes for example mfd.
29 #include <stdlib.h>
30 
31 #include "bark.h"
32 #include "mfdext.h"
33 #include "mfddims.h"
34 #include "tools.h"
35 #include "gamestrn.h"
36 #include "objects.h"
37 #include "mfdart.h"
38 #include "gamescr.h"
39 #include "shodan.h"
40 #include "sfxlist.h"
41 #include "musicai.h"
42 #include "fullscrn.h"
43 #include "cit2d.h"
44 #include "citres.h"
45 #include "fullscrn.h"
46 #include "audiolog.h"
47 #include "gr2ss.h"
48 #include "tools.h"
49 
50 // ============================================================
51 //                   MFD BARK
52 // ============================================================
53 
54 #define BARK_MARGIN 2
55 
mfd_bark_expose(MFD * mfd,ubyte control)56 void mfd_bark_expose(MFD *mfd, ubyte control) {
57     uchar full = control & MFD_EXPOSE_FULL;
58     if (control == 0) // MFD is drawing stuff
59     {
60         // Do unexpose stuff here.
61     }
62     if (control & MFD_EXPOSE) // Time to draw stuff
63     {
64         // clear update rects
65         mfd_clear_rects();
66         // set up canvas
67         gr_push_canvas(pmfd_canvas);
68         ss_safe_set_cliprect(0, 0, MFD_VIEW_WID, MFD_VIEW_HGT);
69 
70         // Clear the canvas by drawing the background bitmap
71         if (!full_game_3d)
72             ss_bitmap(&mfd_background, 0, 0);
73         // gr_bitmap(&mfd_background, 0, 0);
74 
75         if (mfd_bark_mug > 0) {
76 	    FrameDesc *mug = RefLock(REF_IMG_EmailMugShotBase + mfd_bark_mug);
77 	    if (mug != NULL) {
78 		ss_bitmap(&mug->bm, (MFD_VIEW_WID - mug->bm.w) / 2, (MFD_VIEW_HGT - mug->bm.h) / 2);
79 		RefUnlock(REF_IMG_EmailMugShotBase + mfd_bark_mug);
80 	    } else {
81 		WARN("mfd_bark_expose(): could not load mugshot ", mug);
82 	    }
83         } else if (!full_game_3d) {
84             draw_raw_resource_bm(MKREF(RES_mfdArtOverlays, MFD_ART_TRIOP), 0, 0);
85         }
86         if (full && global_fullmap->cyber && mfd->id == MFD_RIGHT && (full_visible & visible_mask(mfd->id)) == 0) {
87 #ifdef STEREO_SUPPORT
88             if (convert_use_mode == 5)
89                 full_visible = visible_mask(mfd->id);
90             else
91 #endif
92                 full_visible |= visible_mask(mfd->id);
93             mfd_notify_func(MFD_BARK_FUNC, MFD_INFO_SLOT, FALSE, MFD_ACTIVE, TRUE);
94         }
95 
96         if (full && mfd_bark_string != REF_STR_Null) {
97             char buf[256];
98             short x, y;
99             short w, h;
100             //RefTable *prt = (RefTable *)ResLock(REFID(mfd_bark_string));
101             RefTable *prt = ResReadRefTable(REFID(mfd_bark_string));
102 
103             if (RefIndexValid(prt, REFINDEX(mfd_bark_string))) {
104                 gr_set_font((grs_font *)ResLock(MFD_FONT));
105                 hyphenated_wrap_text(get_temp_string(mfd_bark_string), buf, MFD_VIEW_WID - 2);
106                 gr_string_size(buf, &w, &h);
107                 gr_set_fcolor(mfd_bark_color);
108                 x = (MFD_VIEW_WID - w) / 2;
109                 if (mfd_bark_mug > 0)
110                     y = BARK_MARGIN;
111                 else
112                     y = (MFD_VIEW_HGT - h) / 2;
113                 draw_shadowed_string(buf, x, y, mfd_bark_mug > 0 || full_game_3d);
114                 ResUnlock(MFD_FONT);
115             }
116             //ResUnlock(REFID(mfd_bark_string));
117             ResFreeRefTable(prt);
118         }
119         if (full)
120             mfd_add_rect(0, 0, MFD_VIEW_WID, MFD_VIEW_HGT);
121 
122         // Pop the canvas
123         gr_pop_canvas();
124         // Now that we've popped the canvas, we can send the
125         // updated mfd to screen
126         mfd_update_rects(mfd);
127     }
128 }
129 
long_bark(ObjID speaker_id,uchar mug_id,int string_id,ubyte color)130 void long_bark(ObjID speaker_id, uchar mug_id, int string_id, ubyte color) {
131     short mfd_id = mfd_grab_func(MFD_BARK_FUNC, MFD_INFO_SLOT);
132 #ifdef AUDIOLOGS
133     errtype alog_rv = ERR_NOEFFECT;
134 #endif
135 
136     mfd_bark_string = string_id;
137     mfd_bark_speaker = speaker_id;
138     mfd_bark_color = color;
139     mfd_bark_mug = mug_id;
140 #ifdef AUDIOLOGS
141     if ((audiolog_setting) && (REFID(string_id) == RES_traps))
142         alog_rv = audiolog_bark_play(string_id - REF_STR_TrapZeroMessage);
143 #else
144     if ((mug_id >= FIRST_SHODAN_BARK) && (mug_id <= FIRST_SHODAN_BARK + NUM_SHODAN_MUGS - 1))
145         play_digi_fx(SFX_SHODAN_BARK, 1);
146 #endif
147 
148 #ifdef AUDIOLOGS
149     if ((alog_rv != OK) || (audiolog_setting == 2))
150 #endif
151     {
152         mfd_notify_func(MFD_BARK_FUNC, MFD_INFO_SLOT, TRUE, MFD_ACTIVE, TRUE);
153         if (speaker_id > 0) {
154             save_mfd_slot(mfd_id);
155             player_struct.panel_ref = speaker_id;
156         }
157         mfd_change_slot(mfd_id, MFD_INFO_SLOT);
158     }
159 }
160