Crossfire Server, Trunk
image.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <assert.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "image.h"
28 
29 #include "assets.h"
30 
36 
37 
45 static const char *const colorname[] = {
46  "black", /* 0 */
47  "white", /* 1 */
48  "blue", /* 2 */
49  "red", /* 3 */
50  "orange", /* 4 */
51  "light_blue", /* 5 */
52  "dark_orange", /* 6 */
53  "green", /* 7 */
54  "light_green", /* 8 */
55  "grey", /* 9 */
56  "brown", /* 10 */
57  "yellow", /* 11 */
58  "khaki" /* 12 */
59 };
60 
74 uint8_t find_color(const char *name) {
75  uint8_t i;
76 
77  for (i = 0; i < sizeof(colorname)/sizeof(*colorname); i++)
78  if (!strcmp(name, colorname[i]))
79  return i;
80 
81  LOG(llevError, "Unknown color: %s\n", name);
82  return 0;
83 }
84 
85 const char *get_colorname(uint8_t index) {
86  if (index < sizeof(colorname) / sizeof(*colorname)) {
87  return colorname[index];
88  }
89  return "";
90 }
91 
101 int find_smooth(const Face *face, const Face **smoothed) {
102  (*smoothed) = NULL;
103 
104  if (face && face->smoothface) {
105  (*smoothed) = face->smoothface;
106  return 1;
107  }
108 
109  return 0;
110 }
111 
116 int is_valid_faceset(int fsn) {
117  return find_faceset(fsn) != NULL;
118 }
119 
132 int get_face_fallback(int faceset, uint16_t imageno) {
133  /* faceset 0 is supposed to have every image, so just return. Doing
134  * so also prevents infinite loops in the case if it not having
135  * the face, but in that case, we are likely to crash when we try
136  * to access the data, but that is probably preferable to an infinite
137  * loop.
138  */
139 
140  face_sets *fs = find_faceset(faceset);
141  if (!fs || !fs->prefix) {
142  LOG(llevError, "get_face_fallback called with unused set (%d)?\n", faceset);
143  return 0; /* use default set */
144  }
145  if (imageno < fs->allocated && fs->faces[imageno].data)
146  return faceset;
147 
148  if (!fs->fallback) {
149  return 0;
150  }
151 
152  return get_face_fallback(fs->fallback->id, imageno);
153 }
154 
155 static void do_face(const Face *face) {
156  fprintf(stderr, "%5d %50s %50s\n", face->number, face->name, face->smoothface ? face->smoothface->name : "(none)");
157 }
158 
162 void dump_faces(void) {
163  fprintf(stderr, "id name smooth\n");
165 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
global.h
llevError
@ llevError
Definition: logger.h:11
get_colorname
const char * get_colorname(uint8_t index)
Definition: image.c:85
find_faceset
face_sets * find_faceset(int id)
Definition: assets.cpp:366
blank_face
const Face * blank_face
Definition: image.c:35
face_sets::id
int id
Definition: image.h:18
is_valid_faceset
int is_valid_faceset(int fsn)
Definition: image.c:116
face_sets::prefix
char * prefix
Definition: image.h:19
do_face
static void do_face(const Face *face)
Definition: image.c:155
Face::number
uint16_t number
Definition: face.h:15
empty_face
const Face * empty_face
Definition: image.c:35
face_info::data
uint8_t * data
Definition: image.h:11
Face::smoothface
struct Face * smoothface
Definition: face.h:18
image.h
face_sets::fallback
struct face_sets * fallback
Definition: image.h:21
find_color
uint8_t find_color(const char *name)
Definition: image.c:74
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
get_face_fallback
int get_face_fallback(int faceset, uint16_t imageno)
Definition: image.c:132
colorname
static const char *const colorname[]
Definition: image.c:45
assets.h
npc_dialog.index
int index
Definition: npc_dialog.py:102
faces_for_each
void faces_for_each(face_op op)
Definition: assets.cpp:323
find_smooth
int find_smooth(const Face *face, const Face **smoothed)
Definition: image.c:101
face_sets
Definition: image.h:17
face_sets::faces
face_info * faces
Definition: image.h:26
smooth_face
const Face * smooth_face
Definition: image.c:35
dump_faces
void dump_faces(void)
Definition: image.c:162
give.name
name
Definition: give.py:27