root/trunk/src/cave.c

Revision 951, 95.3 kB (checked in by takkaria, 3 months ago)

Clear up a constness warning in cave.c.

  • Property svn:eol-style set to native
Line 
1 /*
2  * File: cave.c
3  * Purpose: Lighting and update functions
4  *
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6  *
7  * This work is free software; you can redistribute it and/or modify it
8  * under the terms of either:
9  *
10  * a) the GNU General Public License as published by the Free Software
11  *    Foundation, version 2, or
12  *
13  * b) the "Angband licence":
14  *    This software may be copied and distributed for educational, research,
15  *    and not for profit purposes provided that this copyright and statement
16  *    are included in all such copies.  Other copyrights may also apply.
17  */
18 #include "angband.h"
19 #include "tvalsval.h"
20 #include "game-event.h"
21
22 /*
23  * Support for Adam Bolt's tileset, lighting and transparency effects
24  * by Robert Ruehlmann (rr9@thangorodrim.net)
25  */
26
27 /*
28  * Approximate distance between two points.
29  *
30  * When either the X or Y component dwarfs the other component,
31  * this function is almost perfect, and otherwise, it tends to
32  * over-estimate about one grid per fifteen grids of distance.
33  *
34  * Algorithm: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2
35  */
36 int distance(int y1, int x1, int y2, int x2)
37 {
38         int ay, ax;
39
40         /* Find the absolute y/x distance components */
41         ay = (y1 > y2) ? (y1 - y2) : (y2 - y1);
42         ax = (x1 > x2) ? (x1 - x2) : (x2 - x1);
43
44         /* Hack -- approximate the distance */
45         return ((ay > ax) ? (ay + (ax>>1)) : (ax + (ay>>1)));
46 }
47
48
49 /*
50  * A simple, fast, integer-based line-of-sight algorithm.  By Joseph Hall,
51  * 4116 Brewster Drive, Raleigh NC 27606.  Email to jnh@ecemwl.ncsu.edu.
52  *
53  * This function returns TRUE if a "line of sight" can be traced from the
54  * center of the grid (x1,y1) to the center of the grid (x2,y2), with all
55  * of the grids along this path (except for the endpoints) being non-wall
56  * grids.  Actually, the "chess knight move" situation is handled by some
57  * special case code which allows the grid diagonally next to the player
58  * to be obstructed, because this yields better gameplay semantics.  This
59  * algorithm is totally reflexive, except for "knight move" situations.
60  *
61  * Because this function uses (short) ints for all calculations, overflow
62  * may occur if dx and dy exceed 90.
63  *
64  * Once all the degenerate cases are eliminated, we determine the "slope"
65  * ("m"), and we use special "fixed point" mathematics in which we use a
66  * special "fractional component" for one of the two location components
67  * ("qy" or "qx"), which, along with the slope itself, are "scaled" by a
68  * scale factor equal to "abs(dy*dx*2)" to keep the math simple.  Then we
69  * simply travel from start to finish along the longer axis, starting at
70  * the border between the first and second tiles (where the y offset is
71  * thus half the slope), using slope and the fractional component to see
72  * when motion along the shorter axis is necessary.  Since we assume that
73  * vision is not blocked by "brushing" the corner of any grid, we must do
74  * some special checks to avoid testing grids which are "brushed" but not
75  * actually "entered".
76  *
77  * Angband three different "line of sight" type concepts, including this
78  * function (which is used almost nowhere), the "project()" method (which
79  * is used for determining the paths of projectables and spells and such),
80  * and the "update_view()" concept (which is used to determine which grids
81  * are "viewable" by the player, which is used for many things, such as
82  * determining which grids are illuminated by the player's torch, and which
83  * grids and monsters can be "seen" by the player, etc).
84  */
85 bool los(int y1, int x1, int y2, int x2)
86 {
87         /* Delta */
88         int dx, dy;
89
90         /* Absolute */
91         int ax, ay;
92
93         /* Signs */
94         int sx, sy;
95
96         /* Fractions */
97         int qx, qy;
98
99         /* Scanners */
100         int tx, ty;
101
102         /* Scale factors */
103         int f1, f2;
104
105         /* Slope, or 1/Slope, of LOS */
106         int m;
107
108
109         /* Extract the offset */
110         dy = y2 - y1;
111         dx = x2 - x1;
112
113         /* Extract the absolute offset */
114         ay = ABS(dy);
115         ax = ABS(dx);
116
117
118         /* Handle adjacent (or identical) grids */
119         if ((ax < 2) && (ay < 2)) return (TRUE);
120
121
122         /* Directly South/North */
123         if (!dx)
124         {
125                 /* South -- check for walls */
126                 if (dy > 0)
127                 {
128                         for (ty = y1 + 1; ty < y2; ty++)
129                         {
130                                 if (!cave_floor_bold(ty, x1)) return (FALSE);
131                         }
132                 }
133
134                 /* North -- check for walls */
135                 else
136                 {
137                         for (ty = y1 - 1; ty > y2; ty--)
138                         {
139                                 if (!cave_floor_bold(ty, x1)) return (FALSE);
140                         }
141                 }
142
143                 /* Assume los */
144                 return (TRUE);
145         }
146
147         /* Directly East/West */
148         if (!dy)
149         {
150                 /* East -- check for walls */
151                 if (dx > 0)
152                 {
153                         for (tx = x1 + 1; tx < x2; tx++)
154                         {
155                                 if (!cave_floor_bold(y1, tx)) return (FALSE);
156                         }
157                 }
158
159                 /* West -- check for walls */
160                 else
161                 {
162                         for (tx = x1 - 1; tx > x2; tx--)
163                         {
164                                 if (!cave_floor_bold(y1, tx)) return (FALSE);
165                         }
166                 }
167
168                 /* Assume los */
169                 return (TRUE);
170         }
171
172
173         /* Extract some signs */
174         sx = (dx < 0) ? -1 : 1;
175         sy = (dy < 0) ? -1 : 1;
176
177
178         /* Vertical "knights" */
179         if (ax == 1)
180         {
181                 if (ay == 2)
182                 {
183                         if (cave_floor_bold(y1 + sy, x1)) return (TRUE);
184                 }
185         }
186
187         /* Horizontal "knights" */
188         else if (ay == 1)
189         {
190                 if (ax == 2)
191                 {
192                         if (cave_floor_bold(y1, x1 + sx)) return (TRUE);
193                 }
194         }
195
196
197         /* Calculate scale factor div 2 */
198         f2 = (ax * ay);
199
200         /* Calculate scale factor */
201         f1 = f2 << 1;
202
203
204         /* Travel horizontally */
205         if (ax >= ay)
206         {
207                 /* Let m = dy / dx * 2 * (dy * dx) = 2 * dy * dy */
208                 qy = ay * ay;
209                 m = qy << 1;
210
211                 tx = x1 + sx;
212
213                 /* Consider the special case where slope == 1. */
214                 if (qy == f2)
215                 {
216                         ty = y1 + sy;
217                         qy -= f1;
218                 }
219                 else
220                 {
221                         ty = y1;
222                 }
223
224                 /* Note (below) the case (qy == f2), where */
225                 /* the LOS exactly meets the corner of a tile. */
226                 while (x2 - tx)
227                 {
228                         if (!cave_floor_bold(ty, tx)) return (FALSE);
229
230                         qy += m;
231
232                         if (qy < f2)
233                         {
234                                 tx += sx;
235                         }
236                         else if (qy > f2)
237                         {
238                                 ty += sy;
239                                 if (!cave_floor_bold(ty, tx)) return (FALSE);
240                                 qy -= f1;
241                                 tx += sx;
242                         }
243                         else
244                         {
245                                 ty += sy;
246                                 qy -= f1;
247                                 tx += sx;
248                         }
249                 }
250         }
251
252         /* Travel vertically */
253         else
254         {
255                 /* Let m = dx / dy * 2 * (dx * dy) = 2 * dx * dx */
256                 qx = ax * ax;
257                 m = qx << 1;
258
259                 ty = y1 + sy;
260
261                 if (qx == f2)
262                 {
263                         tx = x1 + sx;
264                         qx -= f1;
265                 }
266                 else
267                 {
268                         tx = x1;
269                 }
270
271                 /* Note (below) the case (qx == f2), where */
272                 /* the LOS exactly meets the corner of a tile. */
273                 while (y2 - ty)
274                 {
275                         if (!cave_floor_bold(ty, tx)) return (FALSE);
276
277                         qx += m;
278
279                         if (qx < f2)
280                         {
281                                 ty += sy;
282                         }
283                         else if (qx > f2)
284                         {
285                                 tx += sx;
286                                 if (!cave_floor_bold(ty, tx)) return (FALSE);
287                                 qx -= f1;
288                                 ty += sy;
289                         }
290                         else
291                         {
292                                 tx += sx;
293                                 qx -= f1;
294                                 ty += sy;
295                         }
296                 }
297         }
298
299         /* Assume los */
300         return (TRUE);
301 }
302
303
304
305
306 /*
307  * Returns true if the player's grid is dark
308  */
309 bool no_lite(void)
310 {
311         return (!player_can_see_bold(p_ptr->py, p_ptr->px));
312 }
313
314
315
316
317 /*
318  * Determine if a given location may be "destroyed"
319  *
320  * Used by destruction spells, and for placing stairs, etc.
321  */
322 bool cave_valid_bold(int y, int x)
323 {
324         object_type *o_ptr;
325
326         /* Forbid perma-grids */
327         if (cave_perma_bold(y, x)) return (FALSE);
328
329         /* Check objects */
330         for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr))
331         {
332                 /* Forbid artifact grids */
333                 if (artifact_p(o_ptr)) return (FALSE);
334         }
335
336         /* Accept */
337         return (TRUE);
338 }
339
340
341 /*
342  * Hack -- Hallucinatory monster
343  */
344 static u16b hallucinatory_monster(void)
345 {
346         monster_race *r_ptr;
347        
348         byte a;
349         char c;
350        
351         while (1)
352         {
353                 /* Select a random monster */
354                 r_ptr = &r_info[randint0(z_info->r_max)];
355                
356                 /* Skip non-entries */
357                 if (!r_ptr->name) continue;
358                
359                 /* Retrieve attr/char */
360                 a = r_ptr->x_attr;
361                 c = r_ptr->x_char;
362                
363                 /* Encode */
364                 return (PICT(a,c));
365         }
366 }
367
368
369 /*
370  * Hack -- Hallucinatory object
371  */
372 static u16b hallucinatory_object(void)
373 {
374         object_kind *k_ptr;
375        
376         byte a;
377         char c;
378        
379         while (1)
380         {
381                 /* Select a random object */
382                 k_ptr = &k_info[randint0(z_info->k_max - 1) + 1];
383                
384                 /* Skip non-entries */
385                 if (!k_ptr->name) continue;
386                
387                 /* Retrieve attr/char (HACK - without flavors) */
388                 a = k_ptr->x_attr;
389                 c = k_ptr->x_char;
390                
391                 /* HACK - Skip empty entries */
392                 if ((a == 0) || (c == 0)) continue;
393                
394                 /* Encode */
395                 return (PICT(a,c));
396         }
397 }
398
399
400
401 /*
402  * The 16x16 tile of the terrain supports lighting
403  */
404 bool feat_supports_lighting(int feat)
405 {
406         /* Pseudo graphics don't support lighting */
407         if (use_graphics == GRAPHICS_PSEUDO) return FALSE;
408
409         if ((use_graphics != GRAPHICS_DAVID_GERVAIS) &&
410             (feat >= FEAT_TRAP_HEAD) && (feat <= FEAT_TRAP_TAIL))
411         {
412                 return TRUE;
413         }
414
415         switch (feat)
416         {
417                 case FEAT_FLOOR:
418                 case FEAT_INVIS:
419                 case FEAT_SECRET:
420                 case FEAT_MAGMA:
421                 case FEAT_QUARTZ:
422                 case FEAT_MAGMA_H:
423                 case FEAT_QUARTZ_H:
424                 case FEAT_WALL_EXTRA:
425                 case FEAT_WALL_INNER:
426                 case FEAT_WALL_OUTER:
427                 case FEAT_WALL_SOLID:
428                 case FEAT_PERM_EXTRA:
429                 case FEAT_PERM_INNER:
430                 case FEAT_PERM_OUTER:
431                 case FEAT_PERM_SOLID:
432                         return TRUE;
433                 default:
434                         return FALSE;
435         }
436 }
437
438 /*
439  * This function modifies the attr/char pair for an empty floor space
440  * to reflect the various lighting options available.
441  *
442  * For text, this means changing the colouring for view_yellow_lite or
443  * view_bright_lite, and for graphics it means modifying the char to
444  * use a different tile in the tileset.  These modifications are different
445  * for different sets, depending on the tiles available, and their position
446  * in the set.
447  */
448 static void special_lighting_floor(byte *a, char *c, enum grid_light_level lighting, bool in_view)
449 {
450         /* The floor starts off "lit" - i.e. rendered in white or the default
451          * tile. */
452
453         if (lighting == LIGHT_TORCH && view_yellow_lite)
454         {
455                 /*
456                  * view_yellow_lite distinguishes between torchlit and
457                  * permanently-lit areas
458                  */
459                 switch (use_graphics)
460                 {
461                         case GRAPHICS_NONE:
462                         case GRAPHICS_PSEUDO:
463                                 /* Use "yellow" */
464                                 if (*a == TERM_WHITE) *a = TERM_YELLOW;
465                                 break;
466                         case GRAPHICS_ADAM_BOLT:
467                                 *c += 2;
468                                 break;
469                         case GRAPHICS_DAVID_GERVAIS:
470                                 *c -= 1;
471                                                 break;
472                 }
473         }
474         else if (lighting == LIGHT_DARK)
475         {
476                 /* Use a dark tile */
477                 switch (use_graphics)
478                 {
479                         case GRAPHICS_NONE:
480                         case GRAPHICS_PSEUDO:
481                                 /* Use "dark gray" */
482                                 if (*a == TERM_WHITE) *a = TERM_L_DARK;
483                                 break;
484                         case GRAPHICS_ADAM_BOLT:
485                         case GRAPHICS_DAVID_GERVAIS:
486                                 *c += 1;
487                                 break;
488                 }
489         }
490         else
491         {
492                 /*
493                  * view_bright_lite makes tiles that aren't in the "eyeline"
494                  * of the player show up dimmer than those that are.
495                  */
496                 if (view_bright_lite && !in_view)
497                 {
498                         switch (use_graphics)
499                         {
500                                 case GRAPHICS_NONE:
501                                 case GRAPHICS_PSEUDO:
502                                         /* Use "gray" */
503                                         if (*a == TERM_WHITE) *a = TERM_SLATE;
504                                         else if (*a == TERM_L_GREEN) *a = TERM_GREEN;
505                                         break;
506                                 case GRAPHICS_ADAM_BOLT:
507                                 case GRAPHICS_DAVID_GERVAIS:
508                                         *c += 1;
509                                         break;
510                         }
511                 }
512         }
513 }
514
515 /*
516  * This function modifies the attr/char pair for a wall (or other "interesting"
517  * grids to show them as more-or-less lit.  Note that how walls are drawn
518  * isn't directly related to how they are lit - walls are always "lit".
519  * The lighting effects we use are as a visual cue to emphasise blindness
520  * and to show field-of-view (view_bright_lite).
521  *
522  * For text, we change the attr and for graphics we modify the char to
523  * use a different tile in the tileset.  These modifications are different
524  * for different sets, depending on the tiles available, and their position
525  * in the set.
526  */
527 static void special_wall_display(byte *a, char *c, bool in_view, int feat)
528 {
529         /* Grids currently in view are left alone, rendered as "white" */
530         if (in_view) return;
531
532         /* When blind, we make walls and other "white" things dark */
533         if (p_ptr->timed[TMD_BLIND])
534         {
535                 switch (use_graphics)
536                 {
537                         case GRAPHICS_NONE:
538                         case GRAPHICS_PSEUDO:
539                                 /* Use "dark gray" */
540                                 if (*a == TERM_WHITE) *a = TERM_L_DARK;
541                                 break;
542                         case GRAPHICS_ADAM_BOLT:
543                         case GRAPHICS_DAVID_GERVAIS:
544                                 if (feat_supports_lighting(feat)) *c += 1;
545                                 break;
546                 }
547         }
548
549         /* Handle "view_bright_lite" by dimming walls not "in view" */
550         else if (view_bright_lite)
551         {
552                 switch (use_graphics)
553                 {
554                         case GRAPHICS_NONE:
555                         case GRAPHICS_PSEUDO:
556                                 /* Use "gray" */
557                                 if (*a == TERM_WHITE) *a = TERM_SLATE;
558                                 break;
559                         case GRAPHICS_ADAM_BOLT:
560                         case GRAPHICS_DAVID_GERVAIS:
561                                 if (feat_supports_lighting(feat)) *c += 1;
562                                 break;
563                 }
564         }
565         else
566         {
567                 /* Use a brightly lit tile */
568                 switch (use_graphics)
569                 {
570                         case GRAPHICS_ADAM_BOLT:
571                                 if (feat_supports_lighting(feat)) *c += 2;
572                                 break;
573                         case GRAPHICS_DAVID_GERVAIS:
574                                 if (feat_supports_lighting(feat)) *c -= 1;
575                                 break;
576                 }
577         }
578 }
579
580
581 /*
582  * Checks if a square is at the (inner) edge of a trap detect area
583  */
584 bool dtrap_edge(int y, int x)
585 {
586         /* Check if the square is a dtrap in the first place */
587         if (!cave_info2[y][x] & CAVE2_DTRAP) return FALSE;
588
589         /* Check for non-dtrap adjacent grids */
590         if (in_bounds_fully(y + 1, x    ) && (!cave_info2[y + 1][x    ] & CAVE2_DTRAP)) return TRUE;
591         if (in_bounds_fully(y    , x + 1) && (!cave_info2[y    ][x + 1] & CAVE2_DTRAP)) return TRUE;
592         if (in_bounds_fully(y - 1, x    ) && (!cave_info2[y - 1][x    ] & CAVE2_DTRAP)) return TRUE;
593         if (in_bounds_fully(y    , x - 1) && (!cave_info2[y    ][x - 1] & CAVE2_DTRAP)) return TRUE;
594
595         return FALSE;
596 }
597
598
599 /*
600  * This function takes a pointer to a grid info struct describing the
601  * contents of a grid location (as obtained through the function map_info)
602  * and fills in the character and attr pairs for display.
603  *
604  * ap and cp are filled with the attr/char pair for the monster, object or
605  * floor tile that is at the "top" of the grid (monsters covering objects,
606  * which cover floor, assuming all are present).
607  *
608  * tap and tcp are filled with the attr/char pair for the floor, regardless
609  * of what is on it.  This can be used by graphical displays with
610  * transparency to place an object onto a floor tile, is desired.
611  *
612  * Any lighting effects are also applied to these pairs, clear monsters allow
613  * the underlying colour or feature to show through (ATTR_CLEAR and
614  * CHAR_CLEAR), multi-hued colour-changing (ATTR_MULTI) is applied, and so on.
615  * Technically, the flag "CHAR_MULTI" is supposed to indicate that a monster
616  * looks strange when examined, but this flag is currently ignored.
617  *
618  * NOTES:
619  * This is called pretty frequently, whenever a grid on the map display
620  * needs updating, so don't overcomplicate it.
621  *
622  * The "zero" entry in the feature/object/monster arrays are
623  * used to provide "special" attr/char codes, with "monster zero" being
624  * used for the player attr/char, "object zero" being used for the "pile"
625  * attr/char, and "feature zero" being used for the "darkness" attr/char.
626  *
627  * TODO:
628  * The transformations for tile colors, or brightness for the 16x16
629  * tiles should be handled differently.  One possibility would be to
630  * extend feature_type with attr/char definitions for the different states.
631  * This will probably be done outside of the current text->graphics mappings
632  * though.
633  */
634 void grid_data_as_text(grid_data *g, byte *ap, char *cp, byte *tap, char *tcp)
635 {
636         byte a;
637         char c;
638        
639         feature_type *f_ptr = &f_info[g->f_idx];
640
641         /* Normal attr and char */
642         a = f_ptr->x_attr;
643         c = f_ptr->x_char;
644
645         /* Check for trap detection boundaries */
646         if (g->trapborder && g->f_idx == FEAT_FLOOR) a = TERM_L_GREEN;
647
648         /* Special lighting effects */
649         if (g->f_idx <= FEAT_INVIS && view_special_lite)
650                 special_lighting_floor(&a, &c, g->lighting, g->in_view);
651
652         /* Special lighting effects (walls only) */
653         if (g->f_idx > FEAT_INVIS && view_granite_lite)
654                 special_wall_display(&a, &c, g->in_view, g->f_idx);
655                
656         /* Save the terrain info for the transparency effects */
657         (*tap) = a;
658         (*tcp) = c;
659
660
661         /* If there's an object, deal with that. */
662         if (g->first_k_idx)
663         {
664                 if (g->hallucinate)
665                 {
666                         /* Just pick a random object to display. */
667                         int i = hallucinatory_object();
668                        
669                         a = PICT_A(i);
670                         c = PICT_C(i);
671                 }
672                 else
673                 {
674                         object_kind *k_ptr = &k_info[g->first_k_idx];
675                        
676                         /* Normal attr and char */
677                         a = object_kind_attr(g->first_k_idx);
678                         c = object_kind_char(g->first_k_idx);
679                        
680                         if (show_piles && g->multiple_objects)
681                         {
682                                 /* Get the "pile" feature instead */
683                                 k_ptr = &k_info[0];
684                                
685                                 a = k_ptr->x_attr;
686                                 c = k_ptr->x_char;
687                         }
688                 }
689         }
690
691         /* If there's a monster */
692         if (g->m_idx > 0)
693         {
694                 if (g->hallucinate)
695                 {
696                         /* Just pick a random monster to display. */
697                         int i = hallucinatory_monster();
698                        
699                         a = PICT_A(i);
700                         c = PICT_C(i);
701                 }
702                 else
703                 {
704                         monster_type *m_ptr = &mon_list[g->m_idx];
705                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
706                                
707                         byte da;
708                         char dc;
709                        
710                         /* Desired attr & char*/
711                         da = r_ptr->x_attr;
712                         dc = r_ptr->x_char;
713                        
714                         /* Special attr/char codes */
715                         if ((da & 0x80) && (dc & 0x80))
716                         {
717                                 /* Use attr */
718                                 a = da;
719                                
720                                 /* Use char */
721                                 c = dc;
722                         }
723                        
724                         /* Multi-hued monster */
725                         else if (r_ptr->flags[0] & (RF0_ATTR_MULTI))
726                         {
727                                 /* Multi-hued attr */
728                                 a = randint1(15);
729                                
730                                 /* Normal char */
731                                 c = dc;
732                         }
733                        
734                         /* Normal monster (not "clear" in any way) */
735                         else if (!(r_ptr->flags[0] & (RF0_ATTR_CLEAR | RF0_CHAR_CLEAR)))
736                         {
737                                 /* Use attr */
738                                 a = da;
739
740                                 /* Desired attr & char */
741                                 da = r_ptr->x_attr;
742                                 dc = r_ptr->x_char;
743                                
744                                 /* Use char */
745                                 c = dc;
746                         }
747                        
748                         /* Hack -- Bizarre grid under monster */
749                         else if ((a & 0x80) || (c & 0x80))
750                         {
751                                 /* Use attr */
752                                 a = da;
753                                
754                                 /* Use char */
755                                 c = dc;
756                         }
757                        
758                         /* Normal char, Clear attr, monster */
759                         else if (!(r_ptr->flags[0] & (RF0_CHAR_CLEAR)))
760                         {
761                                 /* Normal char */
762                                 c = dc;
763                         }
764                                
765                         /* Normal attr, Clear char, monster */
766                         else if (!(r_ptr->flags[0] & (RF0_ATTR_CLEAR)))
767                         {
768                                 /* Normal attr */
769                                         a = da;
770                         }
771                 }
772         }
773
774         /* Handle "player" */
775         else if (g->is_player)
776         {
777                 monster_race *r_ptr = &r_info[0];
778
779                 /* Get the "player" attr */
780                 a = r_ptr->x_attr;
781                 if ((hp_changes_color) && (arg_graphics == GRAPHICS_NONE))
782                 {
783                         switch(p_ptr->chp * 10 / p_ptr->mhp)
784                         {
785                                 case 10:
786                                 case  9:
787                                 {
788                                         a = TERM_WHITE;
789                                         break;
790                                 }
791                                 case  8:
792                                 case  7:
793                                 {
794                                         a = TERM_YELLOW;
795                                         break;
796                                 }
797                                 case  6:
798                                 case  5:
799                                 {
800                                         a = TERM_ORANGE;
801                                         break;
802                                 }
803                                 case  4:
804                                 case  3:
805                                 {
806                                         a = TERM_L_RED;
807                                         break;
808                                 }
809                                 case  2:
810                                 case  1:
811