|
| 1 | +// Cortex SC2 Roleplaying Engine |
| 2 | +// Copyright (C) 2009-2011 <http://www.cortexrp.com/> |
| 3 | +// |
| 4 | +// This program is free software; you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation; version 2 of the License. |
| 7 | +// |
| 8 | +// This program is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
| 12 | + |
| 13 | +const int c_cortexMaxLoggedCommands = 25; |
| 14 | + |
| 15 | +string[libcrtx_max_players][c_cortexMaxLoggedCommands] libcrtx_log_perplayerlog; |
| 16 | +string[c_cortexMaxLoggedCommands] libcrtx_log_globallog; |
| 17 | +int[c_cortexMaxLoggedCommands] libcrtx_log_globallogplayers; |
| 18 | + |
| 19 | +static void libcrtx_log_event_individual(int player, string message) |
| 20 | +{ |
| 21 | + int currentLevel = 0; |
| 22 | + |
| 23 | + // Find free index and insert, if possible |
| 24 | + while(currentLevel < c_cortexMaxLoggedCommands) |
| 25 | + { |
| 26 | + if( libcrtx_log_perplayerlog[player][currentLevel] == "" ) { |
| 27 | + libcrtx_log_perplayerlog[player][currentLevel] = message; |
| 28 | + return; |
| 29 | + } |
| 30 | + currentLevel += 1; |
| 31 | + } |
| 32 | + |
| 33 | + // We're out of space! Discard one message and move the rest upward one level, and use last index. |
| 34 | + currentLevel = 1; |
| 35 | + while(currentLevel < c_cortexMaxLoggedCommands) |
| 36 | + { |
| 37 | + libcrtx_log_perplayerlog[player][currentLevel - 1] = libcrtx_log_perplayerlog[player][currentLevel]; |
| 38 | + currentLevel += 1; |
| 39 | + } |
| 40 | + libcrtx_log_perplayerlog[player][c_cortexMaxLoggedCommands - 1] = message; |
| 41 | +} |
| 42 | + |
| 43 | +static void libcrtx_log_event_global(int player, string message) |
| 44 | +{ |
| 45 | + int currentLevel = 0; |
| 46 | + |
| 47 | + // Find free index and insert, if possible |
| 48 | + while(currentLevel < c_cortexMaxLoggedCommands) |
| 49 | + { |
| 50 | + if( libcrtx_log_globallog[currentLevel] == "" ) { |
| 51 | + libcrtx_log_globallog[currentLevel] = message; |
| 52 | + libcrtx_log_globallogplayers[currentLevel] = player; |
| 53 | + return; |
| 54 | + } |
| 55 | + currentLevel += 1; |
| 56 | + } |
| 57 | + |
| 58 | + // We're out of space! Discard one message and move the rest upward one level, and use last index. |
| 59 | + currentLevel = 1; |
| 60 | + while(currentLevel < c_cortexMaxLoggedCommands) |
| 61 | + { |
| 62 | + libcrtx_log_globallog[currentLevel - 1] = libcrtx_log_globallog[currentLevel]; |
| 63 | + currentLevel += 1; |
| 64 | + } |
| 65 | + libcrtx_log_globallog[c_cortexMaxLoggedCommands - 1] = message; |
| 66 | + libcrtx_log_globallogplayers[c_cortexMaxLoggedCommands - 1] = player; |
| 67 | +} |
| 68 | + |
| 69 | +void libcrtx_log_event(int player, string message) |
| 70 | +{ |
| 71 | + libcrtx_log_event_individual(player, message); |
| 72 | + libcrtx_log_event_global(player, message); |
| 73 | +} |
| 74 | + |
| 75 | +text libcrtx_log_getlog(int player) |
| 76 | +{ |
| 77 | + text ret = StringToText(libcrtx_log_perplayerlog[player][0]); |
| 78 | + int i = 1; |
| 79 | + while(i < c_cortexMaxLoggedCommands) |
| 80 | + { |
| 81 | + if( libcrtx_log_perplayerlog[player][i] != "" ) |
| 82 | + { |
| 83 | + ret += StringToText("<n />") + libcrtx_colored_player_name(player) + StringToText(": " + libcrtx_log_perplayerlog[player][i]); |
| 84 | + } |
| 85 | + i += 1; |
| 86 | + } |
| 87 | + return ret; |
| 88 | +} |
| 89 | + |
| 90 | +text libcrtx_log_getgloballog() |
| 91 | +{ |
| 92 | + text ret = StringToText(libcrtx_log_globallog[0]); |
| 93 | + int i = 1; |
| 94 | + while(i < c_cortexMaxLoggedCommands) |
| 95 | + { |
| 96 | + if( libcrtx_log_globallog[i] != "" ) |
| 97 | + { |
| 98 | + ret += StringToText("<n />") + libcrtx_colored_player_name(libcrtx_log_globallogplayers[i]) + StringToText(": " + libcrtx_log_globallog[i]); |
| 99 | + } |
| 100 | + i += 1; |
| 101 | + } |
| 102 | + return ret; |
| 103 | +} |
0 commit comments