1 float COLOR_TEAM1 = 5; // red
2 float COLOR_TEAM2 = 14; // blue
3 float COLOR_TEAM3 = 10; // pink
4 float COLOR_TEAM4 = 13; // yellow
7 float GAME_DEATHMATCH = 1;
8 float GAME_TEAM_DEATHMATCH = 2;
9 float GAME_DOMINATION = 3;
11 float GAME_RUNEMATCH = 5;
15 // client counts for each team
17 // # of bots on those teams
18 float cb1, cb2, cb3, cb4;
20 float g_domination, g_ctf, g_tdm;
22 float audit_teams_time;
25 string TeamName(float t)
27 // fixme: Search for team entities and get their .netname's!
36 return "Neutral Team";
38 string ColoredTeamName(float t)
40 // fixme: Search for team entities and get their .netname's!
42 return "^1Red Team^7";
44 return "^4Blue Team^7";
46 return "^6Pink Team^7";
48 return "^3Yellow Team^7";
49 return "Neutral Team";
51 string TeamNoName(float t)
53 // fixme: Search for team entities and get their .netname's!
62 return "Neutral Team";
67 void runematch_init();
70 void(entity pl) LogTeamchange =
73 if(!cvar("sv_logspam_console"))
75 str = strcat(":team:", ftos(pl.playerid), ":");
76 str = strcat(str, ftos(pl.team));
77 ServerConsoleEcho(str);
82 cvar_set("g_tdm", "0");
83 cvar_set("g_domination", "0");
84 cvar_set("g_ctf", "0");
85 cvar_set("g_runematch", "0");
86 cvar_set("g_lms", "0");
87 cvar_set("teamplay", "0");
90 cvar_set("exit_cfg", "");
93 void ActivateTeamplay()
95 float teamplay_default;
96 teamplay_default = cvar("teamplay_default");
99 cvar_set("teamplay", ftos(teamplay_default));
101 cvar_set("teamplay", "3");
104 string gamemode_name;
107 void InitGameplayMode()
109 float fraglimit_override, timelimit_override;
113 game = cvar ("gamecfg"); // load game options
115 // game cvars get reset before map changes
116 // then map's cfg sets them as desired
118 // FIXME: also set a message or game mode name to print to players when the join
120 // set both here, gamemode can override it later
121 timelimit_override = cvar("timelimit_override");
122 fraglimit_override = cvar("fraglimit_override");
124 if(game == GAME_DOMINATION || cvar("g_domination"))
126 game = GAME_DOMINATION;
127 cvar_set("g_domination", "1");
131 fraglimit_override = cvar("g_domination_point_limit");
133 gamemode_name = "Domination";
136 else if(game == GAME_CTF || cvar("g_ctf"))
139 cvar_set("g_ctf", "1");
143 fraglimit_override = cvar("g_ctf_capture_limit");
145 gamemode_name = "Capture the Flag";
148 else if((game == GAME_RUNEMATCH || cvar("g_runematch")) && !cvar("g_minstagib"))
150 game = GAME_RUNEMATCH;
151 cvar_set("g_runematch", "1");
153 if(cvar("deathmatch_force_teamplay"))
156 fraglimit_override = cvar("g_runematch_point_limit");
158 gamemode_name = "Rune Match";
164 else if(game == GAME_DEATHMATCH || game == GAME_TEAM_DEATHMATCH || cvar("g_tdm"))
166 if(!cvar("deathmatch"))
167 cvar_set("deathmatch", "1");
170 if(game == GAME_TEAM_DEATHMATCH || cvar("g_tdm") || cvar("deathmatch_force_teamplay"))
172 game = GAME_TEAM_DEATHMATCH;
173 gamemode_name = "Team Deathmatch";
176 cvar_set("g_tdm", "1");
180 game = GAME_DEATHMATCH;
181 gamemode_name = "Deathmatch";
185 fraglimit_override = cvar("fraglimit_override");
187 else if(game == GAME_LMS || cvar("g_lms"))
190 cvar_set("g_lms", "1");
191 fraglimit_override = cvar("g_lms_lives_override");
192 if(fraglimit_override == 0)
193 fraglimit_override = -1;
194 gamemode_name = "Last Man Standing";
196 cvar_set("teamplay", "0");
197 lms_lowest_lives = 999;
201 // we can only assume...
202 gamemode_name = "Deathmatch";
205 /* else if(game == GAME_TEAM_DEATHMATCH)
207 if(!cvar("deathmatch"))
208 cvar_set("deathmatch", "1");
210 //if(!cvar("teamplay"))
211 // cvar_set("teamplay", "3");
214 fraglimit_override = cvar("fraglimit_override");
217 // enforce the server's universal frag/time limits
218 if(fraglimit_override >= 0)
219 cvar_set("fraglimit", ftos(fraglimit_override));
220 if(timelimit_override >= 0)
221 cvar_set("timelimit", ftos(timelimit_override));
223 if (game == GAME_DOMINATION)//cvar("g_domination"))
225 else if (game == GAME_CTF)//cvar("g_ctf"))
227 else if (game == GAME_RUNEMATCH)//cvar("g_runematch"))
229 else if (game == GAME_TEAM_DEATHMATCH)//cvar("g_runematch"))
232 // those mutators rule each other out
233 if(cvar("g_minstagib"))
235 cvar_set("g_instagib", "0");
236 cvar_set("g_rocketarena", "0");
238 if(cvar("g_instagib"))
240 cvar_set("g_minstagib", "0");
241 cvar_set("g_rocketarena", "0");
243 if(cvar("g_rocketarena"))
245 cvar_set("g_instagib", "0");
246 cvar_set("g_minstagib", "0");
249 registercvar("_motd", "");
250 registercvar("_mutatormsg", "");
251 cvar_set("_motd", linewrap(cvar_string("sv_motd"), 50));
252 cvar_set("_mutatormsg", linewrap(cvar_string("g_mutatormsg"), 50));
255 string GetClientVersionMessage(float v) {
256 local string versionmsg;
258 versionmsg = "^1client is too old to get versioninfo.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nUPDATE!!! (http://www.nexuiz.com)^8";
259 // either that or someone wants to be funny
260 } else if (v != cvar("gameversion")) {
261 if(v < cvar("gameversion")) {
262 versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
264 versionmsg = "^3This server is using an outdated Nexuiz version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
267 versionmsg = "^2client version and server version are compatible.^8";
269 return strzone(versionmsg);
274 void PrintWelcomeMessage(entity pl)
276 string s, mutator, modifications;
278 /*if(self.welcomemessage_time < time)
280 if(self.welcomemessage_time2 > time)
282 self.welcomemessage_time2 = time + 0.8; */
284 if(self.welcomemessage_time2 > time) return;
285 self.welcomemessage_time2 = time + 1.0;
287 if(cvar("g_minstagib"))
288 mutator = "^2Minstagib ^1";
289 else if(cvar("g_instagib"))
290 mutator = "^2Instagib ^1";
291 else if(cvar("g_rocketarena"))
292 mutator = "^2Rocketarena ^1";
294 if(cvar("g_midair")) {
295 // to protect against unheedingly made changes
297 modifications = strcat(modifications, ", ");
299 modifications = "midair";
301 if(cvar("g_vampire")) {
303 modifications = strcat(modifications, ", ");
305 modifications = strcat(modifications, "vampire");
307 if(cvar("g_laserguided_missile")) {
309 modifications = strcat(modifications, ", ");
311 modifications = strcat(modifications, "laser-guided-missiles");
314 local string versionmessage;
315 versionmessage = GetClientVersionMessage(self.version);
317 s = strcat(s, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThis is Nexuiz ", cvar_string("g_nexuizversion"), "\n", versionmessage);
318 s = strcat(s, "^8\n\nmatch type is ^1", mutator, gamemode_name, "^8\n");
320 if(modifications != "")
321 s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
323 if((self.classname == "observer" || self.classname == "spectator") && self.version == cvar("gameversion")) {
324 s = strcat(s,"^7\n\n\npress jump to play\npress attack to spectate other players\n\n");
330 if (cvar("g_grappling_hook"))
331 s = strcat(s, "\n\n^8grappling hook is enabled, press 'e' to use it\n");
333 if (cvar_string("_mutatormsg") != "") {
334 s = strcat(s, "\n\n^8special gameplay tips: ^7", cvar_string("_mutatormsg"));
337 if (cvar_string("_motd") != "") {
338 s = strcat(s, "\n\n^8MOTD: ^7", cvar_string("_motd"));
350 void SetPlayerColors(entity pl, float _color)
354 stuffcmd(pl, strcat("color ", s, " ", s, "\n") );
356 //pl.clientcolors = pl.clientcolors - (pl.clientcolors & 15) + cl;
357 pl.clientcolors = 16*cl + cl;*/
360 pants = _color & 0x0F;
361 shirt = _color & 0xF0;
365 setcolor(pl, 16*pants + pants);
367 setcolor(pl, shirt + pants);
371 void SetPlayerTeam(entity pl, float t, float s, float noprint)
376 _color = COLOR_TEAM4 - 1;
378 _color = COLOR_TEAM3 - 1;
380 _color = COLOR_TEAM2 - 1;
382 _color = COLOR_TEAM1 - 1;
384 SetPlayerColors(pl,_color);
386 if(!noprint && t != s)
388 //bprint(strcat(pl.netname, " has changed to ", TeamNoName(t), "\n"));
389 bprint(strcat(pl.netname, "^7 has changed from ", TeamNoName(s), " to ", TeamNoName(t), "\n"));
401 // set c1...c4 to show what teams are allowed
402 void CheckAllowedTeams ()
411 c1 = c2 = c3 = c4 = -1;
412 cb1 = cb2 = cb3 = cb4 = 0;
415 teament_name = "dom_team";
417 teament_name = "ctf_team";
419 teament_name = "tdm_team";
422 // cover anything else by treating it like tdm with no teams spawned
423 dm = cvar("g_tdm_teams");
425 error("g_tdm_teams < 2, not enough teams to play team deathmatch\n");
429 c1 = c2 = c3 = c4 = 0;
442 // first find out what teams are allowed
443 head = find(world, classname, teament_name);
446 if(!(g_domination && head.netname == ""))
448 if(head.team == COLOR_TEAM1)
452 if(head.team == COLOR_TEAM2)
456 if(head.team == COLOR_TEAM3)
460 if(head.team == COLOR_TEAM4)
465 head = find(head, classname, teament_name);
469 // c1...c4 should be set to -1 (not allowed) or 0 (allowed).
470 // teams that are allowed will now have their player counts stored in c1...c4
471 void GetTeamCounts(entity ignore)
474 // now count how many players are on each team already
476 // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
477 // also remember the lowest-scoring player
479 head = find(world, classname, "player");
482 if(head != ignore)// && head.netname != "")
484 if(head.team == COLOR_TEAM1)
492 if(head.team == COLOR_TEAM2)
500 if(head.team == COLOR_TEAM3)
508 if(head.team == COLOR_TEAM4)
517 head = find(head, classname, "player");
521 // returns # of smallest team (1, 2, 3, 4)
522 // NOTE: Assumes CheckAllowedTeams has already been called!
523 float FindSmallestTeam(entity pl, float ignore_pl)
525 float totalteams, smallestteam, smallestteam_count, balance_type;
528 // find out what teams are available
529 //CheckAllowedTeams();
531 // make sure there are at least 2 teams to join
533 totalteams = totalteams + 1;
535 totalteams = totalteams + 1;
537 totalteams = totalteams + 1;
539 totalteams = totalteams + 1;
544 error("Too few teams available for domination\n");
546 error("Too few teams available for ctf\n");
548 error("Too few teams available for team deathmatch\n");
552 // count how many players are in each team
554 GetTeamCounts(world);
560 // c1...c4 now have counts of each team
561 // figure out which is smallest, giving priority to the team the player is already on as a tie-breaker
564 smallestteam_count = 999;
566 // 2 gives priority to what team you're already on, 1 goes in order
567 // 2 doesn't seem to work though...
570 if(balance_type == 1)
572 if(c1 >= 0 && c1 < smallestteam_count)
575 smallestteam_count = c1;
577 if(c2 >= 0 && c2 < smallestteam_count)
580 smallestteam_count = c2;
582 if(c3 >= 0 && c3 < smallestteam_count)
585 smallestteam_count = c3;
587 if(c4 >= 0 && c4 < smallestteam_count)
590 smallestteam_count = c4;
595 if(c1 >= 0 && (c1 < smallestteam_count ||
596 (c1 == smallestteam_count && self.team == COLOR_TEAM1) ) )
599 smallestteam_count = c1;
601 if(c2 >= 0 && c2 < (c2 < smallestteam_count ||
602 (c2 == smallestteam_count && self.team == COLOR_TEAM2) ) )
605 smallestteam_count = c2;
607 if(c3 >= 0 && c3 < (c3 < smallestteam_count ||
608 (c3 == smallestteam_count && self.team == COLOR_TEAM3) ) )
611 smallestteam_count = c3;
613 if(c4 >= 0 && c4 < (c4 < smallestteam_count ||
614 (c4 == smallestteam_count && self.team == COLOR_TEAM4) ) )
617 smallestteam_count = c4;
624 float JoinBestTeam(entity pl, float only_return_best)
626 float smallest, selectedteam;
628 g_domination = cvar("g_domination");
629 g_ctf = cvar("g_ctf");
631 // don't join a team if we're not playing a team game
632 if(!cvar("teamplay") && !g_domination && !g_ctf)
635 // find out what teams are available
639 if(cvar("g_domination"))
641 if(cvar("g_domination_default_teams") < 3)
643 if(cvar("g_domination_default_teams") < 4)
647 // if we don't care what team he ends up on, put him on whatever team he entered as.
648 // if he's not on a valid team, then let other code put him on the smallest team
649 if(!cvar("g_balance_teams") && !cvar("g_balance_teams_force"))
651 if( c1 >= 0 && pl.team == COLOR_TEAM1)
652 selectedteam = pl.team;
653 else if(c2 >= 0 && pl.team == COLOR_TEAM2)
654 selectedteam = pl.team;
655 else if(c3 >= 0 && pl.team == COLOR_TEAM3)
656 selectedteam = pl.team;
657 else if(c4 >= 0 && pl.team == COLOR_TEAM4)
658 selectedteam = pl.team;
663 if(!only_return_best)
665 SetPlayerColors(pl, selectedteam - 1);
670 // otherwise end up on the smallest team (handled below)
673 smallest = FindSmallestTeam(pl, TRUE);
676 if(!only_return_best)
680 SetPlayerColors(pl, COLOR_TEAM1 - 1);
682 else if(smallest == 2)
684 SetPlayerColors(pl, COLOR_TEAM2 - 1);
686 else if(smallest == 3)
688 SetPlayerColors(pl, COLOR_TEAM3 - 1);
690 else if(smallest == 4)
692 SetPlayerColors(pl, COLOR_TEAM4 - 1);
696 error("smallest team: invalid team\n");
699 if(pl.deadflag == DEAD_NO)
700 Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
707 void SV_ChangeTeam(float _color)
709 float scolor, dcolor, steam, dteam, dbotcount, scount, dcount;
711 // in normal deathmatch we can just apply the color and we're done
712 if(!cvar("teamplay")) {
713 SetPlayerColors(self, _color);
717 scolor = self.clientcolors & 0x0F;
718 dcolor = _color & 0x0F;
720 if(scolor == COLOR_TEAM1 - 1)
722 else if(scolor == COLOR_TEAM2 - 1)
724 else if(scolor == COLOR_TEAM3 - 1)
726 else if(scolor == COLOR_TEAM4 - 1)
728 if(dcolor == COLOR_TEAM1 - 1)
730 else if(dcolor == COLOR_TEAM2 - 1)
732 else if(dcolor == COLOR_TEAM3 - 1)
734 else if(dcolor == COLOR_TEAM4 - 1)
737 // remap invalid teams in dom & ctf
738 if(cvar("g_ctf") && dteam == 3)
740 else if(cvar("g_ctf") && dteam == 4)
742 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 3) || (cvar("g_tdm") && cvar("g_tdm_teams") < 3))
749 else if((cvar("g_domination") && cvar("g_domination_default_teams") < 4) || (cvar("g_tdm") && cvar("g_tdm_teams") < 4))
755 // not changing teams
758 //bprint("same team change\n");
759 SetPlayerTeam(self, dteam, steam, TRUE);
765 if(cvar("g_changeteam_banned"))
767 sprint(self, "Team changes not allowed\n");
768 return; // changing teams is not allowed
771 if(cvar("g_balance_teams_prevent_imbalance"))
773 // only allow changing to a smaller or equal size team
775 // find out what teams are available
777 // count how many players on each team
778 GetTeamCounts(world);
781 if(dteam == 1 && c1 >= 0)//dcolor == COLOR_TEAM1 - 1)
786 else if(dteam == 2 && c2 >= 0)//dcolor == COLOR_TEAM2 - 1)
791 else if(dteam == 3 && c3 >= 0)//dcolor == COLOR_TEAM3 - 1)
796 else if(dteam == 4 && c4 >= 0)//dcolor == COLOR_TEAM4 - 1)
803 sprint(self, "Cannot change to an invalid team\n");
809 if(steam == 1)//scolor == COLOR_TEAM1 - 1)
811 else if(steam == 2)//scolor == COLOR_TEAM2 - 1)
813 else if(steam == 3)//scolor == COLOR_TEAM3 - 1)
815 else if(steam == 4)//scolor == COLOR_TEAM4 - 1)
818 if(scount) // started at a valid, nonempty team
820 // check if we're trying to change to a larger team that doens't have bots to swap with
821 if(dcount >= scount && dbotcount <= 0)
823 sprint(self, "Cannot change to a larger team\n");
824 return; // can't change to a larger team
830 // bprint(strcat("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"));
832 SetPlayerTeam(self, dteam, steam, FALSE);
833 if(cvar("teamplay") && self.classname == "player" && steam != dteam)
835 // kill player when changing teams
836 if(self.deadflag == DEAD_NO)
837 Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
838 // reduce frags during a team change
839 self.frags = floor(self.frags * (cvar("g_changeteam_fragtransfer") / 100));
844 void ShufflePlayerOutOfTeam (float source_team)
846 float smallestteam, smallestteam_count, steam;
847 float lowest_bot_score, lowest_player_score;
848 entity head, lowest_bot, lowest_player, selected;
852 smallestteam_count = 999;
854 if(c1 >= 0 && c1 < smallestteam_count)
857 smallestteam_count = c1;
859 if(c2 >= 0 && c2 < smallestteam_count)
862 smallestteam_count = c2;
864 if(c3 >= 0 && c3 < smallestteam_count)
867 smallestteam_count = c3;
869 if(c4 >= 0 && c4 < smallestteam_count)
872 smallestteam_count = c4;
877 bprint("warning: no smallest team\n");
883 else if(source_team == 2)
885 else if(source_team == 3)
887 else if(source_team == 4)
891 lowest_bot_score = 9999;
892 lowest_player = world;
893 lowest_player_score = 9999;
895 // find the lowest-scoring player & bot of that team
896 head = find(world, classname, "player");
899 if(head.team == steam)
903 if(head.frags < lowest_bot_score)
906 lowest_bot_score = head.frags;
911 if(head.frags < lowest_player_score)
913 lowest_player = head;
914 lowest_player_score = head.frags;
918 head = find(head, classname, "player");
921 // prefers to move a bot...
922 if(lowest_bot != world)
923 selected = lowest_bot;
924 // but it will move a player if it has to
926 selected = lowest_player;
927 // don't do anything if it couldn't find anyone
930 bprint("warning: couldn't find a player to move from team\n");
934 // smallest team gains a member
935 if(smallestteam == 1)
939 else if(smallestteam == 2)
943 else if(smallestteam == 3)
947 else if(smallestteam == 4)
953 bprint("warning: destination team invalid\n");
956 // source team loses a member
961 else if(source_team == 2)
965 else if(source_team == 3)
969 else if(source_team == 4)
975 bprint("warning: source team invalid\n");
979 // move the player to the new team
980 SetPlayerTeam(selected, smallestteam, source_team, FALSE);
982 if(selected.deadflag == DEAD_NO)
983 Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
984 m = "You have been moved into a different team to improve team balance\nYou are now on: ";
985 if (selected.team == 5)
986 m = strcat(m, "^1Red Team");
987 else if (selected.team == 14)
988 m = strcat(m, "^4Blue Team");
989 else if (selected.team == 10)
990 m = strcat(m, "^6Pink Team");
991 else if (selected.team == 13)
992 m = strcat(m, "^3Yellow Team");
993 centerprint(selected, m);
996 // part of g_balance_teams_force
997 // occasionally perform an audit of the teams to make
998 // sure they're more or less balanced in player count.
1001 float numplayers, numteams, average;
1002 if(!cvar("g_balance_teams_force"))
1004 if(!cvar("teamplay"))
1007 if(audit_teams_time > time)
1010 audit_teams_time = time + 4 + random();
1012 // bprint("Auditing teams\n");
1014 CheckAllowedTeams();
1015 GetTeamCounts(world);
1018 numteams = numplayers = 0;
1021 numteams = numteams + 1;
1022 numplayers = numplayers + c1;
1026 numteams = numteams + 1;
1027 numplayers = numplayers + c2;
1031 numteams = numteams + 1;
1032 numplayers = numplayers + c3;
1036 numteams = numteams + 1;
1037 numplayers = numplayers + c4;
1041 return; // no players to move around
1043 return; // don't bother shuffling if for some reason there aren't any teams
1045 average = ceil(numplayers / numteams);
1048 return; // that's weird...
1050 if(c1 && c1 > average)
1052 bprint("Rebalancing Teams\n");
1053 //bprint("Shuffle from team 1\n");
1054 ShufflePlayerOutOfTeam(1);
1056 if(c2 && c2 > average)
1058 bprint("Rebalancing Teams\n");
1059 //bprint("Shuffle from team 2\n");
1060 ShufflePlayerOutOfTeam(2);
1062 if(c3 && c3 > average)
1064 bprint("Rebalancing Teams\n");
1065 //bprint("Shuffle from team 3\n");
1066 ShufflePlayerOutOfTeam(3);
1068 if(c4 && c4 > average)
1070 bprint("Rebalancing Teams\n");
1071 //bprint("Shuffle from team 4\n");
1072 ShufflePlayerOutOfTeam(4);
1075 // if teams are still unbalanced, balance them further in the next audit,
1076 // which will happen sooner (keep doing rapid audits until things are in order)
1077 audit_teams_time = time + 0.7 + random()*0.3;
1082 /*void(entity e, float first) UpdateTeamScore =
1087 WriteByte (MSG_ALL, SVC_UPDATENAME);
1088 WriteByte (MSG_ALL, clientno);
1089 WriteString (MSG_ALL, e.netname);
1091 WriteByte (MSG_ALL, SVC_UPDATECOLORS);
1092 WriteByte (MSG_ALL, clientno);
1093 WriteByte (MSG_ALL, e.b_shirt * 16 + who.b_pants);
1096 WriteByte (MSG_ALL, SVC_UPDATEFRAGS);
1097 WriteByte (MSG_ALL, clientno);
1098 WriteShort (MSG_ALL, e.frags + 10000);
1104 // code from here on is just to support maps that don't have team entities
1105 void tdm_spawnteam (string teamname, float teamcolor)
1109 e.classname = "tdm_team";
1110 e.netname = teamname;
1115 // spawn some default teams if the map is not set up for tdm
1116 void() tdm_spawnteams =
1120 numteams = cvar("g_tdm_teams");
1122 tdm_spawnteam("Red", 4);
1123 tdm_spawnteam("Blue", 13);
1126 void() tdm_delayedinit =
1128 self.think = SUB_Remove;
1129 self.nextthink = time;
1130 // if no teams are found, spawn defaults
1131 if (find(world, classname, "tdm_team") == world)
1139 e.think = tdm_delayedinit;
1140 e.nextthink = time + 0.1;