[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
| 4 | * |
---|
| 5 | * This software was released into the Public Domain. As with most public |
---|
| 6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
| 7 | * Jonathan Clark. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "config.h" |
---|
| 11 | |
---|
[39] | 12 | #include <math.h> |
---|
| 13 | |
---|
[481] | 14 | #include "game.h" |
---|
[88] | 15 | |
---|
[481] | 16 | #include "jwindow.h" |
---|
| 17 | #include "lisp.h" |
---|
| 18 | #include "scroller.h" |
---|
| 19 | #include "id.h" |
---|
| 20 | #include "cache.h" |
---|
| 21 | #include "dprint.h" |
---|
| 22 | #include "loader2.h" |
---|
[2] | 23 | |
---|
| 24 | extern int dev_ok; |
---|
[110] | 25 | palette *old_pal = NULL; |
---|
[2] | 26 | |
---|
| 27 | class gray_picker : public spicker |
---|
| 28 | { |
---|
| 29 | public: |
---|
[110] | 30 | int sc; |
---|
| 31 | virtual void draw_item(image *screen, int x, int y, int num, int active) |
---|
| 32 | { |
---|
| 33 | long x2 = x + item_width() - 1; |
---|
| 34 | long y2 = y + item_height() - 1; |
---|
| 35 | screen->bar(x, y, x2, y2, 0); |
---|
| 36 | screen->bar(x, y, x2 - 3, y2, sc + num); |
---|
| 37 | if(active) |
---|
| 38 | { |
---|
| 39 | screen->rectangle(x, y, x2, y2, 255); |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | void set_pos(int x) { cur_sel = x; } |
---|
| 43 | virtual int total() { return 32; } |
---|
| 44 | virtual int item_width() { return 12; } |
---|
| 45 | virtual int item_height() { return 20; } |
---|
| 46 | virtual int activate_on_mouse_move() { return 0; } |
---|
[2] | 47 | |
---|
[110] | 48 | gray_picker(int X, int Y, int ID, int start, int current, ifield *Next) : spicker(X, Y, ID, 1, 20, 0, 0, Next) |
---|
| 49 | { |
---|
| 50 | cur_sel = current; |
---|
| 51 | sc = start; |
---|
| 52 | reconfigure(); |
---|
| 53 | cur_sel=current; |
---|
| 54 | } |
---|
[2] | 55 | }; |
---|
| 56 | |
---|
[142] | 57 | static char const *lang_string(char const *symbol) |
---|
| 58 | { |
---|
[484] | 59 | LispSymbol *v = LispSymbol::Find(symbol); |
---|
| 60 | if (!v || !DEFINEDP(v->GetValue())) |
---|
| 61 | return "Language symbol missing!"; |
---|
| 62 | return lstring_value(v->GetValue()); |
---|
[142] | 63 | } |
---|
[2] | 64 | |
---|
| 65 | void gamma_correct(palette *&pal, int force_menu) |
---|
| 66 | { |
---|
[110] | 67 | long dg=0,old_dg=0; |
---|
| 68 | int abort=0; |
---|
[2] | 69 | |
---|
[110] | 70 | // see if user has already done this routine |
---|
[484] | 71 | LispSymbol *gs = LispSymbol::Find("darkest_gray"); |
---|
[2] | 72 | |
---|
[110] | 73 | if(old_pal) |
---|
| 74 | { |
---|
| 75 | delete pal; |
---|
| 76 | pal = old_pal; |
---|
| 77 | old_pal = NULL; |
---|
| 78 | } |
---|
[2] | 79 | |
---|
[484] | 80 | if(gs && DEFINEDP(gs->GetValue()) && !force_menu) |
---|
[110] | 81 | { |
---|
[484] | 82 | dg = lnumber_value(gs->GetValue()); |
---|
[110] | 83 | } |
---|
| 84 | else |
---|
| 85 | { |
---|
[484] | 86 | if(gs && DEFINEDP(gs->GetValue())) |
---|
[110] | 87 | { |
---|
[484] | 88 | dg = old_dg = lnumber_value(gs->GetValue()); |
---|
[110] | 89 | } |
---|
| 90 | // load in a fine gray palette they can chose from |
---|
| 91 | palette *gray_pal = pal->copy(); |
---|
| 92 | int i = 0; |
---|
| 93 | int tc = 32; |
---|
[2] | 94 | |
---|
[110] | 95 | for(;i < tc; i++) |
---|
| 96 | { |
---|
| 97 | gray_pal->set(i, i * 4, i * 4, i * 4); |
---|
| 98 | } |
---|
[2] | 99 | |
---|
[110] | 100 | gray_pal->load(); |
---|
[2] | 101 | |
---|
[110] | 102 | int wm_bc = wm->bright_color(), wm_mc = wm->medium_color(), wm_dc = wm->dark_color(); |
---|
[2] | 103 | |
---|
[110] | 104 | int br_r = pal->red(wm_bc) + 20; |
---|
| 105 | if(br_r > 255) |
---|
| 106 | br_r = 255; |
---|
| 107 | int br_g = pal->green(wm_bc) + 20; |
---|
| 108 | if(br_g > 255) |
---|
| 109 | br_g = 255; |
---|
| 110 | int br_b = pal->blue(wm_bc) + 20; |
---|
| 111 | if(br_b > 255) |
---|
| 112 | br_b = 255; |
---|
[2] | 113 | |
---|
[110] | 114 | int md_r = pal->red(wm_mc) - 20; |
---|
| 115 | if(md_r < 0) |
---|
| 116 | md_r = 0; |
---|
| 117 | int md_g = pal->green(wm_mc) - 20; |
---|
| 118 | if(md_g < 0) |
---|
| 119 | md_g = 0; |
---|
| 120 | int md_b = pal->blue(wm_mc) - 20; |
---|
| 121 | if(md_b < 0) |
---|
| 122 | md_b = 0; |
---|
[2] | 123 | |
---|
[110] | 124 | int dr_r = pal->red(wm_dc) - 40; |
---|
| 125 | if(dr_r < 0) |
---|
| 126 | dr_r = 0; |
---|
| 127 | int dr_g = pal->green(wm_dc) - 40; |
---|
| 128 | if(dr_g < 0) |
---|
| 129 | dr_g = 0; |
---|
| 130 | int dr_b = pal->blue(wm_dc) - 40; |
---|
| 131 | if(dr_b < 0) |
---|
| 132 | dr_b = 0; |
---|
[2] | 133 | |
---|
[110] | 134 | wm->set_colors(gray_pal->find_closest(br_r, br_g, br_b), |
---|
| 135 | gray_pal->find_closest(md_r, md_g, md_b), |
---|
| 136 | gray_pal->find_closest(dr_r, dr_g, dr_b)); |
---|
[2] | 137 | |
---|
[110] | 138 | int sh = wm->font()->height() + 35; |
---|
[123] | 139 | button *but = new button(5, 5 + sh * 3, ID_GAMMA_OK, cache.img(ok_button), |
---|
[111] | 140 | new info_field(35, 10 + sh * 3, ID_NULL, lang_string("gamma_msg"), 0)); |
---|
[2] | 141 | |
---|
[111] | 142 | gray_picker *gp = new gray_picker(2, 5 + sh, ID_GREEN_PICKER, 0, dg / 4, but); |
---|
[110] | 143 | gp->set_pos(dg / 4); |
---|
[2] | 144 | |
---|
[120] | 145 | Jwindow *gw = wm->new_window(xres / 2 - 190, yres / 2 - 90, -1, -1, gp); |
---|
[2] | 146 | |
---|
[110] | 147 | event ev; |
---|
| 148 | wm->flush_screen(); |
---|
| 149 | do |
---|
| 150 | { |
---|
| 151 | do |
---|
| 152 | { |
---|
| 153 | wm->get_event(ev); |
---|
| 154 | } while(ev.type == EV_MOUSE_MOVE && wm->event_waiting()); |
---|
| 155 | wm->flush_screen(); |
---|
| 156 | if(ev.type == EV_CLOSE_WINDOW) |
---|
| 157 | abort = 1; |
---|
| 158 | if(ev.type == EV_KEY && ev.key == JK_ESC) |
---|
| 159 | abort = 1; |
---|
| 160 | } while(!abort && (ev.type != EV_MESSAGE || ev.message.id != ID_GAMMA_OK)); |
---|
[2] | 161 | |
---|
[110] | 162 | dg = ((spicker *)gw->inm->get(ID_GREEN_PICKER))->first_selected() * 4; |
---|
[2] | 163 | |
---|
[110] | 164 | wm->close_window(gw); |
---|
| 165 | wm->flush_screen(); |
---|
[2] | 166 | |
---|
[110] | 167 | wm->set_colors(wm_bc, wm_mc, wm_dc); |
---|
| 168 | delete gray_pal; |
---|
[2] | 169 | |
---|
[110] | 170 | if(!abort) |
---|
| 171 | { |
---|
| 172 | char *gammapath; |
---|
| 173 | FILE *fp; |
---|
[2] | 174 | |
---|
[129] | 175 | gammapath = (char *)malloc(strlen(get_save_filename_prefix()) + 10); |
---|
[110] | 176 | sprintf(gammapath, "%sgamma.lsp", get_save_filename_prefix()); |
---|
| 177 | fp = open_FILE(gammapath, "wb"); |
---|
| 178 | if(fp) |
---|
| 179 | { |
---|
| 180 | fprintf(fp, "(setq darkest_gray %ld)\n", dg); |
---|
| 181 | fclose(fp); |
---|
| 182 | int sp = current_space; |
---|
| 183 | current_space = PERM_SPACE; |
---|
[484] | 184 | LispSymbol::FindOrCreate("darkest_gray")->SetNumber(dg); |
---|
[2] | 185 | |
---|
[110] | 186 | current_space = sp; |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | dprintf("Unable to write to file gamma.lsp\n"); |
---|
| 191 | } |
---|
[129] | 192 | free(gammapath); |
---|
[110] | 193 | } |
---|
| 194 | } |
---|
[2] | 195 | |
---|
[110] | 196 | if(abort) |
---|
| 197 | dg = old_dg; |
---|
[2] | 198 | |
---|
[110] | 199 | if(dg < 1) |
---|
| 200 | dg = 1; |
---|
| 201 | else if(dg > 128) |
---|
| 202 | dg = 128; |
---|
[2] | 203 | |
---|
[110] | 204 | double gamma = log(dg / 255.0) / log(16.0 / 255.0); |
---|
[2] | 205 | |
---|
[110] | 206 | old_pal = pal; |
---|
| 207 | pal = new palette; |
---|
| 208 | for(int i = 0; i < 256; i++) |
---|
| 209 | { |
---|
| 210 | uint8_t oldr, oldg, oldb; |
---|
| 211 | old_pal->get(i, oldr, oldg, oldb); |
---|
| 212 | pal->set(i, (int)(pow(oldr / 255.0, gamma) * 255), |
---|
| 213 | (int)(pow(oldg / 255.0, gamma) * 255), |
---|
| 214 | (int)(pow(oldb / 255.0, gamma) * 255)); |
---|
| 215 | } |
---|
[2] | 216 | |
---|
[110] | 217 | pal->load(); |
---|
[2] | 218 | } |
---|