File diff r10959:4b345c618e31 → r10960:e97ebf9cf99b
src/newgrf_townname.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file newgrf_townname.cpp
 
 * Implementation of  Action 0F "universal holder" structure and functions.
 
 * This file implements a linked-lists of townname generators,
 
 * holding everything that the newgrf action 0F will send over to OpenTTD.
 
 */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "newgrf_townname.h"
 
#include "core/alloc_func.hpp"
 
#include "string_func.h"
 

	
 
#include "table/strings.h"
 

	
 
static GRFTownName *_grf_townnames = NULL;
 

	
 
GRFTownName *GetGRFTownName(uint32 grfid)
 
{
 
	GRFTownName *t = _grf_townnames;
 
	for (; t != NULL; t = t->next) {
 
		if (t->grfid == grfid) return t;
 
	}
 
	return NULL;
 
}
 

	
 
GRFTownName *AddGRFTownName(uint32 grfid)
 
{
 
	GRFTownName *t = GetGRFTownName(grfid);
 
	if (t == NULL) {
 
		t = CallocT<GRFTownName>(1);
 
		t->grfid = grfid;
 
		t->next = _grf_townnames;
 
		_grf_townnames = t;
 
	}
 
	return t;
 
}
 

	
 
void DelGRFTownName(uint32 grfid)
 
{
 
	GRFTownName *t = _grf_townnames;
 
	GRFTownName *p = NULL;
 
	for (;t != NULL; p = t, t = t->next) if (t->grfid == grfid) break;
 
	if (t != NULL) {
 
		for (int i = 0; i < 128; i++) {
 
			for (int j = 0; j < t->nbparts[i]; j++) {
 
				for (int k = 0; k < t->partlist[i][j].partcount; k++) {
 
					if (!HasBit(t->partlist[i][j].parts[k].prob, 7)) free(t->partlist[i][j].parts[k].data.text);
 
				}
 
				free(t->partlist[i][j].parts);
 
			}
 
			free(t->partlist[i]);
 
		}
 
		if (p != NULL) {
 
			p->next = t->next;
 
		} else {
 
			_grf_townnames = t->next;
 
		}
 
		free(t);
 
	}
 
}
 

	
 
static char *RandomPart(char *buf, GRFTownName *t, uint32 seed, byte id, const char *last)