src/newgrf_config.cpp
changeset 6956 3579bfc5157b
parent 6929 56470c1b8a66
child 6967 73135cd741de
equal deleted inserted replaced
6955:da3431cb25a9 6956:3579bfc5157b
   122 
   122 
   123 
   123 
   124 /** Copy a GRF Config list
   124 /** Copy a GRF Config list
   125  * @param dst pointer to destination list
   125  * @param dst pointer to destination list
   126  * @param src pointer to source list values
   126  * @param src pointer to source list values
       
   127  * @param init_only the copied GRF will be processed up to GLS_INIT
   127  * @return pointer to the last value added to the destination list */
   128  * @return pointer to the last value added to the destination list */
   128 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
   129 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
   129 {
   130 {
   130 	/* Clear destination as it will be overwritten */
   131 	/* Clear destination as it will be overwritten */
   131 	ClearGRFConfigList(dst);
   132 	ClearGRFConfigList(dst);
   132 	for (; src != NULL; src = src->next) {
   133 	for (; src != NULL; src = src->next) {
   133 		GRFConfig *c = CallocT<GRFConfig>(1);
   134 		GRFConfig *c = CallocT<GRFConfig>(1);
   141 			memcpy(c->error, src->error, sizeof(GRFError));
   142 			memcpy(c->error, src->error, sizeof(GRFError));
   142 			if (src->error->data != NULL) c->error->data = strdup(src->error->data);
   143 			if (src->error->data != NULL) c->error->data = strdup(src->error->data);
   143 			if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
   144 			if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
   144 		}
   145 		}
   145 
   146 
       
   147 		if (init_only) SETBIT(c->flags, GCF_INIT_ONLY);
       
   148 
   146 		*dst = c;
   149 		*dst = c;
   147 		dst = &c->next;
   150 		dst = &c->next;
   148 	}
   151 	}
   149 
   152 
   150 	return dst;
   153 	return dst;
   188 void AppendStaticGRFConfigs(GRFConfig **dst)
   191 void AppendStaticGRFConfigs(GRFConfig **dst)
   189 {
   192 {
   190 	GRFConfig **tail = dst;
   193 	GRFConfig **tail = dst;
   191 	while (*tail != NULL) tail = &(*tail)->next;
   194 	while (*tail != NULL) tail = &(*tail)->next;
   192 
   195 
   193 	CopyGRFConfigList(tail, _grfconfig_static);
   196 	CopyGRFConfigList(tail, _grfconfig_static, false);
   194 	RemoveDuplicatesFromGRFConfigList(*dst);
   197 	RemoveDuplicatesFromGRFConfigList(*dst);
   195 }
   198 }
   196 
   199 
   197 /** Appends an element to a list of GRFs
   200 /** Appends an element to a list of GRFs
   198  * @param dst the head of the list to add to
   201  * @param dst the head of the list to add to
   208 
   211 
   209 
   212 
   210 /* Reset the current GRF Config to either blank or newgame settings */
   213 /* Reset the current GRF Config to either blank or newgame settings */
   211 void ResetGRFConfig(bool defaults)
   214 void ResetGRFConfig(bool defaults)
   212 {
   215 {
   213 	GRFConfig **c = &_grfconfig;
   216 	CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults);
   214 
       
   215 	if (defaults) {
       
   216 		c = CopyGRFConfigList(c, _grfconfig_newgame);
       
   217 	} else {
       
   218 		ClearGRFConfigList(c);
       
   219 	}
       
   220 
       
   221 	AppendStaticGRFConfigs(&_grfconfig);
   217 	AppendStaticGRFConfigs(&_grfconfig);
   222 }
   218 }
   223 
   219 
   224 
   220 
   225 /** Check if all GRFs in the GRF config from a savegame can be loaded.
   221 /** Check if all GRFs in the GRF config from a savegame can be loaded.