(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for

dynamic arrays
This commit is contained in:
truelight
2005-01-12 11:21:28 +00:00
parent ff23795f5b
commit a243285af4
17 changed files with 309 additions and 160 deletions

View File

@@ -172,89 +172,6 @@ int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return 0;
}
static void UpdateSignVirtCoords(SignStruct *ss)
{
Point pt = RemapCoords(ss->x, ss->y, ss->z);
SetDParam(0, ss->str);
UpdateViewportSignPos(&ss->sign, pt.x, pt.y - 6, STR_2806);
}
void UpdateAllSignVirtCoords()
{
SignStruct *ss;
for(ss=_sign_list; ss != endof(_sign_list); ss++)
if (ss->str != 0)
UpdateSignVirtCoords(ss);
}
static void MarkSignDirty(SignStruct *ss)
{
MarkAllViewportsDirty(
ss->sign.left-6,
ss->sign.top-3,
ss->sign.left+ss->sign.width_1*4+12,
ss->sign.top + 45
);
}
int32 CmdPlaceSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
SignStruct *ss;
for(ss=_sign_list; ss != endof(_sign_list); ss++) {
if (ss->str == 0) {
if (flags & DC_EXEC) {
ss->str = STR_280A_SIGN;
ss->x = x;
ss->y = y;
ss->z = GetSlopeZ(x,y);
UpdateSignVirtCoords(ss);
MarkSignDirty(ss);
_new_sign_struct = ss;
}
return 0;
}
}
return_cmd_error(STR_2808_TOO_MANY_SIGNS);
}
// p1 = sign index
// p2: 1 -> remove sign
int32 CmdRenameSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
StringID str,old_str;
SignStruct *ss;
if (_decode_parameters[0] != 0 && !p2) {
str = AllocateNameUnique((byte*)_decode_parameters, 0);
if (str == 0)
return CMD_ERROR;
if (flags & DC_EXEC) {
ss = &_sign_list[p1];
MarkSignDirty(ss);
DeleteName(ss->str);
ss->str = str;
UpdateSignVirtCoords(ss);
MarkSignDirty(ss);
} else {
DeleteName(str);
}
} else {
if (flags & DC_EXEC) {
ss = &_sign_list[p1];
old_str = ss->str;
ss->str = 0;
DeleteName(old_str);
MarkSignDirty(ss);
}
}
return 0;
}
// p1 = 0 decrease pause counter
// p1 = 1 increase pause counter
int32 CmdPause(int x, int y, uint32 flags, uint32 p1, uint32 p2)
@@ -318,39 +235,3 @@ int32 CmdChangeDifficultyLevel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
return 0;
}
static const byte _sign_desc[] = {
SLE_VAR(SignStruct,str, SLE_UINT16),
SLE_CONDVAR(SignStruct,x, SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
SLE_CONDVAR(SignStruct,y, SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
SLE_CONDVAR(SignStruct,x, SLE_INT32, 5, 255),
SLE_CONDVAR(SignStruct,y, SLE_INT32, 5, 255),
SLE_VAR(SignStruct,z, SLE_UINT8),
SLE_END()
};
static void Save_SIGN()
{
SignStruct *s;
int i;
for(i=0,s=_sign_list; i!=lengthof(_sign_list); i++,s++) {
if (s->str != 0) {
SlSetArrayIndex(i);
SlObject(s, _sign_desc);
}
}
}
static void Load_SIGN()
{
int index;
while ((index = SlIterateArray()) != -1) {
SlObject(&_sign_list[index], _sign_desc);
}
}
const ChunkHandler _sign_chunk_handlers[] = {
{ 'SIGN', Save_SIGN, Load_SIGN, CH_ARRAY | CH_LAST},
};