~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/ai/api/ai_sign.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ai_sign.cpp 15299 2009-01-31 20:16:06Z smatz $ */
 
2
 
 
3
/** @file ai_sign.cpp Implementation of AISign. */
 
4
 
 
5
#include "ai_sign.hpp"
 
6
#include "table/strings.h"
 
7
#include "../ai_instance.hpp"
 
8
#include "../../command_func.h"
 
9
#include "../../core/alloc_func.hpp"
 
10
#include "../../signs_base.h"
 
11
#include "../../string_func.h"
 
12
#include "../../strings_func.h"
 
13
#include "../../tile_map.h"
 
14
#include "../../company_func.h"
 
15
 
 
16
/* static */ SignID AISign::GetMaxSignID()
 
17
{
 
18
        return ::GetMaxSignIndex();
 
19
}
 
20
 
 
21
/* static */ bool AISign::IsValidSign(SignID sign_id)
 
22
{
 
23
        return ::IsValidSignID(sign_id) && ::GetSign(sign_id)->owner == _current_company;
 
24
}
 
25
 
 
26
/* static */ bool AISign::SetName(SignID sign_id, const char *name)
 
27
{
 
28
        EnforcePrecondition(false, IsValidSign(sign_id));
 
29
        EnforcePrecondition(false, !::StrEmpty(name));
 
30
        EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_SIGN_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
 
31
 
 
32
        return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name);
 
33
}
 
34
 
 
35
/* static */ char *AISign::GetName(SignID sign_id)
 
36
{
 
37
        if (!IsValidSign(sign_id)) return NULL;
 
38
 
 
39
        static const int len = 64;
 
40
        char *sign_name = MallocT<char>(len);
 
41
 
 
42
        ::SetDParam(0, sign_id);
 
43
        ::GetString(sign_name, STR_SIGN_NAME, &sign_name[len - 1]);
 
44
 
 
45
        return sign_name;
 
46
}
 
47
 
 
48
/* static */ TileIndex AISign::GetLocation(SignID sign_id)
 
49
{
 
50
        if (!IsValidSign(sign_id)) return INVALID_TILE;
 
51
 
 
52
        const Sign *sign = ::GetSign(sign_id);
 
53
        return ::TileVirtXY(sign->x, sign->y);
 
54
}
 
55
 
 
56
/* static */ bool AISign::RemoveSign(SignID sign_id)
 
57
{
 
58
        EnforcePrecondition(false, IsValidSign(sign_id));
 
59
        return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, "");
 
60
}
 
61
 
 
62
/* static */ SignID AISign::BuildSign(TileIndex location, const char *text)
 
63
{
 
64
        EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
 
65
        EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text));
 
66
        EnforcePreconditionCustomError(false, ::strlen(text) < MAX_LENGTH_SIGN_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
 
67
 
 
68
        if (!AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN;
 
69
 
 
70
        /* In case of test-mode, we return SignID 0 */
 
71
        return 0;
 
72
}